Search in sources :

Example 36 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class TransactionRepositoryOkHttpImplTest method announceAggregateBondedCosignature.

@Test
public void announceAggregateBondedCosignature() throws Exception {
    Account signer = Account.generateNewAccount(networkType);
    BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
    CosignatureSignedTransaction signedTransaction = new CosignatureSignedTransaction(version, "aParentHash", "aSignature", signer.getPublicAccount());
    AnnounceTransactionInfoDTO announceTransactionInfoDTO = new AnnounceTransactionInfoDTO();
    announceTransactionInfoDTO.setMessage("SomeMessage");
    ArgumentCaptor<Object> parameter = mockRemoteCall(announceTransactionInfoDTO);
    TransactionAnnounceResponse response = repository.announceAggregateBondedCosignature(signedTransaction).toFuture().get();
    Assertions.assertNotNull(response);
    Assertions.assertEquals(announceTransactionInfoDTO.getMessage(), announceTransactionInfoDTO.getMessage());
    Cosignature cosignature = (Cosignature) parameter.getValue();
    Assertions.assertEquals(signedTransaction.getParentHash(), cosignature.getParentHash());
    Assertions.assertEquals(signedTransaction.getSignature(), cosignature.getSignature());
    Assertions.assertEquals(signedTransaction.getSigner().getPublicKey().toHex(), cosignature.getSignerPublicKey());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) BigInteger(java.math.BigInteger) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AnnounceTransactionInfoDTO) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) Cosignature(io.nem.symbol.sdk.openapi.okhttp_gson.model.Cosignature) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) Test(org.junit.jupiter.api.Test)

Example 37 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method shouldHandleStatus.

@Test
public void shouldHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
    Account account1 = Account.generateNewAccount(networkType);
    AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
    simulateWebSocketStartup();
    Assertions.assertNotNull(listener.status(account1.getAddress()).subscribe(reference::set));
    Map<String, Object> message = new HashMap<>();
    message.put("hash", "1234hash");
    message.put("address", account1.getAddress().encoded());
    message.put("code", "some error");
    message.put("deadline", 5555);
    handle(message, "status/" + account1.getAddress().plain());
    Assertions.assertNotNull(reference.get());
    Assertions.assertEquals(message.get("hash"), reference.get().getHash());
    Assertions.assertEquals(message.get("code"), reference.get().getStatus());
    Assertions.assertEquals(account1.getAddress(), reference.get().getAddress());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account1.getAddress().plain())));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 38 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class AccountRepositoryOkHttpImplTest method shouldGetAccountsInfoFromAddresses.

@Test
public void shouldGetAccountsInfoFromAddresses() throws ExecutionException, InterruptedException, ApiException {
    Account account = Account.generateNewAccount(this.networkType);
    Account nodeAccount = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    AccountDTO accountDTO = new AccountDTO();
    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.setVersion(1);
    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.okhttp_gson.model.AccountLinkPublicKeyDTO) AccountInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) BigInteger(java.math.BigInteger) SupplementalPublicKeysDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.SupplementalPublicKeysDTO) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) ActivityBucketDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.ActivityBucketDTO) Test(org.junit.jupiter.api.Test)

Example 39 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class AccountRepositoryOkHttpImplTest 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.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.setVersion(1);
    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.okhttp_gson.model.AccountLinkPublicKeyDTO) AccountInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.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.okhttp_gson.model.SupplementalPublicKeysDTO) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) ActivityBucketDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.ActivityBucketDTO) Test(org.junit.jupiter.api.Test)

Example 40 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class AccountRepositoryOkHttpImplTest method shouldGetAccountInfo.

@Test
public void shouldGetAccountInfo() throws Exception {
    Account account = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    AccountDTO accountDTO = new AccountDTO();
    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);
    accountDTO.setVersion(1);
    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.okhttp_gson.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) ArrayList(java.util.ArrayList) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) Mosaic(io.nem.symbol.sdk.openapi.okhttp_gson.model.Mosaic) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) Test(org.junit.jupiter.api.Test)

Aggregations

Account (io.nem.symbol.sdk.model.account.Account)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)39 EnumSource (org.junit.jupiter.params.provider.EnumSource)36 Test (org.junit.jupiter.api.Test)29 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)26 BigInteger (java.math.BigInteger)21 Address (io.nem.symbol.sdk.model.account.Address)20 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)18 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)17 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)17 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)15 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)15 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)14 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)13 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)11 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)9 Currency (io.nem.symbol.sdk.model.mosaic.Currency)9 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)9 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)7