Search in sources :

Example 1 with AccountInfoDTO

use of io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO in project nem2-sdk-java by nemtech.

the class AccountRepositoryVertxImplTest method shouldProcessExceptionWhenNotFound.

@Test
public void shouldProcessExceptionWhenNotFound() {
    Address address = Address.generateRandom(this.networkType);
    AccountDTO accountDTO = new AccountDTO();
    accountDTO.setAccountType(AccountTypeEnum.NUMBER_1);
    accountDTO.setAddress(encodeAddress(address));
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    mockErrorCode(404, "Account not found!");
    Assertions.assertEquals("ApiException: Not Found - 404 - Code Not Found - Account not found!", Assertions.assertThrows(RepositoryCallException.class, () -> {
        ExceptionUtils.propagate(() -> repository.getAccountInfo(address).toFuture().get());
    }).getMessage());
}
Also used : AccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) AccountDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountDTO) Test(org.junit.jupiter.api.Test)

Example 2 with AccountInfoDTO

use of io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO in project nem2-sdk-java by nemtech.

the class AccountRepositoryVertxImplTest method search.

@Test
public void search() throws Exception {
    Account account = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    Account nodeAccount = Account.generateNewAccount(this.networkType);
    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));
    accountDTO.setSupplementalPublicKeys(new SupplementalPublicKeysDTO().node(new AccountLinkPublicKeyDTO().publicKey(nodeAccount.getPublicKey())));
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    BigInteger startHeight = BigInteger.ONE;
    BigInteger totalFeesPaid = BigInteger.valueOf(2);
    long beneficiaryCount = 3;
    BigInteger rawScore = BigInteger.valueOf(4);
    accountDTO.addActivityBucketsItem(new ActivityBucketDTO().startHeight(startHeight).totalFeesPaid(totalFeesPaid).beneficiaryCount(beneficiaryCount).rawScore(rawScore));
    mockRemoteCall(toPage(accountInfoDTO));
    List<AccountInfo> resolvedAccountInfos = repository.search(new AccountSearchCriteria().orderBy(AccountOrderBy.BALANCE)).toFuture().get().getData();
    Assertions.assertEquals(1, resolvedAccountInfos.size());
    AccountInfo resolvedAccountInfo = resolvedAccountInfos.get(0);
    Assertions.assertEquals(address, resolvedAccountInfo.getAddress());
    Assertions.assertEquals(AccountType.MAIN, resolvedAccountInfo.getAccountType());
    Assertions.assertEquals(nodeAccount.getPublicKey(), resolvedAccountInfo.getSupplementalAccountKeys().getNode().get().toHex());
    Assertions.assertEquals(1, resolvedAccountInfo.getActivityBuckets().size());
    Assertions.assertEquals(startHeight, resolvedAccountInfo.getActivityBuckets().get(0).getStartHeight());
    Assertions.assertEquals(totalFeesPaid, resolvedAccountInfo.getActivityBuckets().get(0).getTotalFeesPaid());
    Assertions.assertEquals(beneficiaryCount, resolvedAccountInfo.getActivityBuckets().get(0).getBeneficiaryCount());
    Assertions.assertEquals(rawScore, resolvedAccountInfo.getActivityBuckets().get(0).getRawScore());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AccountLinkPublicKeyDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountLinkPublicKeyDTO) AccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO) AccountSearchCriteria(io.nem.symbol.sdk.api.AccountSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) BigInteger(java.math.BigInteger) SupplementalPublicKeysDTO(io.nem.symbol.sdk.openapi.vertx.model.SupplementalPublicKeysDTO) AccountDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountDTO) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) ActivityBucketDTO(io.nem.symbol.sdk.openapi.vertx.model.ActivityBucketDTO) Test(org.junit.jupiter.api.Test)

Example 3 with AccountInfoDTO

use of io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO in project nem2-sdk-java by nemtech.

the class AccountRepositoryVertxImplTest method shouldGetAccountsInfoFromAddresses.

@Test
public void shouldGetAccountsInfoFromAddresses() throws ExecutionException, InterruptedException {
    Account account = Account.generateNewAccount(this.networkType);
    Account nodeAccount = 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));
    accountDTO.setSupplementalPublicKeys(new SupplementalPublicKeysDTO().node(new AccountLinkPublicKeyDTO().publicKey(nodeAccount.getPublicKey())));
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    BigInteger startHeight = BigInteger.ONE;
    BigInteger totalFeesPaid = BigInteger.valueOf(2);
    long beneficiaryCount = 3;
    BigInteger rawScore = BigInteger.valueOf(4);
    accountDTO.addActivityBucketsItem(new ActivityBucketDTO().startHeight(startHeight).totalFeesPaid(totalFeesPaid).beneficiaryCount(beneficiaryCount).rawScore(rawScore));
    mockRemoteCall(Collections.singletonList(accountInfoDTO));
    List<AccountInfo> resolvedAccountInfos = repository.getAccountsInfo(Collections.singletonList(address)).toFuture().get();
    Assertions.assertEquals(1, resolvedAccountInfos.size());
    AccountInfo resolvedAccountInfo = resolvedAccountInfos.get(0);
    Assertions.assertEquals(address, resolvedAccountInfo.getAddress());
    Assertions.assertEquals(AccountType.MAIN, resolvedAccountInfo.getAccountType());
    Assertions.assertEquals(nodeAccount.getPublicKey(), resolvedAccountInfo.getSupplementalAccountKeys().getNode().get().toHex());
    Assertions.assertEquals(1, resolvedAccountInfo.getActivityBuckets().size());
    Assertions.assertEquals(startHeight, resolvedAccountInfo.getActivityBuckets().get(0).getStartHeight());
    Assertions.assertEquals(totalFeesPaid, resolvedAccountInfo.getActivityBuckets().get(0).getTotalFeesPaid());
    Assertions.assertEquals(beneficiaryCount, resolvedAccountInfo.getActivityBuckets().get(0).getBeneficiaryCount());
    Assertions.assertEquals(rawScore, resolvedAccountInfo.getActivityBuckets().get(0).getRawScore());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AccountLinkPublicKeyDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountLinkPublicKeyDTO) AccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) BigInteger(java.math.BigInteger) SupplementalPublicKeysDTO(io.nem.symbol.sdk.openapi.vertx.model.SupplementalPublicKeysDTO) AccountDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountDTO) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) ActivityBucketDTO(io.nem.symbol.sdk.openapi.vertx.model.ActivityBucketDTO) Test(org.junit.jupiter.api.Test)

Example 4 with AccountInfoDTO

use of io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO in project nem2-sdk-java by nemtech.

the class AccountRepositoryVertxImpl method getAccountsInfo.

@Override
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
    AccountIds accountIds = new AccountIds().addresses(addresses.stream().map(Address::plain).collect(Collectors.toList()));
    Consumer<Handler<AsyncResult<List<AccountInfoDTO>>>> callback = handler -> getClient().getAccountsInfo(accountIds, handler);
    return exceptionHandling(call(callback).flatMapIterable(item -> item).map(this::toAccountInfo).toList().toObservable());
}
Also used : AccountDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountDTO) AccountOrderByEnum(io.nem.symbol.sdk.openapi.vertx.model.AccountOrderByEnum) MapperUtils.toMosaicId(io.nem.symbol.core.utils.MapperUtils.toMosaicId) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) AccountType(io.nem.symbol.sdk.model.account.AccountType) SupplementalPublicKeysDTO(io.nem.symbol.sdk.openapi.vertx.model.SupplementalPublicKeysDTO) MapperUtils.toAddress(io.nem.symbol.core.utils.MapperUtils.toAddress) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) AccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO) ObjectUtils(org.apache.commons.lang3.ObjectUtils) AccountRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.AccountRoutesApi) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) ActivityBucket(io.nem.symbol.sdk.model.account.ActivityBucket) Observable(io.reactivex.Observable) AsyncResult(io.vertx.core.AsyncResult) AccountPage(io.nem.symbol.sdk.openapi.vertx.model.AccountPage) AccountIds(io.nem.symbol.sdk.openapi.vertx.model.AccountIds) ResolvedMosaic(io.nem.symbol.sdk.model.mosaic.ResolvedMosaic) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) AccountSearchCriteria(io.nem.symbol.sdk.api.AccountSearchCriteria) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) SupplementalAccountKeys(io.nem.symbol.sdk.model.account.SupplementalAccountKeys) PublicKey(io.nem.symbol.core.crypto.PublicKey) AccountLinkPublicKeyDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountLinkPublicKeyDTO) AccountLinkVotingKey(io.nem.symbol.sdk.model.account.AccountLinkVotingKey) Address(io.nem.symbol.sdk.model.account.Address) AccountRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.AccountRoutesApiImpl) Handler(io.vertx.core.Handler) Collections(java.util.Collections) Page(io.nem.symbol.sdk.api.Page) AccountIds(io.nem.symbol.sdk.openapi.vertx.model.AccountIds) MapperUtils.toAddress(io.nem.symbol.core.utils.MapperUtils.toAddress) Address(io.nem.symbol.sdk.model.account.Address) Handler(io.vertx.core.Handler) List(java.util.List)

Example 5 with AccountInfoDTO

use of io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO 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());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) ArrayList(java.util.ArrayList) AccountDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountDTO) Mosaic(io.nem.symbol.sdk.openapi.vertx.model.Mosaic) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) Test(org.junit.jupiter.api.Test)

Aggregations

Address (io.nem.symbol.sdk.model.account.Address)6 AccountDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountDTO)6 AccountInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO)6 Test (org.junit.jupiter.api.Test)5 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)4 Account (io.nem.symbol.sdk.model.account.Account)3 AccountLinkPublicKeyDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountLinkPublicKeyDTO)3 SupplementalPublicKeysDTO (io.nem.symbol.sdk.openapi.vertx.model.SupplementalPublicKeysDTO)3 AccountSearchCriteria (io.nem.symbol.sdk.api.AccountSearchCriteria)2 ActivityBucketDTO (io.nem.symbol.sdk.openapi.vertx.model.ActivityBucketDTO)2 BigInteger (java.math.BigInteger)2 PublicKey (io.nem.symbol.core.crypto.PublicKey)1 MapperUtils.toAddress (io.nem.symbol.core.utils.MapperUtils.toAddress)1 MapperUtils.toMosaicId (io.nem.symbol.core.utils.MapperUtils.toMosaicId)1 AccountRepository (io.nem.symbol.sdk.api.AccountRepository)1 Page (io.nem.symbol.sdk.api.Page)1 AccountLinkVotingKey (io.nem.symbol.sdk.model.account.AccountLinkVotingKey)1 AccountType (io.nem.symbol.sdk.model.account.AccountType)1 ActivityBucket (io.nem.symbol.sdk.model.account.ActivityBucket)1 SupplementalAccountKeys (io.nem.symbol.sdk.model.account.SupplementalAccountKeys)1