Search in sources :

Example 21 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class ListenerStatusIntegrationTest method sendTransactionsReusingListener.

@Test
void sendTransactionsReusingListener() throws ExecutionException, InterruptedException {
    RepositoryType type = DEFAULT_REPOSITORY_TYPE;
    Account account1 = config().getNemesisAccount1();
    Account account2 = Account.generateNewAccount(getNetworkType());
    Account account3 = Account.generateNewAccount(getNetworkType());
    Listener listener = createListener(type);
    listener.unconfirmedRemoved(account1.getAddress()).subscribe(a -> {
        System.out.println(">>>> account 1 " + a);
    });
    listener.unconfirmedRemoved(account2.getAddress()).subscribe(a -> {
        System.out.println(">>>> account 2 " + a);
    });
    listener.unconfirmedRemoved(account3.getAddress()).subscribe(a -> {
        System.out.println(">>>> account 3  " + a);
    });
    // IT PRINTS:
    // >>>> account 1
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 2
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 3
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 1
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 2
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 3
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account2.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
    announceAndValidate(type, account1, transferTransaction);
    sleep(1000);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) Listener(io.nem.symbol.sdk.api.Listener) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test)

Example 22 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage 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());
}
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) 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)

Example 23 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class AggregateTransactionServiceIntegrationTest method isTransferFromMultisigNotComplete.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void isTransferFromMultisigNotComplete(RepositoryType type) {
    Account multisigAccount = helper().getMultisigAccount(type).getLeft();
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), getRecipient(), Collections.emptyList()).message(new PlainMessage("")).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transferTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Collections.singletonList(config().getTestAccount()), getGenerationHash());
    AggregateTransactionService aggregateTransactionService = new AggregateTransactionServiceImpl(getRepositoryFactory(type));
    Assertions.assertFalse(get(aggregateTransactionService.isComplete(signedAggregateTransaction)));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) AggregateTransactionService(io.nem.symbol.sdk.api.AggregateTransactionService) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class HashLockTransactionIntegrationTest method standaloneLockFundsTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void standaloneLockFundsTransaction(RepositoryType type) {
    BigInteger duration = BigInteger.valueOf(10000);
    TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneLockFundsTransaction"));
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(factory.build().toAggregate(account.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedTransaction = this.account.sign(aggregateTransaction, getGenerationHash());
    HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), duration, signedTransaction).maxFee(maxFee).build();
    announceAndValidate(type, this.account, hashLockTransaction);
    announceAndValidate(type, this.account, aggregateTransaction);
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class HashLockTransactionIntegrationTest method aggregateLockFundsTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void aggregateLockFundsTransaction(RepositoryType type) {
    BigInteger duration = BigInteger.valueOf(1000);
    TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), this.account.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneLockFundsTransaction"));
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(factory.build().toAggregate(account.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedTransaction = this.account.sign(aggregateTransaction, getGenerationHash());
    HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), duration, signedTransaction).maxFee(maxFee).build();
    announceAggregateAndValidate(type, hashLockTransaction, this.account);
    announceAndValidate(type, this.account, aggregateTransaction);
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)63 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)45 Test (org.junit.jupiter.api.Test)45 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)31 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)30 Address (io.nem.symbol.sdk.model.account.Address)26 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)23 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)23 BigInteger (java.math.BigInteger)20 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)17 Account (io.nem.symbol.sdk.model.account.Account)14 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 ArrayList (java.util.ArrayList)7 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)6 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)6 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)6 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)6 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)5