use of io.nem.symbol.sdk.model.blockchain.MerkleProofInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryVertxImplTest method getMerkleTransaction.
@Test
public void getMerkleTransaction() throws Exception {
MerkleProofInfoDTO merkleProofInfoDTO = new MerkleProofInfoDTO();
MerklePathItemDTO item = new MerklePathItemDTO().hash("someHash").position(PositionEnum.LEFT);
mockRemoteCall(merkleProofInfoDTO.addMerklePathItem(item));
MerkleProofInfo merkleProofInfo = repository.getMerkleTransaction(BigInteger.ONE, "HASH!").toFuture().get();
Assertions.assertEquals(1, merkleProofInfo.getMerklePath().size());
Assertions.assertEquals("someHash", merkleProofInfo.getMerklePath().get(0).getHash());
Assertions.assertEquals(Position.LEFT, merkleProofInfo.getMerklePath().get(0).getPosition());
}
use of io.nem.symbol.sdk.model.blockchain.MerkleProofInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryVertxImplTest method shouldGetMerkleReceipts.
@Test
public void shouldGetMerkleReceipts() throws Exception {
MerkleProofInfoDTO merkleProofInfoDTO = new MerkleProofInfoDTO();
MerklePathItemDTO marklePathItem = new MerklePathItemDTO();
marklePathItem.setHash("SomeHash");
marklePathItem.setPosition(PositionEnum.LEFT);
merkleProofInfoDTO.setMerklePath(Collections.singletonList(marklePathItem));
mockRemoteCall(merkleProofInfoDTO);
BigInteger height = BigInteger.valueOf(10L);
MerkleProofInfo info = repository.getMerkleReceipts(height, "AnotherHash").toFuture().get();
Assertions.assertNotNull(info);
Assertions.assertEquals(1, info.getMerklePath().size());
Assertions.assertEquals(marklePathItem.getHash(), info.getMerklePath().get(0).getHash());
Assertions.assertEquals(Position.LEFT, info.getMerklePath().get(0).getPosition());
}
use of io.nem.symbol.sdk.model.blockchain.MerkleProofInfo in project nem2-sdk-java by nemtech.
the class BlockServiceTest method isValidStatementInBlockEmpty.
@Test
void isValidStatementInBlockEmpty() throws ExecutionException, InterruptedException {
BigInteger height = BigInteger.ONE;
String leaf = "ABCD";
String root = "ABCD";
BlockInfo blockInfo = Mockito.mock(BlockInfo.class);
Mockito.when(blockInfo.getBlockReceiptsHash()).thenReturn(root);
Mockito.when(blockRepositoryMock.getBlockByHeight(height)).thenReturn(Observable.just(blockInfo));
List<MerklePathItem> merklePath = new ArrayList<>();
MerkleProofInfo merkleProofInfo = new MerkleProofInfo(merklePath);
Mockito.when(blockRepositoryMock.getMerkleReceipts(height, leaf)).thenReturn(Observable.just(merkleProofInfo));
Assertions.assertTrue(service.isValidStatementInBlock(height, leaf).toFuture().get());
}
use of io.nem.symbol.sdk.model.blockchain.MerkleProofInfo in project nem2-sdk-java by nemtech.
the class BlockServiceTest method isValidTransactionInBlockOnError.
@Test
void isValidTransactionInBlockOnError() throws ExecutionException, InterruptedException {
BigInteger height = BigInteger.ONE;
String hash = "1234";
Mockito.when(blockRepositoryMock.getBlockByHeight(height)).thenReturn(Observable.error(new RuntimeException("Some Error When getting Block")));
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.getMerkleTransaction(height, hash)).thenReturn(Observable.just(merkleProofInfo));
Assertions.assertFalse(service.isValidTransactionInBlock(height, hash).toFuture().get());
}
use of io.nem.symbol.sdk.model.blockchain.MerkleProofInfo in project nem2-sdk-java by nemtech.
the class BlockServiceTest method isValidTransactionInBlockEmtpyNotEquals.
@Test
void isValidTransactionInBlockEmtpyNotEquals() throws ExecutionException, InterruptedException {
BigInteger height = BigInteger.ONE;
String leaf = "ABCD";
String root = "1234";
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<>();
MerkleProofInfo merkleProofInfo = new MerkleProofInfo(merklePath);
Mockito.when(blockRepositoryMock.getMerkleTransaction(height, leaf)).thenReturn(Observable.just(merkleProofInfo));
Assertions.assertFalse(service.isValidTransactionInBlock(height, leaf).toFuture().get());
}
Aggregations