use of io.nem.symbol.sdk.model.account.AccountInfo in project nem2-sdk-java by nemtech.
the class AccountRepositoryIntegrationTest method getAccountInfo.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAccountInfo(RepositoryType type) {
Account testAccount = this.config().getDefaultAccount();
Observable<AccountInfo> accountInfo1 = this.getAccountRepository(type).getAccountInfo(testAccount.getPublicAccount().getAddress());
AccountInfo accountInfo = get(accountInfo1);
assertEquals(testAccount.getPublicKey(), accountInfo.getPublicKey().toHex());
assertEquals(AccountType.UNLINKED, accountInfo.getAccountType());
}
use of io.nem.symbol.sdk.model.account.AccountInfo in project nem2-sdk-java by nemtech.
the class AccountRepositoryVertxImplTest method shouldGetAccountInfo.
@Test
public void shouldGetAccountInfo() throws Exception {
Account account = Account.generateNewAccount(this.networkType);
Address address = account.getAddress();
AccountDTO accountDTO = new AccountDTO();
accountDTO.setVersion(1);
accountDTO.setAccountType(AccountTypeEnum.NUMBER_1);
accountDTO.setAddress(encodeAddress(address));
accountDTO.setAddressHeight(BigInteger.TEN);
accountDTO.setPublicKeyHeight(BigInteger.valueOf(20));
accountDTO.setPublicKey(account.getPublicAccount().getPublicKey().toHex());
accountDTO.setImportance(BigInteger.valueOf(5));
accountDTO.setImportanceHeight(BigInteger.valueOf(10));
List<Mosaic> mosaicDtos = new ArrayList<>();
mosaicDtos.add(new Mosaic().id("0000000000000ABC").amount(BigInteger.TEN));
accountDTO.setMosaics(mosaicDtos);
AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
accountInfoDTO.setAccount(accountDTO);
mockRemoteCall(accountInfoDTO);
AccountInfo resolvedAccountInfo = repository.getAccountInfo(address).toFuture().get();
Assertions.assertEquals(address, resolvedAccountInfo.getAddress());
Assertions.assertEquals(AccountType.MAIN, resolvedAccountInfo.getAccountType());
Assertions.assertEquals(1, resolvedAccountInfo.getMosaics().size());
Assertions.assertEquals("0000000000000ABC", resolvedAccountInfo.getMosaics().get(0).getId().getIdAsHex());
Assertions.assertEquals(BigInteger.TEN, resolvedAccountInfo.getMosaics().get(0).getAmount());
}
use of io.nem.symbol.sdk.model.account.AccountInfo in project nem2-sdk-java by nemtech.
the class TestHelper method createMultisigAccountBonded.
public MultisigAccountInfo createMultisigAccountBonded(RepositoryType type, Account multisigAccount, Account... accounts) {
AccountRepository accountRepository = getRepositoryFactory(type).createAccountRepository();
MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
AccountInfo accountInfo = get(accountRepository.getAccountInfo(multisigAccount.getAddress()));
System.out.println(getJsonHelper().print(accountInfo));
if (isMultisig(type, multisigAccount)) {
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " already exist");
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " does not exist. Creating");
System.out.println("Creating multisg account " + multisigAccount.getAddress().plain());
List<UnresolvedAddress> additions = Arrays.stream(accounts).map(Account::getAddress).collect(Collectors.toList());
MultisigAccountModificationTransaction convertIntoMultisigTransaction = MultisigAccountModificationTransactionFactory.create(getNetworkType(), getDeadline(), (byte) 1, (byte) 1, additions, Collections.emptyList()).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(convertIntoMultisigTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(accounts), getGenerationHash());
Mosaic hashAmount = getCurrency().createRelative(BigInteger.valueOf(10));
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), hashAmount, BigInteger.valueOf(100), signedAggregateTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = hashLockTransaction.signWith(multisigAccount, getGenerationHash());
getTransactionOrFail(getTransactionService(type).announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedAggregateTransaction), aggregateTransaction);
HashLockRepository hashLockRepository = getRepositoryFactory(type).createHashLockRepository();
HashLockInfo hashLockInfo = get(hashLockRepository.getHashLock(hashLockTransaction.getHash()));
Assertions.assertNotNull(hashLockInfo);
Assertions.assertEquals(multisigAccount.getAddress(), hashLockInfo.getOwnerAddress());
Assertions.assertEquals(hashAmount.getAmount(), hashLockInfo.getAmount());
Assertions.assertEquals(LockStatus.UNUSED, hashLockInfo.getStatus());
Assertions.assertEquals(hashLockTransaction.getHash(), hashLockInfo.getHash());
Page<HashLockInfo> page = get(hashLockRepository.search(new HashLockSearchCriteria().address(multisigAccount.getAddress())));
Assertions.assertTrue(page.getData().stream().anyMatch(m -> m.getHash().equals(hashLockTransaction.getHash())));
Assertions.assertEquals(20, page.getPageSize());
sleep(1000);
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
use of io.nem.symbol.sdk.model.account.AccountInfo 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.AccountInfo in project nem2-sdk-java by nemtech.
the class TestHelper method createMultisigAccountComplete.
public MultisigAccountInfo createMultisigAccountComplete(RepositoryType type, Account multisigAccount, Account... accounts) {
AccountRepository accountRepository = getRepositoryFactory(type).createAccountRepository();
MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
AccountInfo accountInfo = get(accountRepository.getAccountInfo(multisigAccount.getAddress()));
System.out.println(getJsonHelper().print(accountInfo));
try {
MultisigAccountInfo multisigAccountInfo = get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " already exist");
System.out.println(getJsonHelper().print(multisigAccountInfo));
return multisigAccountInfo;
} catch (RepositoryCallException e) {
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " does not exist. Creating");
}
System.out.println("Creating multisg account " + multisigAccount.getAddress().plain());
List<UnresolvedAddress> additions = Arrays.stream(accounts).map(Account::getAddress).collect(Collectors.toList());
MultisigAccountModificationTransaction convertIntoMultisigTransaction = MultisigAccountModificationTransactionFactory.create(getNetworkType(), getDeadline(), (byte) 1, (byte) 1, additions, Collections.emptyList()).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(convertIntoMultisigTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(accounts), getGenerationHash());
Transaction aggregateTransaciton = get(getTransactionService(type).announce(getListener(type), signedAggregateTransaction));
sleep(1000);
Assertions.assertEquals(aggregateTransaciton.getTransactionInfo().get().getHash().get(), signedAggregateTransaction.getHash());
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
Aggregations