Search in sources :

Example 21 with PublicAccount

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

the class MosaicRepositoryVertxImplTest method shouldGetMosaicsFromAccount.

@Test
public void shouldGetMosaicsFromAccount() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499AAA");
    MosaicDTO mosaicDto = new MosaicDTO();
    mosaicDto.setOwnerAddress(address.encoded());
    mosaicDto.setId("481110499AAA");
    mosaicDto.setRevision(123L);
    mosaicDto.setFlags(5);
    mosaicDto.setDivisibility(6);
    mosaicDto.setVersion(1);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mockRemoteCall(toPage(new MosaicInfoDTO().mosaic(mosaicDto).id("ABC")));
    List<MosaicInfo> resolvedList = repository.search(new MosaicSearchCriteria().ownerAddress(publicAccount.getAddress())).toFuture().get().getData();
    Assertions.assertEquals(1, resolvedList.size());
    MosaicInfo mosaicInfo = resolvedList.get(0);
    Assertions.assertEquals(mosaicId, mosaicInfo.getMosaicId());
    Assertions.assertEquals(mosaicDto.getRevision(), mosaicInfo.getRevision());
    Assertions.assertEquals(mosaicDto.getOwnerAddress(), mosaicInfo.getOwnerAddress().encoded(NetworkType.MIJIN_TEST));
    Assertions.assertFalse(mosaicInfo.isTransferable());
    Assertions.assertEquals(6, mosaicInfo.getDivisibility());
    Assertions.assertEquals(BigInteger.valueOf(7), mosaicInfo.getDuration());
    Assertions.assertEquals(mosaicDto.getStartHeight(), mosaicInfo.getStartHeight());
    Assertions.assertEquals(mosaicDto.getSupply(), mosaicInfo.getSupply());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) Address(io.nem.symbol.sdk.model.account.Address) MosaicDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 22 with PublicAccount

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

the class TransactionRepositoryOkHttpImplTest method searchTransactionsTransactionTypesPartial.

@Test
public void searchTransactionsTransactionTypesPartial() throws Exception {
    TransactionInfoDTO transferTransactionDTO = loadTransactionInfoDTO("standaloneTransferTransaction.json", TransactionInfoDTO.class);
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    mockRemoteCall(toPage(transferTransactionDTO));
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.PARTIAL).transactionTypes(Arrays.asList(TransactionType.NAMESPACE_METADATA, TransactionType.AGGREGATE_COMPLETE));
    Page<Transaction> transactions = repository.search(criteria.address(publicAccount.getAddress())).toFuture().get();
    Assertions.assertEquals(TransactionType.TRANSFER, transactions.getData().get(0).getType());
    Assertions.assertEquals(TransactionGroup.PARTIAL, transactions.getData().get(0).getGroup().get());
    Assertions.assertEquals(1, transactions.getData().size());
    Assertions.assertEquals(1, transactions.getPageNumber());
    Assertions.assertEquals(2, transactions.getPageSize());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TestHelperOkHttp.loadTransactionInfoDTO(io.nem.symbol.sdk.infrastructure.okhttp.TestHelperOkHttp.loadTransactionInfoDTO) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AnnounceTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 23 with PublicAccount

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

the class TransactionRepositoryOkHttpImplTest method searchTransactionsTransactionTypes.

@Test
public void searchTransactionsTransactionTypes() throws Exception {
    TransactionInfoDTO transferTransactionDTO = loadTransactionInfoDTO("standaloneTransferTransaction.json", TransactionInfoDTO.class);
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    mockRemoteCall(toPage(transferTransactionDTO));
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.CONFIRMED).transactionTypes(Arrays.asList(TransactionType.NAMESPACE_METADATA, TransactionType.AGGREGATE_COMPLETE));
    Page<Transaction> transactions = repository.search(criteria.address(publicAccount.getAddress())).toFuture().get();
    Assertions.assertEquals(TransactionType.TRANSFER, transactions.getData().get(0).getType());
    Assertions.assertEquals(TransactionGroup.CONFIRMED, transactions.getData().get(0).getGroup().get());
    Assertions.assertEquals(1, transactions.getData().size());
    Assertions.assertEquals(1, transactions.getPageNumber());
    Assertions.assertEquals(2, transactions.getPageSize());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TestHelperOkHttp.loadTransactionInfoDTO(io.nem.symbol.sdk.infrastructure.okhttp.TestHelperOkHttp.loadTransactionInfoDTO) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AnnounceTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 24 with PublicAccount

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

the class OkHttpAggregateTransactionTest method createAAggregateTransactionViaStaticConstructor.

@Test
void createAAggregateTransactionViaStaticConstructor() {
    Duration epochAdjustment = Duration.ofSeconds(100);
    Address recipient = Address.generateRandom(NetworkType.MIJIN_TEST);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, recipient, Collections.emptyList()).message(new PlainMessage("")).build();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, Deadline.create(epochAdjustment), Collections.singletonList(transferTx.toAggregate(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", networkType)))).build();
    assertEquals(networkType, aggregateTx.getNetworkType());
    assertEquals(1, (int) aggregateTx.getVersion());
    assertTrue(LocalDateTime.now().isBefore(aggregateTx.getDeadline().getLocalDateTime(epochAdjustment)));
    assertEquals(BigInteger.valueOf(0), aggregateTx.getMaxFee());
    assertEquals(1, aggregateTx.getInnerTransactions().size());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test)

Example 25 with PublicAccount

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

the class OkHttpAggregateTransactionTest method serialization.

@Test
@DisplayName("Serialization")
void serialization() {
    Address address = Address.generateRandom(networkType);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, address, Collections.singletonList(createAbsolute(BigInteger.valueOf(10000000)))).message(new PlainMessage("")).build();
    PublicAccount signer = Account.generateNewAccount(networkType).getPublicAccount();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, deadline, Collections.singletonList(transferTx.toAggregate(signer))).build();
    byte[] actual = aggregateTx.serialize();
    BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
    AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(actual);
    assertEquals(signer, deserialized.getInnerTransactions().get(0).getSigner().get());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)35 Test (org.junit.jupiter.api.Test)30 Address (io.nem.symbol.sdk.model.account.Address)16 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)14 BigInteger (java.math.BigInteger)13 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)11 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)9 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)8 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)8 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)7 DisplayName (org.junit.jupiter.api.DisplayName)7 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)6 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)5 BinarySerialization (io.nem.symbol.sdk.api.BinarySerialization)4 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)4 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)3 TestHelperOkHttp.loadTransactionInfoDTO (io.nem.symbol.sdk.infrastructure.okhttp.TestHelperOkHttp.loadTransactionInfoDTO)3 Account (io.nem.symbol.sdk.model.account.Account)3 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)3