use of io.nem.symbol.sdk.model.account.PublicAccount 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.account.PublicAccount 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());
}
use of io.nem.symbol.sdk.model.account.PublicAccount 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.account.PublicAccount 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.account.PublicAccount in project nem2-sdk-java by nemtech.
the class ImportanceBlockInfoTest method createANewBlockInfo.
@Test
void createANewBlockInfo() {
String proofGamma = "proofGamma";
String proofScalar = "proofScalar";
String proofVerificationHash = "proofVerificationHash";
String hash = "24E92B511B54EDB48A4850F9B42485FDD1A30589D92C775632DDDD71D7D1D691";
String generationHash = "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6";
String signature = "37351C8244AC166BE6664E3FA954E99A3239AC46E51E2B32CEA1C72DD0851100A7731868E932E1A9BEF8A27D48E1" + "FFEE401E933EB801824373E7537E51733E0F";
PublicAccount signer = Account.generateNewAccount(NetworkType.MIJIN_TEST).getPublicAccount();
String previousBlockHash = "0000000000000000000000000000000000000000000000000000000000000000";
String blockTransactionsHash = "702090BA31CEF9E90C62BBDECC0CCCC0F88192B6625839382850357F70DD68A0";
String blockReceiptsHash = "702090BA31CEF9E90C62BBDECC0CCCC0F88192B6625839382850357F70DD68A0";
String stateHash = "702090BA31CEF9E90C62BBDECC0CCCC0F88192B6625839382850357F70DD68A0";
List<String> subCacheMerkleRoots = new ArrayList<>();
Address beneficiaryAddress = Account.generateNewAccount(NetworkType.MIJIN_TEST).getAddress();
String id = "abc";
List<String> stateHashSubCacheMerkleRoots = Arrays.asList("abc");
long votingEligibleAccountsCount = 100;
BigInteger harvestingEligibleAccountsCount = BigInteger.valueOf(20);
BigInteger totalVotingBalance = BigInteger.valueOf(300);
String previousImportanceBlockHash = "prhash";
ImportanceBlockInfo blockInfo = new ImportanceBlockInfo(id, 10L, hash, generationHash, BigInteger.ZERO, stateHashSubCacheMerkleRoots, 25, 20, 35, subCacheMerkleRoots, signature, signer, NetworkType.MIJIN_TEST, 1, BlockType.IMPORTANCE_BLOCK, BigInteger.ONE, BigInteger.ZERO, BigInteger.valueOf(276447232L), 1L, previousBlockHash, blockTransactionsHash, blockReceiptsHash, stateHash, proofGamma, proofScalar, proofVerificationHash, beneficiaryAddress, votingEligibleAccountsCount, harvestingEligibleAccountsCount, totalVotingBalance, previousImportanceBlockHash);
assertEquals(hash, blockInfo.getHash());
assertEquals(generationHash, blockInfo.getGenerationHash());
assertEquals(BigInteger.valueOf(0), blockInfo.getTotalFee());
assertEquals(10L, blockInfo.getSize());
assertEquals(25, blockInfo.getTransactionsCount());
assertEquals(20, blockInfo.getTotalTransactionsCount());
assertEquals(35, blockInfo.getStatementsCount());
assertEquals(signature, blockInfo.getSignature());
Assertions.assertEquals(signer, blockInfo.getSignerPublicAccount());
assertEquals(NetworkType.MIJIN_TEST, blockInfo.getNetworkType());
assertEquals(1, (int) blockInfo.getVersion());
assertEquals(BlockType.IMPORTANCE_BLOCK, blockInfo.getType());
assertEquals(BigInteger.valueOf(1), blockInfo.getHeight());
assertEquals(BigInteger.valueOf(0), blockInfo.getTimestamp());
assertEquals(BigInteger.valueOf(276447232), blockInfo.getDifficulty());
assertEquals(1, blockInfo.getFeeMultiplier());
assertEquals(previousBlockHash, blockInfo.getPreviousBlockHash());
assertEquals(blockTransactionsHash, blockInfo.getBlockTransactionsHash());
assertEquals(blockReceiptsHash, blockInfo.getBlockReceiptsHash());
assertEquals(stateHash, blockInfo.getStateHash());
assertEquals(beneficiaryAddress, blockInfo.getBeneficiaryAddress());
assertEquals(proofGamma, blockInfo.getProofGamma());
assertEquals(proofScalar, blockInfo.getProofScalar());
assertEquals(proofVerificationHash, blockInfo.getProofVerificationHash());
assertEquals("abc", blockInfo.getRecordId().get());
assertEquals(stateHashSubCacheMerkleRoots, blockInfo.getStateHashSubCacheMerkleRoots());
assertEquals(votingEligibleAccountsCount, blockInfo.getVotingEligibleAccountsCount());
assertEquals(harvestingEligibleAccountsCount, blockInfo.getHarvestingEligibleAccountsCount());
assertEquals(totalVotingBalance, blockInfo.getTotalVotingBalance());
assertEquals(previousImportanceBlockHash, blockInfo.getPreviousImportanceBlockHash());
}
Aggregations