use of io.nem.symbol.sdk.model.mosaic.MosaicId 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());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId 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)));
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId 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)));
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId 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)));
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class AccountTest method shouldSignTransaction.
@Test
void shouldSignTransaction() {
Account account = new Account("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", NetworkType.MIJIN_TEST);
TransferTransaction transferTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", NetworkType.MIJIN_TEST), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("")).build();
SignedTransaction signedTransaction = account.sign(transferTransaction, generationHash);
String payload = signedTransaction.getPayload();
assertEquals("B10000000000000013193EF4F0D94DE26249D196A0575944877D5572CE13B80E4E8380FA34F9F54FF936F96162473857546F7B624A6248D8F7B3D0142DC85BBB06EB7BFEE125880B2134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F200000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0100010000000000672B0000CE560000640000000000000000", payload);
assertEquals("58D649ABF9A26AFB3F070E26F157920DAB6423415B4344108B93EDD80DE330E5", signedTransaction.getHash());
}
Aggregations