Search in sources :

Example 11 with BlockInfo

use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.

the class BlockServiceTest method isValidStatementInBlockMultipleNotEquals.

@Test
void isValidStatementInBlockMultipleNotEquals() throws ExecutionException, InterruptedException {
    BigInteger height = BigInteger.ONE;
    String leaf = "1234";
    String root = "00000";
    BlockInfo blockInfo = Mockito.mock(BlockInfo.class);
    Mockito.when(blockInfo.getBlockTransactionsHash()).thenReturn(root);
    Mockito.when(blockRepositoryMock.getBlockByHeight(height)).thenReturn(Observable.just(blockInfo));
    List<MerklePathItem> merklePath = new ArrayList<>();
    merklePath.add(new MerklePathItem(Position.LEFT, "11"));
    merklePath.add(new MerklePathItem(Position.RIGHT, "22"));
    merklePath.add(new MerklePathItem(Position.LEFT, "33"));
    merklePath.add(new MerklePathItem(Position.RIGHT, "44"));
    MerkleProofInfo merkleProofInfo = new MerkleProofInfo(merklePath);
    Mockito.when(blockRepositoryMock.getMerkleReceipts(height, leaf)).thenReturn(Observable.just(merkleProofInfo));
    Assertions.assertFalse(service.isValidStatementInBlock(height, leaf).toFuture().get());
}
Also used : BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) MerklePathItem(io.nem.symbol.sdk.model.blockchain.MerklePathItem) MerkleProofInfo(io.nem.symbol.sdk.model.blockchain.MerkleProofInfo) Test(org.junit.jupiter.api.Test)

Example 12 with BlockInfo

use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.

the class BlockServiceTest method isValidStatementInBlockOnError.

@Test
void isValidStatementInBlockOnError() throws ExecutionException, InterruptedException {
    BigInteger height = BigInteger.ONE;
    String hash = "1234";
    String root = "d7de53a6ec87b3cb8e0fb4d6d9aa40b96a17a54b7206702229a6517e91d88dcb";
    BlockInfo blockInfo = Mockito.mock(BlockInfo.class);
    Mockito.when(blockInfo.getBlockReceiptsHash()).thenReturn(root);
    Mockito.when(blockRepositoryMock.getBlockByHeight(height)).thenReturn(Observable.just(blockInfo));
    Mockito.when(blockRepositoryMock.getMerkleReceipts(height, hash)).thenReturn(Observable.error(new RuntimeException("Some Error When getMerkleReceipts")));
    Assertions.assertFalse(service.isValidStatementInBlock(height, hash).toFuture().get());
}
Also used : BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 13 with BlockInfo

use of io.nem.symbol.sdk.model.blockchain.BlockInfo 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)

Example 14 with BlockInfo

use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.

the class BlockRepositoryOkHttpImplTest method shouldGetBlockByHeight.

@Test
public void shouldGetBlockByHeight() 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(8L));
    dto.setMeta(metaDTO);
    BlockDTO blockDto = new BlockDTO();
    blockDto.setType(BlockType.NORMAL_BLOCK.getValue());
    blockDto.setSize(10L);
    blockDto.setVersion(3);
    blockDto.setSignerPublicKey("B630EFDDFADCC4A2077AB8F1EC846B08FEE2D2972EACF95BBAC6BFAC3D31834C");
    blockDto.setBeneficiaryAddress(address.encoded());
    blockDto.setHeight(BigInteger.valueOf(9L));
    blockDto.setNetwork(NetworkTypeEnum.NUMBER_144);
    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.getTransactionsCount(), info.getTransactionsCount());
    Assertions.assertEquals(metaDTO.getGenerationHash(), info.getGenerationHash());
    Assertions.assertEquals(metaDTO.getStatementsCount(), info.getStatementsCount());
    Assertions.assertEquals(metaDTO.getStateHashSubCacheMerkleRoots(), info.getSubCacheMerkleRoots());
    Assertions.assertEquals(metaDTO.getTotalFee(), info.getTotalFee());
    Assertions.assertEquals(blockDto.getHeight(), info.getHeight());
    Assertions.assertEquals(address, info.getBeneficiaryAddress());
    Assertions.assertEquals(10L, info.getSize());
}
Also used : BlockMetaDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockMetaDTO) 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) BigInteger(java.math.BigInteger) 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)

Example 15 with BlockInfo

use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method searchBySignerPublicKey.

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

Aggregations

BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)24 Test (org.junit.jupiter.api.Test)13 BigInteger (java.math.BigInteger)11 BlockSearchCriteria (io.nem.symbol.sdk.api.BlockSearchCriteria)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EnumSource (org.junit.jupiter.params.provider.EnumSource)9 MerklePathItem (io.nem.symbol.sdk.model.blockchain.MerklePathItem)8 MerkleProofInfo (io.nem.symbol.sdk.model.blockchain.MerkleProofInfo)8 ArrayList (java.util.ArrayList)8 BlockPaginationStreamer (io.nem.symbol.sdk.api.BlockPaginationStreamer)7 Address (io.nem.symbol.sdk.model.account.Address)6 ImportanceBlockInfo (io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo)6 BlockRepository (io.nem.symbol.sdk.api.BlockRepository)5 ImportanceBlockDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.ImportanceBlockDTO)3 ImportanceBlockDTO (io.nem.symbol.sdk.openapi.vertx.model.ImportanceBlockDTO)3 PublicKey (io.nem.symbol.core.crypto.PublicKey)2 BlockType (io.nem.symbol.sdk.model.blockchain.BlockType)2 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)2 BlockDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockDTO)2 BlockInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockInfoDTO)2