Search in sources :

Example 1 with BlockSearchCriteria

use of io.nem.symbol.sdk.api.BlockSearchCriteria in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method searchOrderByHeightAsc.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchOrderByHeightAsc(RepositoryType type) {
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    criteria.setOrderBy(BlockOrderBy.HEIGHT);
    criteria.setOrder(OrderBy.ASC);
    BlockPaginationStreamer streamer = new BlockPaginationStreamer(getBlockRepository(type));
    List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
    List<BlockInfo> sorted = blocks.stream().sorted(Comparator.comparing(BlockInfo::getHeight)).collect(Collectors.toList());
    Assertions.assertEquals(blocks, sorted);
}
Also used : BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with BlockSearchCriteria

use of io.nem.symbol.sdk.api.BlockSearchCriteria in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method searchByBeneficiaryAddressWhenInvalid.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByBeneficiaryAddressWhenInvalid(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    Address expectedBeneficiaryAddress = Account.generateNewAccount(getNetworkType()).getAddress();
    criteria.setBeneficiaryAddress(expectedBeneficiaryAddress);
    BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
    List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
    Assertions.assertTrue(blocks.isEmpty());
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with BlockSearchCriteria

use of io.nem.symbol.sdk.api.BlockSearchCriteria in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method searchBySignerPublicKeyWhenInvalid.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchBySignerPublicKeyWhenInvalid(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    PublicKey expectedSignerPublicKey = PublicKey.generateRandom();
    criteria.setSignerPublicKey(expectedSignerPublicKey);
    BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
    List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
    Assertions.assertTrue(blocks.isEmpty());
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) PublicKey(io.nem.symbol.core.crypto.PublicKey) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BlockSearchCriteria

use of io.nem.symbol.sdk.api.BlockSearchCriteria in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method searchByBeneficiaryAddress.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByBeneficiaryAddress(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    BlockInfo block1 = get(blockRepository.getBlockByHeight(BigInteger.ONE));
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    Address expectedBeneficiaryAddress = block1.getBeneficiaryAddress();
    criteria.setBeneficiaryAddress(expectedBeneficiaryAddress);
    BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
    List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
    blocks.forEach(b -> Assertions.assertEquals(expectedBeneficiaryAddress, b.getBeneficiaryAddress()));
    Assertions.assertFalse(blocks.isEmpty());
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with BlockSearchCriteria

use of io.nem.symbol.sdk.api.BlockSearchCriteria in project nem2-sdk-java by nemtech.

the class BlockRepositoryOkHttpImplTest method shouldGetBlocksByHeightWithLimit.

@Test
public void shouldGetBlocksByHeightWithLimit() throws Exception {
    Address address = Address.generateRandom(networkType);
    BlockInfoDTO dto = new BlockInfoDTO();
    BlockMetaDTO metaDTO = new BlockMetaDTO();
    metaDTO.setHash("someHash");
    metaDTO.setTransactionsCount(10);
    metaDTO.setGenerationHash("generationHash");
    metaDTO.setStatementsCount(20);
    metaDTO.setStateHashSubCacheMerkleRoots(Arrays.asList("string1", "string2"));
    metaDTO.setTotalFee(BigInteger.valueOf(8));
    dto.setMeta(metaDTO);
    BlockDTO blockDto = new BlockDTO();
    blockDto.setType(BlockType.NORMAL_BLOCK.getValue());
    blockDto.setVersion(3);
    blockDto.setSignerPublicKey("B630EFDDFADCC4A2077AB8F1EC846B08FEE2D2972EACF95BBAC6BFAC3D31834C");
    blockDto.setBeneficiaryAddress(address.encoded());
    blockDto.setHeight(BigInteger.valueOf(9L));
    blockDto.setNetwork(NetworkTypeEnum.NUMBER_144);
    blockDto.setProofGamma("proofGamma");
    blockDto.setProofScalar("proofScalar");
    blockDto.setProofVerificationHash("proofVerificationHash");
    dto.setBlock(blockDto);
    mockRemoteCall(Collections.singletonList(dto));
    mockRemoteCall(toPage(dto));
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    criteria.offset("abc");
    List<BlockInfo> resolvedList = repository.search(criteria).toFuture().get().getData();
    BlockInfo info = resolvedList.get(0);
    Assertions.assertNotNull(info);
    Assertions.assertEquals(blockDto.getBeneficiaryAddress(), info.getBeneficiaryAddress().encoded());
    Assertions.assertEquals(blockDto.getSignerPublicKey(), info.getSignerPublicAccount().getPublicKey().toHex());
    Assertions.assertEquals(BlockType.NORMAL_BLOCK, info.getType());
    Assertions.assertEquals(3, info.getVersion().intValue());
    Assertions.assertEquals(NetworkType.MIJIN_TEST, info.getNetworkType());
    Assertions.assertEquals(BigInteger.valueOf(9L), info.getHeight());
    Assertions.assertEquals(metaDTO.getHash(), info.getHash());
    Assertions.assertEquals(metaDTO.getTransactionsCount(), info.getTransactionsCount());
    Assertions.assertEquals(metaDTO.getGenerationHash(), info.getGenerationHash());
    Assertions.assertEquals(metaDTO.getTransactionsCount(), info.getTransactionsCount());
    Assertions.assertEquals(metaDTO.getStateHashSubCacheMerkleRoots(), info.getSubCacheMerkleRoots());
    Assertions.assertEquals(metaDTO.getTotalFee(), info.getTotalFee());
    Assertions.assertEquals(blockDto.getHeight(), info.getHeight());
    Assertions.assertEquals(blockDto.getProofGamma(), info.getProofGamma());
    Assertions.assertEquals(blockDto.getProofScalar(), info.getProofScalar());
    Assertions.assertEquals(blockDto.getProofVerificationHash(), info.getProofVerificationHash());
    Assertions.assertEquals(address, info.getBeneficiaryAddress());
}
Also used : BlockMetaDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockMetaDTO) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) BlockInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockInfoDTO) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) ImportanceBlockInfo(io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo) BlockDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockDTO) ImportanceBlockDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.ImportanceBlockDTO) Test(org.junit.jupiter.api.Test)

Aggregations

BlockSearchCriteria (io.nem.symbol.sdk.api.BlockSearchCriteria)9 BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)9 BlockPaginationStreamer (io.nem.symbol.sdk.api.BlockPaginationStreamer)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 BlockRepository (io.nem.symbol.sdk.api.BlockRepository)5 Address (io.nem.symbol.sdk.model.account.Address)4 PublicKey (io.nem.symbol.core.crypto.PublicKey)2 ImportanceBlockInfo (io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo)2 Test (org.junit.jupiter.api.Test)2 BlockDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockDTO)1 BlockInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockInfoDTO)1 BlockMetaDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockMetaDTO)1 ImportanceBlockDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.ImportanceBlockDTO)1 BlockDTO (io.nem.symbol.sdk.openapi.vertx.model.BlockDTO)1 BlockInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.BlockInfoDTO)1 BlockMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.BlockMetaDTO)1 ImportanceBlockDTO (io.nem.symbol.sdk.openapi.vertx.model.ImportanceBlockDTO)1