Search in sources :

Example 1 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class AggregateTransactionTest method maxFeeThreeCosignature.

@Test
void maxFeeThreeCosignature() {
    BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
    NetworkType networkType = NetworkType.MIJIN_TEST;
    AggregateTransactionCosignature cosignature1 = new AggregateTransactionCosignature(version, "AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", networkType));
    AggregateTransactionCosignature cosignature2 = new AggregateTransactionCosignature(version, "BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", networkType));
    AggregateTransactionCosignature cosignature3 = new AggregateTransactionCosignature(version, "CCC9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456333", networkType));
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    AggregateTransactionFactory aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_COMPLETE, networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transaction1), Arrays.asList(cosignature1, cosignature2, cosignature3));
    int multiplier = 10;
    Assertions.assertThrows(IllegalArgumentException.class, () -> aggregateTransaction.calculateMaxFeeFromMultiplier(multiplier));
    aggregateTransaction.calculateMaxFeeForAggregate(multiplier, 1);
    Assertions.assertEquals(BigInteger.valueOf(aggregateTransaction.getSize() * multiplier), aggregateTransaction.getMaxFee());
    aggregateTransaction.calculateMaxFeeForAggregate(multiplier, 2);
    Assertions.assertEquals(BigInteger.valueOf(aggregateTransaction.getSize() * multiplier), aggregateTransaction.getMaxFee());
    aggregateTransaction.calculateMaxFeeForAggregate(multiplier, 3);
    Assertions.assertEquals(BigInteger.valueOf(aggregateTransaction.getSize() * multiplier), aggregateTransaction.getMaxFee());
    aggregateTransaction.calculateMaxFeeForAggregate(multiplier, 4);
    Assertions.assertEquals(BigInteger.valueOf(multiplier * (aggregateTransaction.getSize() + AggregateTransactionFactory.COSIGNATURE_SIZE)), aggregateTransaction.getMaxFee());
    aggregateTransaction.calculateMaxFeeForAggregate(multiplier, 5);
    Assertions.assertEquals(BigInteger.valueOf(multiplier * (aggregateTransaction.getSize() + AggregateTransactionFactory.COSIGNATURE_SIZE * 2)), aggregateTransaction.getMaxFee());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 2 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class AggregateTransactionTest method serializeTwoTransaction.

@Test
void serializeTwoTransaction() {
    NetworkType networkType = NetworkType.MIJIN_TEST;
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    MosaicSupplyChangeTransaction transaction2 = MosaicSupplyChangeTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new MosaicId(new BigInteger("6300565133566699912")), MosaicSupplyChangeActionType.INCREASE, BigInteger.valueOf(10)).signer(account.getPublicAccount()).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Arrays.asList(transaction1, transaction2), Collections.emptyList()).build();
    BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
    String expected = "60010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001904142000000000000000001000000000000006C610D61B3E6839AE85AC18465CF6AD06D8F17A4F145F720BD324880B4FBB12BB8000000000000006D00000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E6000000000190544190F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0D00010000000000672B0000CE560000640000000000000000536F6D65204D6573736167650000004100000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E60000000001904D428869746E9B1A70570A000000000000000100000000000000";
    Assertions.assertEquals(expected, ConvertUtils.toHex(aggregateTransaction.serialize()));
    AggregateTransaction serialized = assertSerialization(expected, aggregateTransaction);
    Assertions.assertEquals(0, serialized.getCosignatures().size());
    Assertions.assertEquals(2, serialized.getInnerTransactions().size());
    Assertions.assertEquals(transaction1.getType(), serialized.getInnerTransactions().get(0).getType());
    Assertions.assertArrayEquals(binarySerialization.serializeEmbedded(transaction1), binarySerialization.serializeEmbedded(serialized.getInnerTransactions().get(0)));
    Assertions.assertEquals(transaction2.getType(), serialized.getInnerTransactions().get(1).getType());
    Assertions.assertArrayEquals(binarySerialization.serializeEmbedded(transaction2), binarySerialization.serializeEmbedded(serialized.getInnerTransactions().get(1)));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Example 3 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class AggregateTransactionTest method serializeThreeCosignature.

@Test
void serializeThreeCosignature() {
    NetworkType networkType = NetworkType.MIJIN_TEST;
    BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
    AggregateTransactionCosignature cosignature1 = new AggregateTransactionCosignature(version, "AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", networkType));
    AggregateTransactionCosignature cosignature2 = new AggregateTransactionCosignature(version, "BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", networkType));
    AggregateTransactionCosignature cosignature3 = new AggregateTransactionCosignature(version, "CCC9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456333", networkType));
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_COMPLETE, networkType, new Deadline(BigInteger.ONE), Collections.emptyList(), Arrays.asList(cosignature1, cosignature2, cosignature3)).build();
    Assertions.assertEquals(3, aggregateTransaction.getCosignatures().size());
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> assertSerialization("", aggregateTransaction));
    Assertions.assertEquals("Partially loaded and incomplete transactions cannot be serialized.", exception.getMessage());
}
Also used : NetworkType(io.nem.symbol.sdk.model.network.NetworkType) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 4 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class AggregateTransactionTest method serializeTwoTransactionTwoCosignatureUsingAdd.

@Test
void serializeTwoTransactionTwoCosignatureUsingAdd() {
    NetworkType networkType = NetworkType.MIJIN_TEST;
    BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
    AggregateTransactionCosignature cosignature1 = new AggregateTransactionCosignature(version, "AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", networkType));
    AggregateTransactionCosignature cosignature2 = new AggregateTransactionCosignature(version, "BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", networkType));
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    MosaicSupplyChangeTransaction transaction2 = MosaicSupplyChangeTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new MosaicId(new BigInteger("6300565133566699912")), MosaicSupplyChangeActionType.INCREASE, BigInteger.valueOf(10)).signer(account.getPublicAccount()).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Arrays.asList(transaction1, transaction2), Collections.singletonList(cosignature1)).addCosignatures(cosignature2).build();
    String expected = "30020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001904142000000000000000001000000000000006C610D61B3E6839AE85AC18465CF6AD06D8F17A4F145F720BD324880B4FBB12BB8000000000000006D00000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E6000000000190544190F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0D00010000000000672B0000CE560000640000000000000000536F6D65204D6573736167650000004100000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E60000000001904D428869746E9B1A70570A00000000000000010000000000000000000000000000009A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA6545611100000000000000009A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222";
    Assertions.assertEquals(expected, ConvertUtils.toHex(aggregateTransaction.serialize()));
    AggregateTransaction serialized = assertSerialization(expected, aggregateTransaction);
    Assertions.assertEquals(TransactionType.AGGREGATE_BONDED, serialized.getType());
    Assertions.assertEquals(2, serialized.getCosignatures().size());
    Assertions.assertEquals(cosignature1.getSigner(), serialized.getCosignatures().get(0).getSigner());
    Assertions.assertEquals(cosignature1.getSignature(), serialized.getCosignatures().get(0).getSignature().toUpperCase());
    Assertions.assertEquals(cosignature2.getSigner(), serialized.getCosignatures().get(1).getSigner());
    Assertions.assertEquals(cosignature2.getSignature(), serialized.getCosignatures().get(1).getSignature().toUpperCase());
    BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
    Assertions.assertEquals(2, serialized.getInnerTransactions().size());
    Assertions.assertEquals(transaction1.getType(), serialized.getInnerTransactions().get(0).getType());
    Assertions.assertArrayEquals(binarySerialization.serializeEmbedded(transaction1), binarySerialization.serializeEmbedded(serialized.getInnerTransactions().get(0)));
    Assertions.assertEquals(transaction2.getType(), serialized.getInnerTransactions().get(1).getType());
    Assertions.assertArrayEquals(binarySerialization.serializeEmbedded(transaction2), binarySerialization.serializeEmbedded(serialized.getInnerTransactions().get(1)));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Example 5 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class AggregateTransactionTest method serializeTwoTransactionTwoCosignature.

@Test
void serializeTwoTransactionTwoCosignature() {
    BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
    NetworkType networkType = NetworkType.MIJIN_TEST;
    AggregateTransactionCosignature cosignature1 = new AggregateTransactionCosignature(version, "AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111", networkType));
    AggregateTransactionCosignature cosignature2 = new AggregateTransactionCosignature(version, "BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222", networkType));
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    MosaicSupplyChangeTransaction transaction2 = MosaicSupplyChangeTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new MosaicId(new BigInteger("6300565133566699912")), MosaicSupplyChangeActionType.INCREASE, BigInteger.valueOf(10)).signer(account.getPublicAccount()).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Arrays.asList(transaction1, transaction2), Arrays.asList(cosignature1, cosignature2)).build();
    String expected = "30020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001904142000000000000000001000000000000006C610D61B3E6839AE85AC18465CF6AD06D8F17A4F145F720BD324880B4FBB12BB8000000000000006D00000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E6000000000190544190F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0D00010000000000672B0000CE560000640000000000000000536F6D65204D6573736167650000004100000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E60000000001904D428869746E9B1A70570A00000000000000010000000000000000000000000000009A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456111AAA9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA6545611100000000000000009A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222BBB9366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456222";
    Assertions.assertEquals(expected, ConvertUtils.toHex(aggregateTransaction.serialize()));
    AggregateTransaction serialized = assertSerialization(expected, aggregateTransaction);
    Assertions.assertEquals(TransactionType.AGGREGATE_BONDED, serialized.getType());
    Assertions.assertEquals(2, serialized.getCosignatures().size());
    Assertions.assertEquals(cosignature1.getSigner(), serialized.getCosignatures().get(0).getSigner());
    Assertions.assertEquals(cosignature1.getSignature(), serialized.getCosignatures().get(0).getSignature().toUpperCase());
    Assertions.assertEquals(cosignature2.getSigner(), serialized.getCosignatures().get(1).getSigner());
    Assertions.assertEquals(cosignature2.getSignature(), serialized.getCosignatures().get(1).getSignature().toUpperCase());
    BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
    Assertions.assertEquals(2, serialized.getInnerTransactions().size());
    Assertions.assertEquals(transaction1.getType(), serialized.getInnerTransactions().get(0).getType());
    Assertions.assertArrayEquals(binarySerialization.serializeEmbedded(transaction1), binarySerialization.serializeEmbedded(serialized.getInnerTransactions().get(0)));
    Assertions.assertEquals(transaction2.getType(), serialized.getInnerTransactions().get(1).getType());
    Assertions.assertArrayEquals(binarySerialization.serializeEmbedded(transaction2), binarySerialization.serializeEmbedded(serialized.getInnerTransactions().get(1)));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Aggregations

NetworkType (io.nem.symbol.sdk.model.network.NetworkType)31 Test (org.junit.jupiter.api.Test)13 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)11 BigInteger (java.math.BigInteger)10 Address (io.nem.symbol.sdk.model.account.Address)9 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)7 Account (io.nem.symbol.sdk.model.account.Account)5 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)5 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)5 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)5 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)5 Duration (java.time.Duration)5 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)3 UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)3 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)3 Optional (java.util.Optional)3 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)2