use of io.nem.symbol.sdk.api.BinarySerialization in project nem2-sdk-java by nemtech.
the class AggregateTransactionTest method basicCatbufferAggregateSerialization.
@Test
void basicCatbufferAggregateSerialization() {
String expected = "6001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000190414200000000000000000100000000000000B4C97320255A2F755F6BE2F4DDAC0BB3EBDD25508DBE460EA6988366F404706AB8000000000000006D00000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E6000000000190544190E8FEBD671DD41BEE94EC3BA5831CB608A312C2F203BA840D00010000000000672B0000CE560000640000000000000000536F6D65204D6573736167650000004100000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E60000000001904D428869746E9B1A70570A000000000000000100000000000000";
BinarySerialization serialization = new BinarySerializationImpl();
AggregateTransaction deserialize = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(expected));
Assertions.assertEquals(2, deserialize.getInnerTransactions().size());
Assertions.assertEquals(0, deserialize.getCosignatures().size());
AggregateBondedTransactionBuilder transactionBuilder = AggregateBondedTransactionBuilder.loadFromBinary(SerializationUtils.toDataInput(ConvertUtils.fromHexToBytes(expected)));
Assertions.assertEquals(2, transactionBuilder.getTransactions().size());
Assertions.assertEquals(0, transactionBuilder.getCosignatures().size());
Assertions.assertEquals(expected, ConvertUtils.toHex(deserialize.serialize()));
Assertions.assertEquals(expected, ConvertUtils.toHex(transactionBuilder.serialize()));
}
use of io.nem.symbol.sdk.api.BinarySerialization in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method createPersistentDelegationRequestTransaction.
@Test
void createPersistentDelegationRequestTransaction() {
Duration epochAdjustment = Duration.ofSeconds(100);
KeyPair signingPrivateKey = KeyPair.fromPrivate(PrivateKey.fromHexString("2602F4236B199B3DF762B2AAB46FC3B77D8DDB214F0B62538D3827576C46C111"));
KeyPair vrfPrivateKey = KeyPair.fromPrivate(PrivateKey.fromHexString("2602F4236B199B3DF762B2AAB46FC3B77D8DDB214F0B62538D3827576C46C000"));
KeyPair recipient = KeyPair.fromPrivate(PrivateKey.fromHexString("B72F2950498111BADF276D6D9D5E345F04E0D5C9B8342DA983C3395B4CF18F08"));
TransferTransaction transferTransaction = TransferTransactionFactory.createPersistentDelegationRequestTransaction(networkType, Deadline.create(epochAdjustment), signingPrivateKey.getPrivateKey(), vrfPrivateKey.getPrivateKey(), recipient.getPublicKey()).build();
assertEquals(networkType, transferTransaction.getNetworkType());
assertEquals(1, (int) transferTransaction.getVersion());
assertTrue(LocalDateTime.now().isBefore(transferTransaction.getDeadline().getLocalDateTime(epochAdjustment)));
assertEquals(BigInteger.valueOf(0), transferTransaction.getMaxFee());
assertEquals(Address.createFromPublicKey(recipient.getPublicKey().toHex(), networkType), transferTransaction.getRecipient());
assertEquals(0, transferTransaction.getMosaics().size());
assertNotNull(transferTransaction.getMessage());
assertEquals(MessageType.PERSISTENT_HARVESTING_DELEGATION_MESSAGE, transferTransaction.getMessage().get().getType());
assertNotNull(transferTransaction.getMessage().get().getText());
PersistentHarvestingDelegationMessage message = (PersistentHarvestingDelegationMessage) transferTransaction.getMessage().get();
HarvestingKeys decodedKeys = message.decryptPayload(recipient.getPrivateKey());
Assertions.assertEquals(signingPrivateKey.getPrivateKey(), decodedKeys.getSigningPrivateKey());
Assertions.assertEquals(vrfPrivateKey.getPrivateKey(), decodedKeys.getVrfPrivateKey());
byte[] actual = transferTransaction.serialize();
BinarySerialization serialization = new BinarySerializationImpl();
TransferTransaction deserialized = (TransferTransaction) serialization.deserialize(actual);
assertEquals(MessageType.PERSISTENT_HARVESTING_DELEGATION_MESSAGE, deserialized.getMessage().get().getType());
PersistentHarvestingDelegationMessage deserializedMessage = (PersistentHarvestingDelegationMessage) deserialized.getMessage().get();
HarvestingKeys decodedKeys2 = deserializedMessage.decryptPayload(recipient.getPrivateKey());
Assertions.assertEquals(signingPrivateKey.getPrivateKey(), decodedKeys2.getSigningPrivateKey());
Assertions.assertEquals(vrfPrivateKey.getPrivateKey(), decodedKeys2.getVrfPrivateKey());
}
use of io.nem.symbol.sdk.api.BinarySerialization in project nem2-sdk-java by nemtech.
the class VertxAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.
@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
Address address = Address.generateRandom(networkType);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", networkType)))).build();
Account cosignatoryAccount = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount2 = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount3 = Account.generateNewAccount(this.networkType);
SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2, cosignatoryAccount3), generationHash);
BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
Assertions.assertEquals(2, deserialized.getCosignatures().size());
Assertions.assertEquals(cosignatoryAccount2.getPublicAccount(), deserialized.getCosignatures().get(0).getSigner());
Assertions.assertEquals(cosignatoryAccount3.getPublicAccount(), deserialized.getCosignatures().get(1).getSigner());
}
use of io.nem.symbol.sdk.api.BinarySerialization in project nem2-sdk-java by nemtech.
the class VertxAggregateTransactionTest method serialization.
@Test
@DisplayName("Serialization")
void serialization() {
Address address = Address.generateRandom(networkType);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), address, Collections.singletonList(createAbsolute(BigInteger.valueOf(10000000)))).message(new PlainMessage("")).build();
PublicAccount signer = Account.generateNewAccount(networkType).getPublicAccount();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTx.toAggregate(signer))).build();
byte[] actual = aggregateTx.serialize();
BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(actual);
assertEquals(signer, deserialized.getInnerTransactions().get(0).getSigner().get());
}
use of io.nem.symbol.sdk.api.BinarySerialization in project nem2-sdk-java by nemtech.
the class OkHttpAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.
@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
Address address = Address.generateRandom(networkType);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, deadline, Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", networkType)))).build();
Account cosignatoryAccount = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount2 = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount3 = Account.generateNewAccount(this.networkType);
SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2, cosignatoryAccount3), generationHash);
BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
Assertions.assertEquals(2, deserialized.getCosignatures().size());
Assertions.assertEquals(cosignatoryAccount2.getPublicAccount(), deserialized.getCosignatures().get(0).getSigner());
Assertions.assertEquals(cosignatoryAccount3.getPublicAccount(), deserialized.getCosignatures().get(1).getSigner());
}
Aggregations