use of io.nem.symbol.sdk.model.account.Account 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());
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method shouldFilterOutHandleStatus.
@Test
public void shouldFilterOutHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
Account account1 = Account.generateNewAccount(NETWORK_TYPE);
Account account2 = Account.generateNewAccount(NETWORK_TYPE);
AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
simulateWebSocketStartup();
Assertions.assertNotNull(listener.status(account2.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.assertNull(reference.get());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account2.getAddress().plain())));
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenEmptyNames.
@Test
void getNetworkCurrencyFromMosaicIdWhenEmptyNames() throws Exception {
MosaicId mosaicId = new MosaicId(BigInteger.TEN);
Account account = Account.generateNewAccount(NetworkType.MAIN_NET);
BigInteger supply = BigInteger.valueOf(12);
MosaicInfo mosaicInfo = new MosaicInfo("abc", 1, mosaicId, supply, BigInteger.ONE, account.getAddress(), 4L, MosaicFlags.create(true, true, true), 10, BigInteger.TEN);
Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(mosaicInfo)));
Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(new MosaicNames(mosaicId, Collections.emptyList()))));
Currency currency = service.getCurrency(mosaicId).toFuture().get();
Assertions.assertEquals(10, currency.getDivisibility());
Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
Assertions.assertFalse(currency.getNamespaceId().isPresent());
Assertions.assertTrue(currency.isTransferable());
Assertions.assertTrue(currency.isSupplyMutable());
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent.
@Test
void getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent() throws Exception {
MosaicId mosaicId = new MosaicId(BigInteger.TEN);
Account account = Account.generateNewAccount(NetworkType.MAIN_NET);
BigInteger supply = BigInteger.valueOf(12);
MosaicInfo mosaicInfo = new MosaicInfo("abc", 1, mosaicId, supply, BigInteger.ONE, account.getAddress(), 4L, MosaicFlags.create(true, true, true), 10, BigInteger.TEN);
Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Arrays.asList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicInfo)));
String name = "some.alias";
NamespaceId namespaceId = NamespaceId.createFromName(name);
MosaicNames mosaicNames = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName(name), new NamespaceName("some.alias2")));
MosaicNames mosaicNames2 = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName("some.alias2"), new NamespaceName("some.alias3")));
Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicNames, mosaicNames2)));
Currency currency = service.getCurrency(mosaicId).toFuture().get();
Assertions.assertEquals(10, currency.getDivisibility());
Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
Assertions.assertEquals(namespaceId, currency.getNamespaceId().get());
Assertions.assertEquals("some.alias", currency.getNamespaceId().get().getFullName().get());
Assertions.assertTrue(currency.isTransferable());
Assertions.assertTrue(currency.isSupplyMutable());
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TransactionRepositoryOkHttpImplTest method getSignedTransaction.
private SignedTransaction getSignedTransaction() {
String generationHash = "A94B1BE81F1D4C95D6D252AD7BA3FFFB1674991FD880B7A57DC3180AF8D69C32";
Account account = Account.createFromPrivateKey("063F36659A8BB01D5685826C19E2C2CA9D281465B642BD5E43CB69510408ECF7", networkType);
Address address = Address.generateRandom(networkType);
TransferTransaction transferTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, deadline, address, Collections.singletonList(createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneTransferTransaction:message")).build();
SignedTransaction signedTransaction = account.sign(transferTransaction, generationHash);
String payload = signedTransaction.getPayload();
assertEquals(444, payload.length());
return signedTransaction;
}
Aggregations