Search in sources :

Example 1 with SecretLockInfo

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

the class StateProofServiceTest method secretLock.

@Test
void secretLock() throws Exception {
    SecretLockRepository repository = mock(SecretLockRepository.class);
    when(factory.createSecretLockRepository()).thenReturn(repository);
    String id = "secret";
    SecretLockInfo state = Mockito.mock(SecretLockInfo.class);
    when(state.getCompositeHash()).thenReturn(id);
    when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
    when(repository.getSecretLock(eq(id))).thenReturn(Observable.just(state));
    when(repository.getSecretLockMerkle(eq(id))).thenReturn(Observable.just(tree));
    StateMerkleProof<SecretLockInfo> proof = service.secretLock(id).toFuture().get();
    Assertions.assertTrue(proof.isValid());
    Assertions.assertEquals(state, proof.getState());
}
Also used : SecretLockRepository(io.nem.symbol.sdk.api.SecretLockRepository) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) Test(org.junit.jupiter.api.Test)

Example 2 with SecretLockInfo

use of io.nem.symbol.sdk.model.transaction.SecretLockInfo 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());
}
Also used : SecretLockSearchCriteria(io.nem.symbol.sdk.api.SecretLockSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) SecretLockInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.SecretLockInfoDTO) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) SecretLockEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.SecretLockEntryDTO) Test(org.junit.jupiter.api.Test)

Example 3 with SecretLockInfo

use of io.nem.symbol.sdk.model.transaction.SecretLockInfo 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);
}
Also used : Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MapperUtils(io.nem.symbol.core.utils.MapperUtils) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) LockHashAlgorithm(io.nem.symbol.sdk.model.transaction.LockHashAlgorithm) LockStatus(io.nem.symbol.sdk.model.transaction.LockStatus) SecretLockEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.SecretLockEntryDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Collectors(java.util.stream.Collectors) SecretLockRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.SecretLockRoutesApiImpl) Consumer(java.util.function.Consumer) SecretLockSearchCriteria(io.nem.symbol.sdk.api.SecretLockSearchCriteria) SecretLockInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.SecretLockInfoDTO) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) SecretLockPage(io.nem.symbol.sdk.openapi.vertx.model.SecretLockPage) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) SecretLockRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.SecretLockRoutesApi) Observable(io.reactivex.Observable) SecretLockRepository(io.nem.symbol.sdk.api.SecretLockRepository) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) Handler(io.vertx.core.Handler) SecretLockPage(io.nem.symbol.sdk.openapi.vertx.model.SecretLockPage)

Example 4 with SecretLockInfo

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

the class SecretLockRepositoryVertxImpl method toSecretLockInfo.

private SecretLockInfo toSecretLockInfo(SecretLockInfoDTO dto) {
    SecretLockEntryDTO lock = dto.getLock();
    MosaicId mosaicId = MapperUtils.toMosaicId(lock.getMosaicId());
    return new SecretLockInfo(dto.getId(), ObjectUtils.defaultIfNull(lock.getVersion(), 1), MapperUtils.toAddress(lock.getOwnerAddress()), mosaicId, lock.getAmount(), lock.getEndHeight(), LockStatus.rawValueOf(lock.getStatus().getValue().byteValue()), LockHashAlgorithm.rawValueOf(lock.getHashAlgorithm().getValue()), lock.getSecret(), MapperUtils.toAddress(lock.getRecipientAddress()), lock.getCompositeHash());
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) SecretLockEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.SecretLockEntryDTO)

Example 5 with SecretLockInfo

use of io.nem.symbol.sdk.model.transaction.SecretLockInfo 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());
}
Also used : SecretLockSearchCriteria(io.nem.symbol.sdk.api.SecretLockSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) SecretLockInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.SecretLockInfoDTO) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) SecretLockEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.SecretLockEntryDTO) Test(org.junit.jupiter.api.Test)

Aggregations

SecretLockInfo (io.nem.symbol.sdk.model.transaction.SecretLockInfo)9 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)6 SecretLockSearchCriteria (io.nem.symbol.sdk.api.SecretLockSearchCriteria)5 SecretLockRepository (io.nem.symbol.sdk.api.SecretLockRepository)4 Address (io.nem.symbol.sdk.model.account.Address)4 SecretLockEntryDTO (io.nem.symbol.sdk.openapi.vertx.model.SecretLockEntryDTO)4 Test (org.junit.jupiter.api.Test)4 SecretLockInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.SecretLockInfoDTO)3 Page (io.nem.symbol.sdk.api.Page)2 LockHashAlgorithm (io.nem.symbol.sdk.model.transaction.LockHashAlgorithm)2 LockStatus (io.nem.symbol.sdk.model.transaction.LockStatus)2 SecretLockEntryDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.SecretLockEntryDTO)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)1 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1 OrderBy (io.nem.symbol.sdk.api.OrderBy)1 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)1 Account (io.nem.symbol.sdk.model.account.Account)1 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)1 Currency (io.nem.symbol.sdk.model.mosaic.Currency)1