Search in sources :

Example 1 with TransactionMetaDTO

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

the class TransactionMapperVertxTest method validateAggregateTransaction.

void validateAggregateTransaction(AggregateTransaction aggregateTransaction, TransactionInfoDTO transactionDTO) {
    AggregateTransactionBodyExtendedDTO aggregateTransactionBodyDTO = jsonHelper.convert(transactionDTO.getTransaction(), AggregateTransactionBodyExtendedDTO.class);
    TransactionMetaDTO meta = jsonHelper.convert(transactionDTO.getMeta(), TransactionMetaDTO.class);
    if (aggregateTransaction.getTransactionInfo().isPresent()) {
        TransactionInfo transactionInfo = aggregateTransaction.getTransactionInfo().get();
        assertEquals(meta.getHeight(), transactionInfo.getHeight());
        if (transactionInfo.getHash().isPresent()) {
            assertEquals(meta.getHash(), transactionInfo.getHash().get());
        }
        if (transactionInfo.getMerkleComponentHash().isPresent()) {
            assertEquals(meta.getMerkleComponentHash(), transactionInfo.getMerkleComponentHash().get());
        }
        if (transactionInfo.getIndex().isPresent()) {
            assertEquals(transactionInfo.getIndex().get(), meta.getIndex());
        }
    }
    // if (aggregateTransaction.getTransactionInfo().get().getId().isPresent()) {
    // assertEquals(
    // transactionDTO.getMeta().getId(),
    // aggregateTransaction.getTransactionInfo().get().getId().get());
    // }
    assertEquals(jsonHelper.getString(transactionDTO.getTransaction(), "signature"), aggregateTransaction.getSignature().get());
    assertEquals(jsonHelper.getString(transactionDTO.getTransaction(), "signerPublicKey"), aggregateTransaction.getSigner().get().getPublicKey().toHex());
    int version = jsonHelper.getInteger(transactionDTO.getTransaction(), "version");
    assertEquals((int) aggregateTransaction.getVersion(), version);
    int networkType = jsonHelper.getInteger(transactionDTO.getTransaction(), "network");
    assertEquals(aggregateTransaction.getNetworkType().getValue(), networkType);
    assertEquals(aggregateTransaction.getType().getValue(), (int) jsonHelper.getInteger(transactionDTO.getTransaction(), "type"));
    assertEquals(jsonHelper.getBigInteger(transactionDTO.getTransaction(), "maxFee"), aggregateTransaction.getMaxFee());
    assertNotNull(aggregateTransaction.getDeadline());
    assertEquals(aggregateTransactionBodyDTO.getCosignatures().get(0).getSignature(), aggregateTransaction.getCosignatures().get(0).getSignature());
    assertEquals(aggregateTransactionBodyDTO.getCosignatures().get(0).getSignerPublicKey(), aggregateTransaction.getCosignatures().get(0).getSigner().getPublicKey().toHex());
    Transaction innerTransaction = aggregateTransaction.getInnerTransactions().get(0);
    validateStandaloneTransaction(innerTransaction, jsonHelper.convert(aggregateTransactionBodyDTO.getTransactions().get(0), TransactionInfoDTO.class), transactionDTO);
}
Also used : SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AccountKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) AggregateTransactionBodyExtendedDTO(io.nem.symbol.sdk.openapi.vertx.model.AggregateTransactionBodyExtendedDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) TransactionInfo(io.nem.symbol.sdk.model.transaction.TransactionInfo) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)

Example 2 with TransactionMetaDTO

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

the class TransactionMapperVertxTest method validateStandaloneTransaction.

void validateStandaloneTransaction(Transaction transaction, TransactionInfoDTO transactionDTO, TransactionInfoDTO parentTransaction) {
    TransactionMetaDTO meta = jsonHelper.convert(transactionDTO.getMeta(), TransactionMetaDTO.class);
    if (transaction.getTransactionInfo().isPresent()) {
        TransactionInfo transactionInfo = transaction.getTransactionInfo().get();
        assertEquals(meta.getHeight(), transactionInfo.getHeight());
        if (transactionInfo.getHash().isPresent()) {
            assertEquals(meta.getHash(), transactionInfo.getHash().get());
        }
        if (transactionInfo.getMerkleComponentHash().isPresent()) {
            assertEquals(meta.getMerkleComponentHash(), transactionInfo.getMerkleComponentHash().get());
        }
        if (transactionInfo.getIndex().isPresent()) {
            assertEquals(transactionInfo.getIndex().get(), meta.getIndex());
        }
    }
    // if (transaction.getTransactionInfo().get().getId().isPresent()) {
    // assertEquals(
    // transactionDTO.getMeta().getId(),
    // transaction.getTransactionInfo().get().getId().get());
    // }
    // if (transaction.getTransactionInfo().get().getAggregateHash().isPresent()) {
    // assertEquals(
    // transactionDTO.getMeta().getAggregateHash(),
    // transaction.getTransactionInfo().get().getAggregateHash().get());
    // }
    // if (transaction.getTransactionInfo().get().getAggregateId().isPresent()) {
    // assertEquals(
    // transactionDTO.getMeta().getAggregateId(),
    // transaction.getTransactionInfo().get().getAggregateId().get());
    // }
    assertEquals(jsonHelper.getString(parentTransaction.getTransaction(), "signature"), transaction.getSignature().get());
    assertEquals(jsonHelper.getString(transactionDTO.getTransaction(), "signerPublicKey"), transaction.getSigner().get().getPublicKey().toHex());
    assertEquals(transaction.getType().getValue(), (int) jsonHelper.getInteger(transactionDTO.getTransaction(), "type"));
    int version = jsonHelper.getInteger(transactionDTO.getTransaction(), "version");
    assertEquals((int) transaction.getVersion(), version);
    int networkType = jsonHelper.getInteger(transactionDTO.getTransaction(), "network");
    assertEquals(transaction.getNetworkType().getValue(), networkType);
    assertEquals(jsonHelper.getBigInteger(parentTransaction.getTransaction(), "maxFee"), transaction.getMaxFee());
    assertNotNull(transaction.getDeadline());
    if (transaction.getType() == TransactionType.TRANSFER) {
        validateTransferTx((TransferTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.NAMESPACE_REGISTRATION) {
        validateNamespaceCreationTx((NamespaceRegistrationTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.MOSAIC_DEFINITION) {
        validateMosaicCreationTx((MosaicDefinitionTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.MOSAIC_SUPPLY_CHANGE) {
        validateMosaicSupplyChangeTx((MosaicSupplyChangeTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.MULTISIG_ACCOUNT_MODIFICATION) {
        validateMultisigModificationTx((MultisigAccountModificationTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.HASH_LOCK) {
        validateLockFundsTx((HashLockTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.SECRET_LOCK) {
        validateSecretLockTx((SecretLockTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.SECRET_PROOF) {
        validateSecretProofTx((SecretProofTransaction) transaction, transactionDTO);
    }
}
Also used : MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) TransactionInfo(io.nem.symbol.sdk.model.transaction.TransactionInfo) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)

Example 3 with TransactionMetaDTO

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

the class ListenerVertxTest method subscribeValid.

@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeValid(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), NETWORK_TYPE);
    String channelName = channel.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    BiFunction<UnresolvedAddress, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmedOrError : listener::aggregateBondedAddedOrError;
    TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
    subscriber.apply(address, meta.getHash()).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ArrayList(java.util.ArrayList) Observable(io.reactivex.Observable) 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.vertx.model.TransactionInfoDTO) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TransactionMetaDTO

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

the class ListenerVertxTest method subscribeValidUsingBase.

@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeValidUsingBase(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), NETWORK_TYPE);
    String channelName = channel.toString();
    List<ListenerMessage<Transaction>> messages = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
    listener.subscribe(new ListenerRequest<Transaction>(channel, address).transactionHashOrError(meta.getHash())).doOnError(exceptions::add).forEach(messages::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, messages.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(meta.getHash(), messages.get(0).getTransactionHash());
    Assertions.assertEquals(channel, messages.get(0).getChannel());
    Assertions.assertEquals(address.plain(), messages.get(0).getChannelParams());
    Assertions.assertEquals(channelName + "/" + address.plain(), messages.get(0).getTopic());
    Assertions.assertEquals(address, messages.get(0).getMessage().getSigner().get().getAddress());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ArrayList(java.util.ArrayList) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) ListenerRequest(io.nem.symbol.sdk.infrastructure.ListenerRequest) ListenerMessage(io.nem.symbol.sdk.infrastructure.ListenerMessage) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TransactionMetaDTO

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

the class ListenerVertxTest method subscribeOnError.

@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeOnError(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), NETWORK_TYPE);
    String channelName = channel.toString();
    Map<String, Object> transactionStatusError = new HashMap<>();
    transactionStatusError.put("address", address.encoded());
    transactionStatusError.put("code", "Fail 666");
    TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
    transactionStatusError.put("hash", meta.getHash());
    transactionStatusError.put("deadline", 123);
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    BiFunction<Address, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmedOrError : listener::aggregateBondedAddedOrError;
    subscriber.apply(address, meta.getHash()).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 " + meta.getHash(), exceptions.get(0).getMessage());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Observable(io.reactivex.Observable) 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.vertx.model.TransactionInfoDTO) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)9 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)5 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)5 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)5 ArrayList (java.util.ArrayList)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 Address (io.nem.symbol.sdk.model.account.Address)4 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)4 Observable (io.reactivex.Observable)4 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)2 TestHelperVertx.loadTransactionInfoDTO (io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)2 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)2 SecretProofTransaction (io.nem.symbol.sdk.model.transaction.SecretProofTransaction)2 TransactionInfo (io.nem.symbol.sdk.model.transaction.TransactionInfo)2 AnnounceTransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO)2