Search in sources :

Example 21 with BlockInfo

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

Example 22 with BlockInfo

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

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

the class BlockServiceTest method isValidTransactionInBlockMultipleNotEquals.

@Test
void isValidTransactionInBlockMultipleNotEquals() 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.getMerkleTransaction(height, leaf)).thenReturn(Observable.just(merkleProofInfo));
    Assertions.assertFalse(service.isValidTransactionInBlock(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 24 with BlockInfo

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

the class BlockServiceTest method isValidTransactionInBlockEmptyEquals.

@Test
void isValidTransactionInBlockEmptyEquals() throws ExecutionException, InterruptedException {
    BigInteger height = BigInteger.ONE;
    String leaf = "ABCD";
    String root = "ABCD";
    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.assertTrue(service.isValidTransactionInBlock(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

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