Search in sources :

Example 51 with TransactionInfoDTO

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

the class ListenerOkHttpTest method confirmedUsingHash.

@Test
public void confirmedUsingHash() 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();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.confirmedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    final Address address1 = transactions.get(0).getSigner().get().getAddress();
    Assertions.assertEquals(address, address1);
    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) 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) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 52 with TransactionInfoDTO

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

the class ListenerOkHttpTest method aggregateBondedAddedRaisingError.

@Test
public void aggregateBondedAddedRaisingError() 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.AGGREGATE_BONDED_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.aggregateBondedAddedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    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())));
    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());
}
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 53 with TransactionInfoDTO

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

the class AbstractTransactionMapper method mapToDto.

@Override
public Object mapToDto(Transaction transaction, Boolean embedded) {
    if (transaction.getTransactionInfo().flatMap(TransactionInfo::getAggregateHash).isPresent() || Boolean.TRUE.equals(embedded)) {
        EmbeddedTransactionInfoDTO dto = new EmbeddedTransactionInfoDTO();
        dto.setMeta(createTransactionInfoEmbedded(transaction));
        dto.setId(transaction.getRecordId().orElse(null));
        dto.setTransaction(mapTransaction(transaction, true));
        return dto;
    } else {
        TransactionInfoDTO dto = new TransactionInfoDTO();
        dto.setMeta(createTransactionInfo(transaction));
        dto.setId(transaction.getRecordId().orElse(null));
        dto.setTransaction(mapTransaction(transaction, false));
        return dto;
    }
}
Also used : TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) EmbeddedTransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.EmbeddedTransactionInfoDTO) TransactionInfo(io.nem.symbol.sdk.model.transaction.TransactionInfo) EmbeddedTransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.EmbeddedTransactionInfoDTO)

Aggregations

TransactionInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO)53 Test (org.junit.jupiter.api.Test)49 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)41 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)35 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)32 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)28 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)28 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)28 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)28 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)28 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)28 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)27 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)27 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)27 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)27 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)27 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)27 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)27 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)27 SecretLockTransaction (io.nem.symbol.sdk.model.transaction.SecretLockTransaction)27