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());
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations