Search in sources :

Example 36 with TransactionInfoDTO

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

the class TransactionMapperSerializationOkHttpTest method testDtoToModelMapping.

@ParameterizedTest
@MethodSource("transactionJsonFiles")
void testDtoToModelMapping(String jsonFilename) {
    String json = TestHelperOkHttp.loadResource(jsonFilename);
    TransactionInfoDTO originalTransactionInfo = jsonHelper.parse(json, TransactionInfoDTO.class);
    Transaction transactionModel = transactionMapper.mapFromDto(originalTransactionInfo);
    Integer version = jsonHelper.getInteger(originalTransactionInfo, "transaction", "version");
    Integer type = jsonHelper.getInteger(originalTransactionInfo, "transaction", "type");
    Integer network = jsonHelper.getInteger(originalTransactionInfo, "transaction", "network");
    Assertions.assertEquals(transactionModel.getVersion(), version);
    Assertions.assertEquals(transactionModel.getType().getValue(), type);
    Assertions.assertEquals(transactionModel.getNetworkType().getValue(), network);
    Assertions.assertNotNull(transactionModel);
    TransactionInfoDTO mappedTransactionInfo = (TransactionInfoDTO) transactionMapper.mapToDto(transactionModel);
    Map<String, Object> transactionMap = jsonHelper.convert(mappedTransactionInfo.getTransaction(), Map.class);
    Map<String, Object> originalTransactionMap = jsonHelper.convert(originalTransactionInfo.getTransaction(), Map.class);
    originalTransactionMap.put("size", transactionModel.getSize());
    originalTransactionInfo.setTransaction(originalTransactionMap);
    // Patching the sort
    mappedTransactionInfo.setTransaction(transactionMap);
    mappedTransactionInfo.setMeta(jsonHelper.convert(mappedTransactionInfo.getMeta(), Map.class));
    BinarySerialization serialization = new BinarySerializationImpl();
    String serialized = ConvertUtils.toHex(serialization.serialize(transactionModel));
    TransactionBuilder builder = TransactionBuilderHelper.loadFromBinary(SerializationUtils.toDataInput(serialization.serialize(transactionModel)));
    System.out.println(ConvertUtils.toHex(builder.serialize()));
    serialization.deserialize(serialization.serialize(transactionModel));
    Assertions.assertEquals(jsonHelper.prettyPrint(originalTransactionInfo), jsonHelper.prettyPrint(mappedTransactionInfo));
    Assertions.assertEquals(serialized, ConvertUtils.toHex(serialization.serialize(transactionMapper.mapFromDto(mappedTransactionInfo))));
    originalTransactionInfo.setMeta(null);
    Map<String, Object> transactionJson = (Map<String, Object>) originalTransactionInfo.getTransaction();
    if (transactionJson.containsKey("transactions")) {
        List<Map<String, Object>> transactionsJson = (List<Map<String, Object>>) transactionJson.get("transactions");
        transactionsJson.forEach(t -> t.remove("meta"));
    }
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) TransactionBuilder(io.nem.symbol.catapult.builders.TransactionBuilder) List(java.util.List) Map(java.util.Map) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 37 with TransactionInfoDTO

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

the class TransactionMapperOkHttpTest method shouldCreateAccountOperationRestriction.

@Test
public void shouldCreateAccountOperationRestriction() throws Exception {
    TransactionInfoDTO transactionInfoDTO = TestHelperOkHttp.loadTransactionInfoDTO("accountOperationRestrictionTransaction.json");
    AccountOperationRestrictionTransaction transaction = (AccountOperationRestrictionTransaction) map(transactionInfoDTO);
    validateStandaloneTransaction(transaction, transactionInfoDTO);
    Assertions.assertEquals(AccountOperationRestrictionFlags.ALLOW_OUTGOING_TRANSACTION_TYPE, transaction.getRestrictionFlags());
    Assertions.assertEquals(1, transaction.getRestrictionAdditions().size());
    Assertions.assertEquals(TransactionType.MOSAIC_METADATA, transaction.getRestrictionAdditions().get(0));
}
Also used : TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) Test(org.junit.jupiter.api.Test)

Example 38 with TransactionInfoDTO

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

the class TransactionMapperOkHttpTest method shouldCreateAggregateSubNamespaceCreationTransaction.

@Test
void shouldCreateAggregateSubNamespaceCreationTransaction() {
    TransactionInfoDTO aggregateNamespaceCreationTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateSubNamespaceCreationTransaction.json");
    Transaction aggregateNamespaceCreationTransaction = map(aggregateNamespaceCreationTransactionDTO);
    validateAggregateTransaction((AggregateTransaction) aggregateNamespaceCreationTransaction, aggregateNamespaceCreationTransactionDTO);
}
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) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) Test(org.junit.jupiter.api.Test)

Example 39 with TransactionInfoDTO

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

the class TransactionMapperOkHttpTest method shouldCreateAggregateRootNamespaceCreationTransaction.

@Test
void shouldCreateAggregateRootNamespaceCreationTransaction() {
    TransactionInfoDTO aggregateNamespaceCreationTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateRootNamespaceCreationTransaction.json");
    Transaction aggregateNamespaceCreationTransaction = map(aggregateNamespaceCreationTransactionDTO);
    validateAggregateTransaction((AggregateTransaction) aggregateNamespaceCreationTransaction, aggregateNamespaceCreationTransactionDTO);
}
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) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) Test(org.junit.jupiter.api.Test)

Example 40 with TransactionInfoDTO

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

the class TransactionMapperOkHttpTest method shouldCreateAggregateMultisigModificationTransaction.

@Test
void shouldCreateAggregateMultisigModificationTransaction() {
    TransactionInfoDTO aggregateMultisigModificationTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMultisigModificationTransaction.json");
    Transaction aggregateMultisigModificationTransaction = map(aggregateMultisigModificationTransactionDTO);
    validateAggregateTransaction((AggregateTransaction) aggregateMultisigModificationTransaction, aggregateMultisigModificationTransactionDTO);
}
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) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) Test(org.junit.jupiter.api.Test)

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