use of io.nem.symbol.sdk.api.SecretLockSearchCriteria in project nem2-sdk-java by nemtech.
the class SecretLockRepositoryVertxImplTest method shouldSearch.
@Test
public void shouldSearch() throws Exception {
Address address = Address.generateRandom(this.networkType);
Address recipientAddress = Address.generateRandom(this.networkType);
MosaicId mosaicId = MosaicId.createFromNonce(MosaicNonce.createRandom(), address);
SecretLockEntryDTO lockHashDto = new SecretLockEntryDTO();
lockHashDto.setOwnerAddress(encodeAddress(address));
lockHashDto.setAmount(BigInteger.ONE);
lockHashDto.setEndHeight(BigInteger.TEN);
lockHashDto.setCompositeHash("ABC");
lockHashDto.setRecipientAddress(encodeAddress(recipientAddress));
lockHashDto.setMosaicId(mosaicId.getIdAsHex());
lockHashDto.setStatus(LockStatus.NUMBER_1);
lockHashDto.setSecret("someSecret");
lockHashDto.setHashAlgorithm(LockHashAlgorithmEnum.NUMBER_2);
lockHashDto.setVersion(1);
SecretLockInfoDTO hashLockInfoDTO = new SecretLockInfoDTO();
hashLockInfoDTO.setLock(lockHashDto);
hashLockInfoDTO.setId("123");
mockRemoteCall(toPage(hashLockInfoDTO));
List<SecretLockInfo> list = repository.search(new SecretLockSearchCriteria().address(address)).toFuture().get().getData();
Assertions.assertEquals(1, list.size());
SecretLockInfo resolvedSecretLockInfo = list.get(0);
Assertions.assertEquals(address, resolvedSecretLockInfo.getOwnerAddress());
Assertions.assertEquals(hashLockInfoDTO.getId(), resolvedSecretLockInfo.getRecordId().get());
Assertions.assertEquals(address, resolvedSecretLockInfo.getOwnerAddress());
Assertions.assertEquals(recipientAddress, resolvedSecretLockInfo.getRecipientAddress());
Assertions.assertEquals(LockHashAlgorithm.HASH_256, resolvedSecretLockInfo.getHashAlgorithm());
Assertions.assertEquals(lockHashDto.getCompositeHash(), resolvedSecretLockInfo.getCompositeHash());
Assertions.assertEquals(io.nem.symbol.sdk.model.transaction.LockStatus.USED, resolvedSecretLockInfo.getStatus());
Assertions.assertEquals(mosaicId, resolvedSecretLockInfo.getMosaicId());
Assertions.assertEquals(lockHashDto.getAmount(), resolvedSecretLockInfo.getAmount());
Assertions.assertEquals(lockHashDto.getEndHeight(), resolvedSecretLockInfo.getEndHeight());
}
use of io.nem.symbol.sdk.api.SecretLockSearchCriteria in project nem2-sdk-java by nemtech.
the class SecretLockRepositoryOkHttpImplTest method shouldSearch.
@Test
public void shouldSearch() throws Exception {
Address address = Address.generateRandom(this.networkType);
MosaicId mosaicId = MosaicId.createFromNonce(MosaicNonce.createRandom(), address);
Address recipientAddress = Address.generateRandom(this.networkType);
SecretLockEntryDTO lockHashDto = new SecretLockEntryDTO();
lockHashDto.setOwnerAddress(encodeAddress(address));
lockHashDto.setAmount(BigInteger.ONE);
lockHashDto.setEndHeight(BigInteger.TEN);
lockHashDto.setCompositeHash("ABC");
lockHashDto.setMosaicId(mosaicId.getIdAsHex());
lockHashDto.setRecipientAddress(encodeAddress(recipientAddress));
lockHashDto.setHashAlgorithm(LockHashAlgorithmEnum.NUMBER_2);
lockHashDto.setStatus(LockStatus.NUMBER_1);
lockHashDto.setSecret("someSecret");
lockHashDto.setVersion(1);
SecretLockInfoDTO hashLockInfoDTO = new SecretLockInfoDTO();
hashLockInfoDTO.setLock(lockHashDto);
hashLockInfoDTO.setId("123");
mockRemoteCall(toPage(hashLockInfoDTO));
List<SecretLockInfo> list = repository.search(new SecretLockSearchCriteria().address(address)).toFuture().get().getData();
Assertions.assertEquals(1, list.size());
SecretLockInfo resolvedSecretLockInfo = list.get(0);
Assertions.assertEquals(address, resolvedSecretLockInfo.getOwnerAddress());
Assertions.assertEquals(recipientAddress, resolvedSecretLockInfo.getRecipientAddress());
Assertions.assertEquals(hashLockInfoDTO.getId(), resolvedSecretLockInfo.getRecordId().get());
Assertions.assertEquals(address, resolvedSecretLockInfo.getOwnerAddress());
Assertions.assertEquals(lockHashDto.getCompositeHash(), resolvedSecretLockInfo.getCompositeHash());
Assertions.assertEquals(io.nem.symbol.sdk.model.transaction.LockStatus.USED, resolvedSecretLockInfo.getStatus());
Assertions.assertEquals(mosaicId, resolvedSecretLockInfo.getMosaicId());
Assertions.assertEquals(LockHashAlgorithm.HASH_256, resolvedSecretLockInfo.getHashAlgorithm());
Assertions.assertEquals(lockHashDto.getAmount(), resolvedSecretLockInfo.getAmount());
Assertions.assertEquals(lockHashDto.getEndHeight(), resolvedSecretLockInfo.getEndHeight());
Assertions.assertEquals(lockHashDto.getSecret(), resolvedSecretLockInfo.getSecret());
}
use of io.nem.symbol.sdk.api.SecretLockSearchCriteria in project nem2-sdk-java by nemtech.
the class SecretLockRepositoryVertxImpl method search.
@Override
public Observable<Page<SecretLockInfo>> search(SecretLockSearchCriteria criteria) {
String address = toDto(criteria.getAddress());
Integer pageSize = criteria.getPageSize();
Integer pageNumber = criteria.getPageNumber();
String offset = criteria.getOffset();
String secret = criteria.getSecret();
Order order = toDto(criteria.getOrder());
Consumer<Handler<AsyncResult<SecretLockPage>>> handlerConsumer = (h) -> getClient().searchSecretLock(address, secret, pageSize, pageNumber, offset, order, h);
return this.call(handlerConsumer, this::toPage);
}
use of io.nem.symbol.sdk.api.SecretLockSearchCriteria in project nem2-sdk-java by nemtech.
the class MerkleLoaderIntegrationTest method secretLocks.
public List<Arguments> secretLocks() {
RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
SecretLockRepository repository = repositoryFactory.createSecretLockRepository();
return getArguments(repository, new SecretLockSearchCriteria().order(ORDER_BY));
}
use of io.nem.symbol.sdk.api.SecretLockSearchCriteria in project nem2-sdk-java by nemtech.
the class SecretLockIntegrationTest method secretLockAndProofTransaction.
@ParameterizedTest
@MethodSource("provider")
void secretLockAndProofTransaction(RepositoryType type, LockHashAlgorithm lockHashAlgorithm) {
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
byte[] secretSeed = RandomUtils.generateRandomBytes(20);
String secret = ConvertUtils.toHex(lockHashAlgorithm.hash(secretSeed));
String storedSecret = ConvertUtils.padHex(secret, LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE);
if (lockHashAlgorithm == LockHashAlgorithm.HASH_160) {
Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, storedSecret.length());
Assertions.assertEquals(40, secret.length());
} else {
Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, storedSecret.length());
Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, secret.length());
}
String proof = ConvertUtils.toHex(secretSeed);
Account account = config().getNemesisAccount1();
Account account2 = config().getNemesisAccount2();
Currency currency = get(repositoryFactory.getNetworkCurrency());
Mosaic mosaic = currency.createAbsolute(BigInteger.valueOf(1));
BigInteger amount = mosaic.getAmount();
BigInteger duration = BigInteger.valueOf(10000);
SecretLockTransaction secretLockTransaction = SecretLockTransactionFactory.create(getNetworkType(), getDeadline(), mosaic, duration, lockHashAlgorithm, secret, account2.getAddress()).maxFee(maxFee).build();
announceAndValidate(type, account, secretLockTransaction);
SecretProofTransaction secretProofTransaction = SecretProofTransactionFactory.create(getNetworkType(), getDeadline(), lockHashAlgorithm, account2.getAddress(), secret, proof).maxFee(maxFee).build();
SecretProofTransaction secretProofTransactionAnnounced = announceAndValidate(type, account, secretProofTransaction);
sleep(500);
Assertions.assertEquals(lockHashAlgorithm, secretProofTransactionAnnounced.getHashType());
Assertions.assertEquals(account2.getAddress(), secretProofTransactionAnnounced.getRecipient());
Assertions.assertEquals(storedSecret, secretProofTransactionAnnounced.getSecret());
Assertions.assertEquals(proof, secretProofTransactionAnnounced.getProof());
SecretLockRepository hashLockRepository = getRepositoryFactory(type).createSecretLockRepository();
SecretLockInfo info = get(hashLockRepository.search(new SecretLockSearchCriteria().address(account.getAddress()).secret(storedSecret))).getData().get(0);
Assertions.assertNotNull(info);
Assertions.assertEquals(account.getAddress(), info.getOwnerAddress());
Assertions.assertEquals(account2.getAddress(), info.getRecipientAddress());
Assertions.assertEquals(amount, info.getAmount());
Assertions.assertEquals(storedSecret, info.getSecret());
Assertions.assertEquals(lockHashAlgorithm, info.getHashAlgorithm());
Assertions.assertEquals(LockStatus.USED, info.getStatus());
Page<SecretLockInfo> page = get(hashLockRepository.search(new SecretLockSearchCriteria().address(account.getAddress()).order(OrderBy.DESC)));
Assertions.assertTrue(page.getData().stream().anyMatch(m -> m.getSecret().equals(storedSecret)));
Assertions.assertEquals(20, page.getPageSize());
SecretLockInfo infoSearch = page.getData().stream().filter(m -> m.getSecret().equals(storedSecret)).findFirst().get();
Assertions.assertNotNull(infoSearch);
Assertions.assertEquals(account.getAddress(), infoSearch.getOwnerAddress());
Assertions.assertEquals(account2.getAddress(), infoSearch.getRecipientAddress());
Assertions.assertEquals(amount, infoSearch.getAmount());
Assertions.assertEquals(lockHashAlgorithm, infoSearch.getHashAlgorithm());
Assertions.assertEquals(LockStatus.USED, infoSearch.getStatus());
Assertions.assertEquals(storedSecret, infoSearch.getSecret());
}
Aggregations