use of io.nem.symbol.sdk.api.AccountRepository in project nem2-sdk-java by nemtech.
the class AccountRepositoryIntegrationTest method getAccountInfoNotExisting.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAccountInfoNotExisting(RepositoryType type) {
AccountRepository accountHttp = getRepositoryFactory(type).createAccountRepository();
Address addressObject = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(accountHttp.getAccountInfo(addressObject)));
Assertions.assertTrue(exception.getMessage().contains("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id"));
}
use of io.nem.symbol.sdk.api.AccountRepository in project nem2-sdk-java by nemtech.
the class MerkleLoaderIntegrationTest method accounts.
public List<Arguments> accounts() {
RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
AccountRepository repository = repositoryFactory.createAccountRepository();
return getArguments(repository, new AccountSearchCriteria().order(ORDER_BY));
}
use of io.nem.symbol.sdk.api.AccountRepository 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.api.AccountRepository 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()));
}
use of io.nem.symbol.sdk.api.AccountRepository in project nem2-sdk-java by nemtech.
the class StateProofServiceTest method account.
@Test
void account() throws Exception {
AccountRepository repository = mock(AccountRepository.class);
when(factory.createAccountRepository()).thenReturn(repository);
Address id = Address.generateRandom(NetworkType.MIJIN_TEST);
AccountInfo state = Mockito.mock(AccountInfo.class);
when(state.getAddress()).thenReturn(id);
when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
when(repository.getAccountInfo(eq(id))).thenReturn(Observable.just(state));
when(repository.getAccountInfoMerkle(eq(id))).thenReturn(Observable.just(tree));
StateMerkleProof<AccountInfo> proof = service.account(id).toFuture().get();
Assertions.assertTrue(proof.isValid());
Assertions.assertEquals(state, proof.getState());
}
Aggregations