use of io.nem.symbol.sdk.model.transaction.SecretProofTransaction 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.SecretProofTransaction in project nem2-sdk-java by nemtech.
the class SecretLockSecretProofTransactionIntegrationTest method standaloneSecretProofTransaction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void standaloneSecretProofTransaction(RepositoryType type) {
byte[] secretBytes = RandomUtils.generateRandomBytes(20);
byte[] result = Hashes.sha3_256(secretBytes);
String secret = ConvertUtils.toHex(result);
String proof = ConvertUtils.toHex(secretBytes);
Address recipient = config().getTestAccount2().getAddress();
SecretLockTransaction secretLockTransaction = SecretLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), LockHashAlgorithm.SHA3_256, secret, recipient).maxFee(maxFee).build();
announceAndValidate(type, account, secretLockTransaction);
SecretProofTransaction secretProofTransaction = SecretProofTransactionFactory.create(getNetworkType(), getDeadline(), LockHashAlgorithm.SHA3_256, recipient, secret, proof).maxFee(maxFee).build();
announceAndValidate(type, account, secretProofTransaction);
}
use of io.nem.symbol.sdk.model.transaction.SecretProofTransaction in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method secretProofTransactionResolveAlias.
@Test
void secretProofTransactionResolveAlias() throws ExecutionException, InterruptedException {
UnresolvedAddress recipient = addressNamespace1;
String transactionHash = "aaaa";
String secret = "1118ba10229ab5778d05d9c4b7f56676a88bf9295c185acfc0f961db5408cafe";
String proof = "2228ba10229ab5778d05d9c4b7f56676a88bf9295c185acfc0f961db5408cafe";
TransactionFactory<SecretProofTransaction> factory = SecretProofTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), LockHashAlgorithm.SHA3_256, recipient, secret, proof).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
simulateStatement(height, 1, 0);
SecretProofTransaction 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)));
SecretProofTransaction resolvedTransaction = (SecretProofTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
Assertions.assertEquals(address1, resolvedTransaction.getRecipient());
}
use of io.nem.symbol.sdk.model.transaction.SecretProofTransaction in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest method shouldCreateStandaloneSecretProofTransaction.
@Test
void shouldCreateStandaloneSecretProofTransaction() {
TransactionInfoDTO secretProofTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("standaloneSecretProofTransaction.json");
Transaction secretProofTransaction = map(secretProofTransactionDTO);
validateStandaloneTransaction(secretProofTransaction, secretProofTransactionDTO);
}
use of io.nem.symbol.sdk.model.transaction.SecretProofTransaction in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest 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());
}
}
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);
}
}
Aggregations