Search in sources :

Example 1 with Account

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;
}
Also used : Account(io.nem.symbol.sdk.model.account.Account)

Example 2 with Account

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";
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with Account

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());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) Test(org.junit.jupiter.api.Test)

Example 4 with Account

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());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) BigInteger(java.math.BigInteger) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) Cosignature(io.nem.symbol.sdk.openapi.vertx.model.Cosignature) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) Test(org.junit.jupiter.api.Test)

Example 5 with Account

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());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

Account (io.nem.symbol.sdk.model.account.Account)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)39 EnumSource (org.junit.jupiter.params.provider.EnumSource)36 Test (org.junit.jupiter.api.Test)29 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)26 BigInteger (java.math.BigInteger)21 Address (io.nem.symbol.sdk.model.account.Address)20 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)18 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)17 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)17 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)15 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)15 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)14 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)13 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)11 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)9 Currency (io.nem.symbol.sdk.model.mosaic.Currency)9 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)9 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)7