use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TransactionServiceIntegrationTest method testTransferCustomCurrencyFromAccount1.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void testTransferCustomCurrencyFromAccount1(RepositoryType type) {
String mosaicAlias = ("testTransferCustomCurrencyFromAccount1" + RandomUtils.nextInt(0, 10000)).toLowerCase();
String recipientAlias = "testaccount" + RandomUtils.nextInt(0, 10000);
Account testAccount = helper.getTestAccount(type).getLeft();
MosaicId mosaicId = helper().createMosaic(testAccount, type, BigInteger.valueOf(10000), mosaicAlias);
helper().setAddressAlias(type, testAccount.getAddress(), recipientAlias);
String transferTransactionHash = transferUsingAliases(testAccount, type, mosaicAlias, recipientAlias, BigInteger.ONE).getTransactionInfo().get().getHash().get();
List<Transaction> transactions = get(getTransactionService(type).resolveAliases(Arrays.asList(transferTransactionHash)));
Assertions.assertEquals(1, transactions.size());
TransferTransaction resolvedTransaction = (TransferTransaction) transactions.get(0);
assertTransaction(mosaicId, resolvedTransaction, testAccount);
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TransactionServiceIntegrationTest method testTransferCustomCurrencyFromAccount1UsingAggregate.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void testTransferCustomCurrencyFromAccount1UsingAggregate(RepositoryType type) {
String mosaicAlias = ("testTransferCustomCurrencyFromAccount1UsingAggregate" + RandomUtils.nextInt(0, 10000)).toLowerCase();
Account testAccount = helper().getTestAccount(type).getLeft();
String recipientAlias = "testaccount" + RandomUtils.nextInt(0, 10000);
MosaicId mosaicId = helper().createMosaic(testAccount, type, BigInteger.valueOf(10000), mosaicAlias);
String aggregateTransactionHash = transferUsingAliasesAggregate(testAccount, type, mosaicAlias, recipientAlias, BigInteger.ONE).getTransactionInfo().get().getHash().get();
List<Transaction> transactions = get(getTransactionService(type).resolveAliases(Collections.singletonList(aggregateTransactionHash)));
Assertions.assertEquals(1, transactions.size());
TransferTransaction resolvedTransaction = (TransferTransaction) ((AggregateTransaction) transactions.get(0)).getInnerTransactions().get(0);
assertTransaction(mosaicId, resolvedTransaction, testAccount);
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class VotingKeyLinkTransactionIntegrationTest method basicAnnounce.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void basicAnnounce(RepositoryType type) {
Account account = config().getNemesisAccount1();
PublicKey linkedPublicKey = PublicKey.generateRandom();
VotingKeyLinkTransaction linkTransaction = VotingKeyLinkTransactionFactory.create(getNetworkType(), getDeadline(), linkedPublicKey, (72), (26280), LinkAction.LINK).maxFee(maxFee).build();
announceAndValidate(type, account, linkTransaction);
VotingKeyLinkTransaction unlinkTransaction = VotingKeyLinkTransactionFactory.create(getNetworkType(), getDeadline(), linkedPublicKey, (72), (26280), LinkAction.UNLINK).maxFee(maxFee).build();
announceAndValidate(type, account, unlinkTransaction);
}
use of io.nem.symbol.sdk.model.account.Account 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())));
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class MosaicMetadataServiceIntegrationTest method setAndUpdateMosaicMetadata.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void setAndUpdateMosaicMetadata(RepositoryType type) {
// TODO FIX THIS ONE when target != signerAccount
Account signerAccount = config().getDefaultAccount();
Account targetAccount = config().getDefaultAccount();
Assertions.assertFalse(helper().isMultisig(type, signerAccount));
Assertions.assertFalse(helper().isMultisig(type, targetAccount));
MosaicId targetMosaicId = super.createMosaic(signerAccount, type, BigInteger.ZERO, null);
BigInteger key = BigInteger.valueOf(RandomUtils.generateRandomInt(100000));
String originalMessage = "The original message";
String newMessage = "The new Message";
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
MetadataRepository metadataRepository = repositoryFactory.createMetadataRepository();
MetadataTransactionService service = new MetadataTransactionServiceImpl(repositoryFactory);
MosaicMetadataTransaction originalTransaction = get(service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), key, originalMessage, signerAccount.getAddress(), targetMosaicId)).maxFee(maxFee).build();
Assertions.assertEquals(targetAccount.getAddress(), originalTransaction.getTargetAddress());
Assertions.assertEquals(targetMosaicId, originalTransaction.getTargetMosaicId());
Assertions.assertEquals(key, originalTransaction.getScopedMetadataKey());
Assertions.assertEquals(originalMessage, originalTransaction.getValue());
helper().announceAggregateAndValidate(type, originalTransaction, signerAccount);
assertMetadata(targetMosaicId, key, originalMessage, metadataRepository, signerAccount, targetAccount);
MosaicMetadataTransaction updateTransaction = get(service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), key, newMessage, signerAccount.getAddress(), targetMosaicId)).maxFee(maxFee).build();
Assertions.assertEquals(targetAccount.getAddress(), updateTransaction.getTargetAddress());
Assertions.assertEquals(targetMosaicId, updateTransaction.getTargetMosaicId());
Assertions.assertEquals(key, updateTransaction.getScopedMetadataKey());
Pair<String, Integer> xorAndDelta = ConvertUtils.xorValues(originalMessage, newMessage);
Assertions.assertEquals(xorAndDelta.getLeft(), updateTransaction.getValue());
Assertions.assertEquals(xorAndDelta.getRight(), updateTransaction.getValueSizeDelta());
helper().announceAggregateAndValidate(type, updateTransaction, signerAccount);
assertMetadata(targetMosaicId, key, newMessage, metadataRepository, signerAccount, targetAccount);
}
Aggregations