use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class AbstractTransactionTester method assertAggregate.
/**
* This method asserts that the given transaction, if put into a aggregate transaction, can be
* reproduced.
*
* <p>It also asserts that the transaction can be deserialized back to the same aggregate
* transaction.
*
* @param transaction the transaction under test
* @param <T> the type of the transaction.
* @return the cloned transaction
*/
protected <T extends Transaction> T assertAggregate(T transaction) {
byte[] actual = transaction.serialize();
// Clone
T deserialized = (T) binarySerialization.deserialize(actual);
String generationHash = "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6";
Account account = Account.generateNewAccount(deserialized.getNetworkType());
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, deserialized.getNetworkType(), deserialized.getDeadline(), Collections.singletonList(deserialized.toAggregate(account.getPublicAccount())), Collections.emptyList()).maxFee(BigInteger.TEN).build();
account.sign(aggregateTransaction, generationHash);
byte[] serializedAggregate = aggregateTransaction.serialize();
assertEquals(serializedAggregate.length, aggregateTransaction.getSize());
assertEquals(ConvertUtils.toHex(serializedAggregate), ConvertUtils.toHex(binarySerialization.deserialize(serializedAggregate).serialize()));
return deserialized;
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method setup.
@BeforeAll
public static void setup() {
account = new Account("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", networkType);
generationHash = "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6";
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class SignedTransactionTest method createASignedTransactionViaConstructor.
@Test
void createASignedTransactionViaConstructor() {
Account signer = Account.generateNewAccount(NetworkType.MIJIN_TEST);
SignedTransaction signedTransaction = new SignedTransaction(signer.getPublicAccount(), "payload", "hash", TransactionType.TRANSFER);
assertEquals("payload", signedTransaction.getPayload());
assertEquals("hash", signedTransaction.getHash());
assertEquals(TransactionType.TRANSFER, signedTransaction.getType());
assertEquals(signer.getPublicAccount(), signedTransaction.getSigner());
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TransactionRepositoryVertxImplTest method announceAggregateBondedCosignature.
@Test
public void announceAggregateBondedCosignature() throws Exception {
Account signer = Account.generateNewAccount(networkType);
BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
CosignatureSignedTransaction signedTransaction = new CosignatureSignedTransaction(version, "aParentHash", "aSignature", signer.getPublicAccount());
AnnounceTransactionInfoDTO announceTransactionInfoDTO = new AnnounceTransactionInfoDTO();
announceTransactionInfoDTO.setMessage("SomeMessage");
ArgumentCaptor<Object> parameter = mockRemoteCall(announceTransactionInfoDTO);
TransactionAnnounceResponse response = repository.announceAggregateBondedCosignature(signedTransaction).toFuture().get();
Assertions.assertNotNull(response);
Assertions.assertEquals(announceTransactionInfoDTO.getMessage(), announceTransactionInfoDTO.getMessage());
Cosignature cosignature = (Cosignature) parameter.getValue();
Assertions.assertEquals(signedTransaction.getParentHash(), cosignature.getParentHash());
Assertions.assertEquals(signedTransaction.getSignature(), cosignature.getSignature());
Assertions.assertEquals(signedTransaction.getSigner().getPublicKey().toHex(), cosignature.getSignerPublicKey());
Assertions.assertEquals(signedTransaction.getVersion(), cosignature.getVersion());
}
use of io.nem.symbol.sdk.model.account.Account 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());
}
Aggregations