Search in sources :

Example 31 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method confirmedUsingHashUsingAlias.

@Test
public void confirmedUsingHashUsingAlias() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    NamespaceId alias = NamespaceId.createFromId(BigInteger.TEN);
    String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.confirmedOrError(alias, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + alias.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + alias.plain())));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + alias.plain())));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 32 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method confirmedUsingHashRaiseError.

@Test
public void confirmedUsingHashRaiseError() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
    Map<String, Object> transactionStatusError = new HashMap<>();
    transactionStatusError.put("address", address.encoded());
    transactionStatusError.put("code", "Fail 666");
    transactionStatusError.put("hash", getHash(transactionInfo));
    transactionStatusError.put("deadline", 123);
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.confirmedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionStatusError, "status/" + address.plain());
    Assertions.assertEquals(0, transactions.size());
    Assertions.assertEquals(1, exceptions.size());
    Assertions.assertEquals(TransactionStatusException.class, exceptions.get(0).getClass());
    Assertions.assertEquals("Fail 666 processing transaction " + getHash(transactionInfo), exceptions.get(0).getMessage());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test)

Example 33 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.

the class TransactionRepositoryOkHttpImplTest method shouldGetTransactionPartial.

@Test
public void shouldGetTransactionPartial() throws Exception {
    TransactionInfoDTO transactionInfoDTO = loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json", TransactionInfoDTO.class);
    String hash = jsonHelper.getString(transactionInfoDTO, "meta", "hash");
    mockRemoteCall(transactionInfoDTO);
    Transaction transaction = repository.getTransaction(TransactionGroup.PARTIAL, hash).toFuture().get();
    Assertions.assertNotNull(transaction);
    Assertions.assertEquals(hash, transaction.getTransactionInfo().get().getHash().get());
    Assertions.assertEquals(TransactionGroup.PARTIAL, transaction.getGroup().get());
}
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) Test(org.junit.jupiter.api.Test)

Example 34 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.

the class TransactionRepositoryOkHttpImplTest method searchTransactions.

@Test
public void searchTransactions() throws Exception {
    BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
    TransactionInfoDTO transferTransactionDTO = loadTransactionInfoDTO("standaloneTransferTransaction.json", TransactionInfoDTO.class);
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    mockRemoteCall(toPage(transferTransactionDTO));
    Page<Transaction> transactions = repository.search(new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED).signerPublicKey(publicAccount.getPublicKey())).toFuture().get();
    Assertions.assertEquals(TransactionType.TRANSFER, transactions.getData().get(0).getType());
    Assertions.assertEquals(TransactionGroup.UNCONFIRMED, 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) BigInteger(java.math.BigInteger) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 35 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.

the class TransactionRepositoryOkHttpImplTest method shouldGetTransaction.

@Test
public void shouldGetTransaction() throws Exception {
    TransactionInfoDTO transactionInfoDTO = loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json", TransactionInfoDTO.class);
    String hash = jsonHelper.getString(transactionInfoDTO, "meta", "hash");
    mockRemoteCall(transactionInfoDTO);
    Transaction transaction = repository.getTransaction(TransactionGroup.CONFIRMED, hash).toFuture().get();
    Assertions.assertNotNull(transaction);
    Assertions.assertEquals(hash, transaction.getTransactionInfo().get().getHash().get());
    Assertions.assertEquals(TransactionGroup.CONFIRMED, transaction.getGroup().get());
}
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) Test(org.junit.jupiter.api.Test)

Aggregations

Transaction (io.nem.symbol.sdk.model.transaction.Transaction)125 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)107 Test (org.junit.jupiter.api.Test)78 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)70 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)65 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)60 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)58 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)58 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)57 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)57 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)57 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)55 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)55 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)55 SecretLockTransaction (io.nem.symbol.sdk.model.transaction.SecretLockTransaction)55 SecretProofTransaction (io.nem.symbol.sdk.model.transaction.SecretProofTransaction)55 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)54 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)54 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)54 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)54