Search in sources :

Example 1 with MerklePathItem

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

the class BlockServiceTest method isValidTransactionInBlockMultipleEquals.

@Test
void isValidTransactionInBlockMultipleEquals() throws ExecutionException, InterruptedException {
    BigInteger height = BigInteger.ONE;
    String hash = "1234";
    String root = "d7de53a6ec87b3cb8e0fb4d6d9aa40b96a17a54b7206702229a6517e91d88dcb";
    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.getMerkleTransaction(height, hash)).thenReturn(Observable.just(merkleProofInfo));
    Assertions.assertTrue(service.isValidTransactionInBlock(height, hash).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 2 with MerklePathItem

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

the class BlockServiceTest method isValidStatementInBlockEmtpyNotEquals.

@Test
void isValidStatementInBlockEmtpyNotEquals() 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.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 3 with MerklePathItem

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

the class BlockServiceTest method isValidStatementInBlockMultipleEquals.

@Test
void isValidStatementInBlockMultipleEquals() 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));
    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, hash)).thenReturn(Observable.just(merkleProofInfo));
    Assertions.assertTrue(service.isValidStatementInBlock(height, hash).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 4 with MerklePathItem

use of io.nem.symbol.sdk.model.blockchain.MerklePathItem 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 5 with MerklePathItem

use of io.nem.symbol.sdk.model.blockchain.MerklePathItem 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());
}
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)

Aggregations

MerklePathItem (io.nem.symbol.sdk.model.blockchain.MerklePathItem)9 MerkleProofInfo (io.nem.symbol.sdk.model.blockchain.MerkleProofInfo)9 BigInteger (java.math.BigInteger)9 ArrayList (java.util.ArrayList)9 Test (org.junit.jupiter.api.Test)9 BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)8