Search in sources :

Example 1 with HashLockTransaction

use of io.nem.symbol.sdk.model.transaction.HashLockTransaction in project nem2-sdk-java by nemtech.

the class TransactionServiceTest method hashLockTransactionResolveAlias.

@Test
void hashLockTransactionResolveAlias() throws ExecutionException, InterruptedException {
    Mosaic unresolvedMosaicId = new Mosaic(mosaicNamespace2, BigInteger.valueOf(2));
    String transactionHash = "aaaa";
    TransactionFactory<HashLockTransaction> factory = HashLockTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), unresolvedMosaicId, BigInteger.TEN, "SomeHash").transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    simulateStatement(height, 1, 0);
    HashLockTransaction transaction = factory.build();
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    HashLockTransaction resolvedTransaction = (HashLockTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaic().getId());
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 2 with HashLockTransaction

use of io.nem.symbol.sdk.model.transaction.HashLockTransaction in project nem2-sdk-java by nemtech.

the class TransactionMapperVertxTest method validateStandaloneTransaction.

void validateStandaloneTransaction(Transaction transaction, TransactionInfoDTO transactionDTO, TransactionInfoDTO parentTransaction) {
    TransactionMetaDTO meta = jsonHelper.convert(transactionDTO.getMeta(), TransactionMetaDTO.class);
    if (transaction.getTransactionInfo().isPresent()) {
        TransactionInfo transactionInfo = transaction.getTransactionInfo().get();
        assertEquals(meta.getHeight(), transactionInfo.getHeight());
        if (transactionInfo.getHash().isPresent()) {
            assertEquals(meta.getHash(), transactionInfo.getHash().get());
        }
        if (transactionInfo.getMerkleComponentHash().isPresent()) {
            assertEquals(meta.getMerkleComponentHash(), transactionInfo.getMerkleComponentHash().get());
        }
        if (transactionInfo.getIndex().isPresent()) {
            assertEquals(transactionInfo.getIndex().get(), meta.getIndex());
        }
    }
    // if (transaction.getTransactionInfo().get().getId().isPresent()) {
    // assertEquals(
    // transactionDTO.getMeta().getId(),
    // transaction.getTransactionInfo().get().getId().get());
    // }
    // if (transaction.getTransactionInfo().get().getAggregateHash().isPresent()) {
    // assertEquals(
    // transactionDTO.getMeta().getAggregateHash(),
    // transaction.getTransactionInfo().get().getAggregateHash().get());
    // }
    // if (transaction.getTransactionInfo().get().getAggregateId().isPresent()) {
    // assertEquals(
    // transactionDTO.getMeta().getAggregateId(),
    // transaction.getTransactionInfo().get().getAggregateId().get());
    // }
    assertEquals(jsonHelper.getString(parentTransaction.getTransaction(), "signature"), transaction.getSignature().get());
    assertEquals(jsonHelper.getString(transactionDTO.getTransaction(), "signerPublicKey"), transaction.getSigner().get().getPublicKey().toHex());
    assertEquals(transaction.getType().getValue(), (int) jsonHelper.getInteger(transactionDTO.getTransaction(), "type"));
    int version = jsonHelper.getInteger(transactionDTO.getTransaction(), "version");
    assertEquals((int) transaction.getVersion(), version);
    int networkType = jsonHelper.getInteger(transactionDTO.getTransaction(), "network");
    assertEquals(transaction.getNetworkType().getValue(), networkType);
    assertEquals(jsonHelper.getBigInteger(parentTransaction.getTransaction(), "maxFee"), transaction.getMaxFee());
    assertNotNull(transaction.getDeadline());
    if (transaction.getType() == TransactionType.TRANSFER) {
        validateTransferTx((TransferTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.NAMESPACE_REGISTRATION) {
        validateNamespaceCreationTx((NamespaceRegistrationTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.MOSAIC_DEFINITION) {
        validateMosaicCreationTx((MosaicDefinitionTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.MOSAIC_SUPPLY_CHANGE) {
        validateMosaicSupplyChangeTx((MosaicSupplyChangeTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.MULTISIG_ACCOUNT_MODIFICATION) {
        validateMultisigModificationTx((MultisigAccountModificationTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.HASH_LOCK) {
        validateLockFundsTx((HashLockTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.SECRET_LOCK) {
        validateSecretLockTx((SecretLockTransaction) transaction, transactionDTO);
    } else if (transaction.getType() == TransactionType.SECRET_PROOF) {
        validateSecretProofTx((SecretProofTransaction) transaction, transactionDTO);
    }
}
Also used : MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) TransactionInfo(io.nem.symbol.sdk.model.transaction.TransactionInfo) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)

Example 3 with HashLockTransaction

use of io.nem.symbol.sdk.model.transaction.HashLockTransaction in project nem2-sdk-java by nemtech.

the class MultisignIntegrationTest method createHashLockTransactionAndAnnounce.

private Observable<Transaction> createHashLockTransactionAndAnnounce(RepositoryType type, SignedTransaction signedAggregatedTransaction, Account signer) {
    HashLockTransaction hasLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(10000), signedAggregatedTransaction).maxFee(maxFee).build();
    SignedTransaction signedLockFundsTransaction = signer.sign(hasLockTransaction, getGenerationHash());
    TransactionServiceImpl transactionService = new TransactionServiceImpl(getRepositoryFactory(type));
    return transactionService.announce(getListener(type), signedLockFundsTransaction);
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

Example 4 with HashLockTransaction

use of io.nem.symbol.sdk.model.transaction.HashLockTransaction in project nem2-sdk-java by nemtech.

the class ListenerIntegrationTest method createAggregateBondedTransaction.

private Pair<SignedTransaction, SignedTransaction> createAggregateBondedTransaction(RepositoryType type) {
    helper().sendMosaicFromNemesis(type, this.cosignatoryAccount.getAddress(), false);
    helper().sendMosaicFromNemesis(type, this.cosignatoryAccount2.getAddress(), false);
    helper().sendMosaicFromNemesis(type, this.multisigAccount.getAddress(), false);
    helper().createMultisigAccountBonded(type, this.multisigAccount, this.cosignatoryAccount, this.cosignatoryAccount2);
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), Account.generateNewAccount(getNetworkType()).getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(transferTransaction.toAggregate(this.multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction aggregateSignedTransaction = this.cosignatoryAccount.sign(aggregateTransaction, getGenerationHash());
    HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), aggregateSignedTransaction).maxFee(maxFee).build();
    SignedTransaction signedHashLockTransaction = hashLockTransaction.signWith(this.cosignatoryAccount, getGenerationHash());
    return Pair.of(aggregateSignedTransaction, signedHashLockTransaction);
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

Example 5 with HashLockTransaction

use of io.nem.symbol.sdk.model.transaction.HashLockTransaction 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)

Aggregations

HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)11 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)7 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)6 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)5 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)4 BigInteger (java.math.BigInteger)4 Account (io.nem.symbol.sdk.model.account.Account)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)3 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)3 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)3 Test (org.junit.jupiter.api.Test)3 TransactionService (io.nem.symbol.sdk.api.TransactionService)2 Address (io.nem.symbol.sdk.model.account.Address)2 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)2 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)2 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2