Search in sources :

Example 1 with BlockRepository

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

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

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

the class BlockRepositoryIntegrationTest method searchByBeneficiaryAddressWhenInvalid.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByBeneficiaryAddressWhenInvalid(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    Address expectedBeneficiaryAddress = Account.generateNewAccount(getNetworkType()).getAddress();
    criteria.setBeneficiaryAddress(expectedBeneficiaryAddress);
    BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
    List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
    Assertions.assertTrue(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 4 with BlockRepository

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

the class BlockRepositoryIntegrationTest method searchBySignerPublicKeyWhenInvalid.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchBySignerPublicKeyWhenInvalid(RepositoryType type) {
    BlockRepository blockRepository = getBlockRepository(type);
    BlockSearchCriteria criteria = new BlockSearchCriteria();
    PublicKey expectedSignerPublicKey = PublicKey.generateRandom();
    criteria.setSignerPublicKey(expectedSignerPublicKey);
    BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
    List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
    Assertions.assertTrue(blocks.isEmpty());
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) PublicKey(io.nem.symbol.core.crypto.PublicKey) 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 5 with BlockRepository

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

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