use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method searchOrderByHeightDesc.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchOrderByHeightDesc(RepositoryType type) {
BlockSearchCriteria criteria = new BlockSearchCriteria();
criteria.setOrderBy(BlockOrderBy.HEIGHT);
criteria.setOrder(OrderBy.DESC);
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).reversed()).collect(Collectors.toList());
Assertions.assertEquals(blocks, sorted);
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method searchUsingOffset.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUsingOffset(RepositoryType type) {
BlockRepository blockRepository = getBlockRepository(type);
BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
BlockSearchCriteria criteria = new BlockSearchCriteria();
criteria.setPageSize(10);
criteria.setOrderBy(BlockOrderBy.HEIGHT);
int offsetIndex = 2;
List<BlockInfo> blocksWithoutOffset = get(streamer.search(criteria).toList().toObservable());
String offset = blocksWithoutOffset.get(offsetIndex).getHeight().toString();
criteria.setOffset(offset);
List<BlockInfo> blockFromOffsets = get(streamer.search(criteria).toList().toObservable());
List<BlockInfo> expectedList = blocksWithoutOffset.stream().skip(offsetIndex + 1).collect(Collectors.toList());
// If the block grows when running the last search
PaginationTester.sameEntities(expectedList, blockFromOffsets.subList(0, expectedList.size()));
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method getBlockByHeight.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getBlockByHeight(RepositoryType type) {
BlockInfo blockInfo = get(getBlockRepository(type).getBlockByHeight(BigInteger.valueOf(1)));
assertEquals(1, blockInfo.getHeight().intValue());
assertEquals(0, blockInfo.getTimestamp().intValue());
assertNotEquals(getGenerationHash(), blockInfo.getGenerationHash());
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryVertxImplTest method shouldGetBlockByHeight.
@Test
public void shouldGetBlockByHeight() throws Exception {
Address address = Address.generateRandom(this.networkType);
BlockInfoDTO dto = new BlockInfoDTO();
BlockMetaDTO metaDTO = new BlockMetaDTO();
metaDTO.setHash("someHash");
metaDTO.setTransactionsCount(10);
metaDTO.setTotalTransactionsCount(5);
metaDTO.setTransactionsCount(15);
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.setSize(10L);
blockDto.setNetwork(NetworkTypeEnum.NUMBER_144);
blockDto.setSignerPublicKey("B630EFDDFADCC4A2077AB8F1EC846B08FEE2D2972EACF95BBAC6BFAC3D31834C");
blockDto.setBeneficiaryAddress(address.encoded());
blockDto.setHeight(BigInteger.valueOf(9));
dto.setBlock(blockDto);
mockRemoteCall(dto);
BigInteger height = BigInteger.valueOf(10L);
BlockInfo info = repository.getBlockByHeight(height).toFuture().get();
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(10, info.getSize());
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.getTotalTransactionsCount(), info.getTotalTransactionsCount());
Assertions.assertEquals(metaDTO.getTransactionsCount(), info.getTransactionsCount());
Assertions.assertEquals(metaDTO.getTotalTransactionsCount(), info.getTotalTransactionsCount());
Assertions.assertEquals(metaDTO.getStatementsCount(), info.getStatementsCount());
Assertions.assertEquals(metaDTO.getGenerationHash(), info.getGenerationHash());
Assertions.assertEquals(metaDTO.getStateHashSubCacheMerkleRoots(), info.getSubCacheMerkleRoots());
Assertions.assertEquals(metaDTO.getTotalFee(), info.getTotalFee());
Assertions.assertEquals(blockDto.getHeight(), info.getHeight());
Assertions.assertEquals(address, info.getBeneficiaryAddress());
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryVertxImplTest method shouldGetBlocksByHeightWithLimit.
@Test
public void shouldGetBlocksByHeightWithLimit() throws Exception {
Address address = Address.generateRandom(this.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.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());
}
Aggregations