Search in sources :

Example 1 with MerkleProofInfo

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

the class BlockRepositoryOkHttpImplTest 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());
}
Also used : MerklePathItemDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MerklePathItemDTO) MerkleProofInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MerkleProofInfoDTO) BigInteger(java.math.BigInteger) MerkleProofInfo(io.nem.symbol.sdk.model.blockchain.MerkleProofInfo) Test(org.junit.jupiter.api.Test)

Example 2 with MerkleProofInfo

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

the class BlockRepositoryIntegrationTest method getMerkleReceiptsFromAddresses.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMerkleReceiptsFromAddresses(RepositoryType type) {
    Pair<Account, NamespaceId> testAccount = helper().getTestAccount(type);
    helper().basicSendMosaicFromNemesis(type, testAccount.getRight());
    BlockRepository blockRepository = getBlockRepository(type);
    ReceiptRepository receiptRepository = getRepositoryFactory(type).createReceiptRepository();
    PaginationStreamer<AddressResolutionStatement, ResolutionStatementSearchCriteria> streamer = ReceiptPaginationStreamer.addresses(receiptRepository);
    List<AddressResolutionStatement> list = get(streamer.search(new ResolutionStatementSearchCriteria()).take(5).toList().toObservable());
    Assertions.assertFalse(list.isEmpty());
    list.forEach(s -> {
        String hash = s.generateHash(getNetworkType());
        MerkleProofInfo merkleProofInfo = get(blockRepository.getMerkleReceipts(s.getHeight(), hash));
        Assertions.assertFalse(merkleProofInfo.getMerklePath().isEmpty());
    });
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) ReceiptRepository(io.nem.symbol.sdk.api.ReceiptRepository) BlockRepository(io.nem.symbol.sdk.api.BlockRepository) AddressResolutionStatement(io.nem.symbol.sdk.model.receipt.AddressResolutionStatement) ResolutionStatementSearchCriteria(io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MerkleProofInfo(io.nem.symbol.sdk.model.blockchain.MerkleProofInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with MerkleProofInfo

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

the class BlockRepositoryIntegrationTest method getMerkleTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMerkleTransaction(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    List<Transaction> list = get(streamer.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED)).take(5).toList().toObservable());
    Assertions.assertFalse(list.isEmpty());
    list.forEach(s -> {
        String hash = s.getTransactionInfo().get().getHash().get();
        BigInteger height = s.getTransactionInfo().get().getHeight();
        MerkleProofInfo merkleProofInfo = get(blockRepository.getMerkleTransaction(height, hash));
        Assertions.assertFalse(merkleProofInfo.getMerklePath().isEmpty());
    });
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) BigInteger(java.math.BigInteger) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) MerkleProofInfo(io.nem.symbol.sdk.model.blockchain.MerkleProofInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with MerkleProofInfo

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

the class BlockRepositoryIntegrationTest method getMerkleReceiptsFromTransactions.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMerkleReceiptsFromTransactions(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    ReceiptRepository receiptRepository = getRepositoryFactory(type).createReceiptRepository();
    PaginationStreamer<TransactionStatement, TransactionStatementSearchCriteria> streamer = ReceiptPaginationStreamer.transactions(receiptRepository);
    List<TransactionStatement> list = get(streamer.search(new TransactionStatementSearchCriteria()).take(5).toList().toObservable());
    System.out.println(list.size());
    list.forEach(s -> {
        String hash = s.generateHash();
        System.out.println(hash);
        System.out.println(s.getHeight());
        MerkleProofInfo merkleProofInfo = get(blockRepository.getMerkleReceipts(s.getHeight(), hash));
        System.out.println(toJson(merkleProofInfo));
    });
}
Also used : TransactionStatementSearchCriteria(io.nem.symbol.sdk.api.TransactionStatementSearchCriteria) ReceiptRepository(io.nem.symbol.sdk.api.ReceiptRepository) BlockRepository(io.nem.symbol.sdk.api.BlockRepository) TransactionStatement(io.nem.symbol.sdk.model.receipt.TransactionStatement) MerkleProofInfo(io.nem.symbol.sdk.model.blockchain.MerkleProofInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with MerkleProofInfo

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

Aggregations

MerkleProofInfo (io.nem.symbol.sdk.model.blockchain.MerkleProofInfo)17 Test (org.junit.jupiter.api.Test)13 BigInteger (java.math.BigInteger)12 MerklePathItem (io.nem.symbol.sdk.model.blockchain.MerklePathItem)9 ArrayList (java.util.ArrayList)9 BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)8 BlockRepository (io.nem.symbol.sdk.api.BlockRepository)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 ReceiptRepository (io.nem.symbol.sdk.api.ReceiptRepository)3 ResolutionStatementSearchCriteria (io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria)2 MerklePathItemDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MerklePathItemDTO)2 MerkleProofInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MerkleProofInfoDTO)2 MerklePathItemDTO (io.nem.symbol.sdk.openapi.vertx.model.MerklePathItemDTO)2 MerkleProofInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.MerkleProofInfoDTO)2 TransactionPaginationStreamer (io.nem.symbol.sdk.api.TransactionPaginationStreamer)1 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)1 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)1 TransactionStatementSearchCriteria (io.nem.symbol.sdk.api.TransactionStatementSearchCriteria)1 Account (io.nem.symbol.sdk.model.account.Account)1