Search in sources :

Example 6 with BlockRepository

use of io.nem.symbol.sdk.api.BlockRepository in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method searchByBeneficiaryAddress.

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

Example 7 with BlockRepository

use of io.nem.symbol.sdk.api.BlockRepository 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)

Example 8 with BlockRepository

use of io.nem.symbol.sdk.api.BlockRepository in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method getMerkleReceiptsFromMosaics.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMerkleReceiptsFromMosaics(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    ReceiptRepository receiptRepository = getRepositoryFactory(type).createReceiptRepository();
    PaginationStreamer<MosaicResolutionStatement, ResolutionStatementSearchCriteria> streamer = ReceiptPaginationStreamer.mosaics(receiptRepository);
    List<MosaicResolutionStatement> 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 : ReceiptRepository(io.nem.symbol.sdk.api.ReceiptRepository) BlockRepository(io.nem.symbol.sdk.api.BlockRepository) ResolutionStatementSearchCriteria(io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria) MerkleProofInfo(io.nem.symbol.sdk.model.blockchain.MerkleProofInfo) MosaicResolutionStatement(io.nem.symbol.sdk.model.receipt.MosaicResolutionStatement) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with BlockRepository

use of io.nem.symbol.sdk.api.BlockRepository in project nem2-sdk-java by nemtech.

the class BlockRepositoryIntegrationTest method searchUsingOffset.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUsingOffset(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    criteria.setPageSize(10);
    criteria.setOrderBy(BlockOrderBy.HEIGHT);
    int offsetIndex = 2;
    List<BlockInfo> blocksWithoutOffset = get(streamer.search(criteria).toList().toObservable());
    String offset = blocksWithoutOffset.get(offsetIndex).getHeight().toString();
    criteria.setOffset(offset);
    List<BlockInfo> blockFromOffsets = get(streamer.search(criteria).toList().toObservable());
    List<BlockInfo> expectedList = blocksWithoutOffset.stream().skip(offsetIndex + 1).collect(Collectors.toList());
    // If the block grows when running the last search
    PaginationTester.sameEntities(expectedList, blockFromOffsets.subList(0, expectedList.size()));
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BlockRepository (io.nem.symbol.sdk.api.BlockRepository)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EnumSource (org.junit.jupiter.params.provider.EnumSource)9 BlockPaginationStreamer (io.nem.symbol.sdk.api.BlockPaginationStreamer)5 BlockSearchCriteria (io.nem.symbol.sdk.api.BlockSearchCriteria)5 BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)5 MerkleProofInfo (io.nem.symbol.sdk.model.blockchain.MerkleProofInfo)4 ReceiptRepository (io.nem.symbol.sdk.api.ReceiptRepository)3 PublicKey (io.nem.symbol.core.crypto.PublicKey)2 ResolutionStatementSearchCriteria (io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria)2 Address (io.nem.symbol.sdk.model.account.Address)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 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)1 AddressResolutionStatement (io.nem.symbol.sdk.model.receipt.AddressResolutionStatement)1 MosaicResolutionStatement (io.nem.symbol.sdk.model.receipt.MosaicResolutionStatement)1 TransactionStatement (io.nem.symbol.sdk.model.receipt.TransactionStatement)1