use of io.nem.symbol.sdk.model.mosaic.Currency in project nem2-sdk-java by nemtech.
the class RepositoryFactoryConfigurationExamplesIntegrationTest method bootAppFullyOffline.
@Test
void bootAppFullyOffline() throws ExecutionException, InterruptedException {
// Option 1) Client app boot time. The clients defines the configuration to work
// offline.
RepositoryFactoryConfiguration configuration = new RepositoryFactoryConfiguration("http://localhost:3000");
configuration.withNetworkType(NetworkType.MAIN_NET);
configuration.withGenerationHash("abc");
Currency currency = new CurrencyBuilder(NamespaceId.createFromName("my.custom.currency"), 6).build();
Currency harvest = new CurrencyBuilder(NamespaceId.createFromName("my.custom.harvest"), 3).build();
configuration.withNetworkCurrencies(new NetworkCurrencies(currency, harvest));
try (RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(configuration)) {
appDoSomeStuff(repositoryFactory);
}
}
use of io.nem.symbol.sdk.model.mosaic.Currency in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method standaloneTransferTransactionEncryptedMessage.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void standaloneTransferTransactionEncryptedMessage(RepositoryType type) throws Exception {
this.helper().sendMosaicFromNemesis(type, getRecipient(), false);
String namespaceName = "standaloneTransferTransactionEncryptedMessagealias".toLowerCase();
NamespaceId recipient = setAddressAlias(type, getRecipient(), namespaceName);
System.out.println(recipient.getIdAsHex());
Assertions.assertEquals("9960629109A48AFBC0000000000000000000000000000000", recipient.encoded(getNetworkType()));
String message = "E2ETest:standaloneTransferTransaction:message 漢字";
KeyPair senderKeyPair = KeyPair.random();
KeyPair recipientKeyPair = KeyPair.random();
Message encryptedMessage = EncryptedMessage.create(message, senderKeyPair.getPrivateKey(), recipientKeyPair.getPublicKey());
Currency networkCurrency = getNetworkCurrency();
Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(10202020));
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(encryptedMessage).maxFee(maxFee).build();
TransferTransaction processed = announceAndValidate(type, signerAccount, transferTransaction);
assertTransferTransactions(transferTransaction, processed);
assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, processed);
TransferTransaction restTransaction = (TransferTransaction) get(getRepositoryFactory(type).createTransactionRepository().getTransaction(TransactionGroup.CONFIRMED, processed.getTransactionInfo().get().getHash().get()));
assertTransferTransactions(transferTransaction, restTransaction);
assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, restTransaction);
}
use of io.nem.symbol.sdk.model.mosaic.Currency in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method basicTransfer.
private List<String> basicTransfer(RepositoryType type, UnresolvedAddress recipient, String s, int i, List<String> expected, boolean includeAliases, UnresolvedAddress... listenTo) throws InterruptedException, ExecutionException {
List<String> messages = new ArrayList<>();
Listener listener = listen(type, messages, includeAliases, listenTo);
sleep(1000);
try {
String message = s;
Currency networkCurrency = getNetworkCurrency();
Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(i));
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(new PlainMessage(message)).maxFee(maxFee).build();
TransferTransaction processed = announceAggregateAndValidate(type, transferTransaction, signerAccount).getKey();
Assertions.assertEquals(message, processed.getMessage().get().getText());
sleep(1000);
Assertions.assertEquals(expected, messages);
return messages;
} finally {
listener.close();
}
}
use of io.nem.symbol.sdk.model.mosaic.Currency in project nem2-sdk-java by nemtech.
the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenEmptyNames.
@Test
void getNetworkCurrencyFromMosaicIdWhenEmptyNames() throws Exception {
MosaicId mosaicId = new MosaicId(BigInteger.TEN);
Account account = Account.generateNewAccount(NetworkType.MAIN_NET);
BigInteger supply = BigInteger.valueOf(12);
MosaicInfo mosaicInfo = new MosaicInfo("abc", 1, mosaicId, supply, BigInteger.ONE, account.getAddress(), 4L, MosaicFlags.create(true, true, true), 10, BigInteger.TEN);
Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(mosaicInfo)));
Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(new MosaicNames(mosaicId, Collections.emptyList()))));
Currency currency = service.getCurrency(mosaicId).toFuture().get();
Assertions.assertEquals(10, currency.getDivisibility());
Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
Assertions.assertFalse(currency.getNamespaceId().isPresent());
Assertions.assertTrue(currency.isTransferable());
Assertions.assertTrue(currency.isSupplyMutable());
}
use of io.nem.symbol.sdk.model.mosaic.Currency in project nem2-sdk-java by nemtech.
the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent.
@Test
void getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent() throws Exception {
MosaicId mosaicId = new MosaicId(BigInteger.TEN);
Account account = Account.generateNewAccount(NetworkType.MAIN_NET);
BigInteger supply = BigInteger.valueOf(12);
MosaicInfo mosaicInfo = new MosaicInfo("abc", 1, mosaicId, supply, BigInteger.ONE, account.getAddress(), 4L, MosaicFlags.create(true, true, true), 10, BigInteger.TEN);
Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Arrays.asList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicInfo)));
String name = "some.alias";
NamespaceId namespaceId = NamespaceId.createFromName(name);
MosaicNames mosaicNames = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName(name), new NamespaceName("some.alias2")));
MosaicNames mosaicNames2 = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName("some.alias2"), new NamespaceName("some.alias3")));
Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicNames, mosaicNames2)));
Currency currency = service.getCurrency(mosaicId).toFuture().get();
Assertions.assertEquals(10, currency.getDivisibility());
Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
Assertions.assertEquals(namespaceId, currency.getNamespaceId().get());
Assertions.assertEquals("some.alias", currency.getNamespaceId().get().getFullName().get());
Assertions.assertTrue(currency.isTransferable());
Assertions.assertTrue(currency.isSupplyMutable());
}
Aggregations