Search in sources :

Example 11 with RepositoryFactory

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

the class AccountSearchRepositoryIntegrationTest method searchMosaicIdProvided.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchMosaicIdProvided(RepositoryType type) {
    AccountPaginationStreamer streamer = new AccountPaginationStreamer(this.getAccountRepository(type));
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    NamespaceId networkCurrencyId = get(repositoryFactory.getNetworkCurrency()).getNamespaceId().get();
    Assertions.assertTrue(networkCurrencyId.getFullName().isPresent());
    MosaicId mosaicId = get(repositoryFactory.createNamespaceRepository().getLinkedMosaicId(networkCurrencyId));
    AccountSearchCriteria criteria = new AccountSearchCriteria().mosaicId(mosaicId);
    List<AccountInfo> accounts = get(streamer.search(criteria).toList().toObservable());
    Assertions.assertFalse(accounts.isEmpty());
    System.out.println(toJson(accounts));
    accounts.forEach(a -> {
        Assertions.assertTrue(a.getMosaics().stream().filter(m -> m.getId().equals(mosaicId)).findFirst().get().getAmount().longValue() > 0);
    });
}
Also used : AccountSearchCriteria(io.nem.symbol.sdk.api.AccountSearchCriteria) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) AccountPaginationStreamer(io.nem.symbol.sdk.api.AccountPaginationStreamer) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with RepositoryFactory

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

the class ListenerIntegrationTest method shouldReturnAggregateBondedAddedTransactionViaListener.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnAggregateBondedAddedTransactionViaListener(RepositoryType type) {
    Listener listener = getListener(type);
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    TransactionService transactionService = new TransactionServiceImpl(repositoryFactory);
    Pair<SignedTransaction, SignedTransaction> pair = this.createAggregateBondedTransaction(type);
    System.out.println("Announcing HashLock transaction " + pair.getRight().getHash());
    get(transactionService.announce(listener, pair.getRight()));
    SignedTransaction signedTransaction = pair.getLeft();
    System.out.println("Announcing Aggregate transaction " + signedTransaction.getHash());
    AggregateTransaction aggregateTransaction = get(transactionService.announceAggregateBonded(listener, signedTransaction).take(1));
    assertEquals(signedTransaction.getHash(), aggregateTransaction.getTransactionInfo().get().getHash().get());
}
Also used : Listener(io.nem.symbol.sdk.api.Listener) TransactionService(io.nem.symbol.sdk.api.TransactionService) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with RepositoryFactory

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

the class BlockServiceIntegrationTest method isValidTransactionInBlock.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void isValidTransactionInBlock(RepositoryType type) {
    BigInteger height = BigInteger.ONE;
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).height(height).pageNumber(1))).getData();
    BlockService service = new BlockServiceImpl(repositoryFactory);
    transactions.forEach(t -> {
        String hash = t.getTransactionInfo().get().getHash().get();
        Assertions.assertNotNull(hash);
        Boolean valid = get(service.isValidTransactionInBlock(height, hash));
        Assertions.assertTrue(valid);
    });
}
Also used : Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) BigInteger(java.math.BigInteger) BlockService(io.nem.symbol.sdk.api.BlockService) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with RepositoryFactory

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

the class RepositoryFactoryVertxImplTest method getUserProvidedConfiguration.

@Test
public void getUserProvidedConfiguration() throws Exception {
    String baseUrl = "https://localhost:1934/path";
    RepositoryFactoryConfiguration configuration = new RepositoryFactoryConfiguration(baseUrl);
    configuration.withGenerationHash("abc");
    configuration.withNetworkType(NetworkType.MAIN_NET);
    configuration.withNetworkCurrencies(NetworkCurrencies.PUBLIC);
    RepositoryFactory factory = new RepositoryFactoryVertxImpl(configuration);
    Assertions.assertEquals(configuration.getNetworkType(), factory.getNetworkType().toFuture().get());
    Assertions.assertEquals(configuration.getGenerationHash(), factory.getGenerationHash().toFuture().get());
    Assertions.assertEquals(configuration.getNetworkCurrencies().getHarvest(), factory.getHarvestCurrency().toFuture().get());
    Assertions.assertEquals(configuration.getNetworkCurrencies().getCurrency(), factory.getNetworkCurrency().toFuture().get());
}
Also used : RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) RepositoryFactoryConfiguration(io.nem.symbol.sdk.api.RepositoryFactoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 15 with RepositoryFactory

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

the class TransactionServiceTest method setup.

@BeforeEach
void setup() {
    account = Account.generateNewAccount(networkType);
    RepositoryFactory factory = Mockito.mock(RepositoryFactory.class);
    transactionRepositoryMock = Mockito.mock(TransactionRepository.class);
    Mockito.when(factory.createTransactionRepository()).thenReturn(transactionRepositoryMock);
    receiptRepositoryMock = Mockito.mock(ReceiptRepository.class);
    Mockito.when(factory.createReceiptRepository()).thenReturn(receiptRepositoryMock);
    listener = Mockito.mock(Listener.class);
    service = new TransactionServiceImpl(factory);
}
Also used : ReceiptRepository(io.nem.symbol.sdk.api.ReceiptRepository) Listener(io.nem.symbol.sdk.api.Listener) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)44 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 EnumSource (org.junit.jupiter.params.provider.EnumSource)16 Test (org.junit.jupiter.api.Test)11 BeforeEach (org.junit.jupiter.api.BeforeEach)7 RepositoryFactoryConfiguration (io.nem.symbol.sdk.api.RepositoryFactoryConfiguration)6 Account (io.nem.symbol.sdk.model.account.Account)6 BigInteger (java.math.BigInteger)6 Listener (io.nem.symbol.sdk.api.Listener)5 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)5 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)5 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)5 NetworkCurrencies (io.nem.symbol.sdk.model.mosaic.NetworkCurrencies)5 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)4 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)4 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)4 CurrencyService (io.nem.symbol.sdk.api.CurrencyService)3 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)3 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)3 TransactionService (io.nem.symbol.sdk.api.TransactionService)3