use of io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction in project nem2-sdk-java by nemtech.
the class TransactionMapperVertxTest method shouldCreateAggregateMosaicAliasTransaction.
@Test
void shouldCreateAggregateMosaicAliasTransaction() {
TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicAliasTransaction.json");
Transaction aggregateTransferTransaction = map(aggregateTransferTransactionDTO);
validateAggregateTransaction((AggregateTransaction) aggregateTransferTransaction, aggregateTransferTransactionDTO);
MosaicAliasTransaction transaction = (MosaicAliasTransaction) ((AggregateTransaction) aggregateTransferTransaction).getInnerTransactions().get(0);
Assertions.assertEquals(new BigInteger("884562898459306"), transaction.getMosaicId().getId());
Assertions.assertEquals(AliasAction.UNLINK, transaction.getAliasAction());
Assertions.assertEquals(new BigInteger("307262000798378"), transaction.getNamespaceId().getId());
}
use of io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction in project nem2-sdk-java by nemtech.
the class TestHelper method createMosaic.
protected MosaicId createMosaic(Account account, RepositoryType type, BigInteger initialSupply, String alias) {
MosaicNonce nonce = MosaicNonce.createRandom();
MosaicId mosaicId = MosaicId.createFromNonce(nonce, account.getPublicAccount());
MosaicDefinitionTransaction mosaicDefinitionTransaction = MosaicDefinitionTransactionFactory.create(getNetworkType(), getDeadline(), nonce, mosaicId, MosaicFlags.create(true, true, true), 4, new BlockDuration(100)).maxFee(maxFee).build();
MosaicDefinitionTransaction validateTransaction = announceAndValidate(type, account, mosaicDefinitionTransaction);
Assertions.assertEquals(mosaicId, validateTransaction.getMosaicId());
UnresolvedMosaicId unresolvedMosaicId = mosaicId;
if (alias != null) {
NamespaceId rootNamespaceId = createRootNamespace(type, account, alias);
unresolvedMosaicId = rootNamespaceId;
MosaicAliasTransaction addressAliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
announceAggregateAndValidate(type, addressAliasTransaction, account);
}
if (initialSupply != null && initialSupply.longValue() > 0) {
MosaicSupplyChangeTransaction mosaicSupplyChangeTransaction = MosaicSupplyChangeTransactionFactory.create(getNetworkType(), getDeadline(), unresolvedMosaicId, MosaicSupplyChangeActionType.INCREASE, initialSupply).maxFee(maxFee).build();
announceAndValidate(type, account, mosaicSupplyChangeTransaction);
}
return mosaicId;
}
use of io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest method shouldCreateAggregateMosaicAliasTransaction.
@Test
void shouldCreateAggregateMosaicAliasTransaction() {
TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicAliasTransaction.json");
Transaction aggregateTransferTransaction = map(aggregateTransferTransactionDTO);
validateAggregateTransaction((AggregateTransaction) aggregateTransferTransaction, aggregateTransferTransactionDTO);
MosaicAliasTransaction transaction = (MosaicAliasTransaction) ((AggregateTransaction) aggregateTransferTransaction).getInnerTransactions().get(0);
Assertions.assertEquals(new BigInteger("884562898459306"), transaction.getMosaicId().getId());
Assertions.assertEquals(AliasAction.UNLINK, transaction.getAliasAction());
Assertions.assertEquals(new BigInteger("307262000798378"), transaction.getNamespaceId().getId());
}
use of io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction in project nem2-sdk-java by nemtech.
the class TestHelper method setMosaicAlias.
protected NamespaceId setMosaicAlias(RepositoryType type, MosaicId mosaicId, String namespaceName) {
Account nemesisAccount = config().getNemesisAccount1();
NamespaceId namespaceId = NamespaceId.createFromName(namespaceName);
if (isAlias(type, mosaicId, namespaceId)) {
System.out.println(namespaceName + " MOSAIC Alias found, reusing it.");
return namespaceId;
} else {
System.out.println(namespaceName + " MOSAIC Alias not found, CREATING MOSAIC ALIAS");
}
System.out.println("Setting up namespace " + namespaceName);
NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, getDuration()).maxFee(maxFee).build();
NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, nemesisAccount).getLeft().getNamespaceId();
System.out.println("Setting mosaic alias " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
MosaicAliasTransaction aliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
announceAggregateAndValidate(type, aliasTransaction, nemesisAccount);
int retry = 10;
while (!isAlias(type, mosaicId, namespaceId)) {
sleep(300);
retry--;
if (retry == 0) {
Assertions.fail("Could not create " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
}
}
return rootNamespaceId;
}
use of io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction in project nem2-sdk-java by nemtech.
the class MosaicAliasTransactionIntegrationTest method sendMosaicAliasTransaction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void sendMosaicAliasTransaction(RepositoryType type) {
String namespaceName = "test-root-namespace-for-mosaic-alias-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
Account account = this.config().getDefaultAccount();
AccountInfo accountInfo = get(getRepositoryFactory(type).createAccountRepository().getAccountInfo(account.getPublicAccount().getAddress()));
Assertions.assertFalse(accountInfo.getMosaics().isEmpty());
MosaicId mosaicId = createMosaic(account, type, BigInteger.ZERO, null);
NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, helper().getDuration()).maxFee(maxFee).build();
NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, account).getLeft().getNamespaceId();
MosaicAliasTransaction addressAliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
announceAggregateAndValidate(type, addressAliasTransaction, account);
List<MosaicNames> accountNames = get(getRepositoryFactory(type).createNamespaceRepository().getMosaicsNames(Collections.singletonList(mosaicId)));
Assertions.assertEquals(1, accountNames.size());
assertEquals(1, accountNames.size());
assertEquals(mosaicId, accountNames.get(0).getMosaicId());
assertTrue(accountNames.get(0).getNames().stream().anyMatch(n -> namespaceName.equals(n.getName())));
}
Aggregations