Search in sources :

Example 6 with Listener

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

the class ListenerIntegrationTest method shouldReturnConfirmedTransactionAddressSignerViaListener.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnConfirmedTransactionAddressSignerViaListener(RepositoryType type) {
    Listener listener = getListener(type);
    SignedTransaction signedTransaction = this.announceStandaloneTransferTransaction(type, this.getRecipient());
    Observable<Transaction> confirmed = listener.confirmed(this.account.getAddress(), signedTransaction.getHash());
    Transaction transaction = get(confirmed.take(1));
    assertEquals(signedTransaction.getHash(), transaction.getTransactionInfo().get().getHash().get());
}
Also used : Listener(io.nem.symbol.sdk.api.Listener) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) 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 7 with Listener

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

the class ListenerIntegrationTest method shouldConnectToWebSocket.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldConnectToWebSocket(RepositoryType type) throws ExecutionException, InterruptedException {
    Listener listener = getRepositoryFactory(type).createListener();
    CompletableFuture<Void> connected = listener.open();
    connected.get();
    assertTrue(connected.isDone());
    assertNotNull(listener.getUid());
}
Also used : Listener(io.nem.symbol.sdk.api.Listener) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with Listener

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

the class ListenerForTests method run.

private void run() throws ExecutionException, InterruptedException {
    Listener listener = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE).createListener();
    listener.open().get();
    listener.newBlock().subscribe(b -> {
        System.out.println("New BLOCK!! " + b.getHeight());
    });
    listener.finalizedBlock().subscribe(b -> {
        System.out.println("New Finalized Block!! " + b.getHeight());
    });
    listenToAccount("Test Account 1", config().getTestAccount().getAddress(), listener);
    listenToAccount("Test Account 2", config().getTestAccount2().getAddress(), listener);
    listenToAccount("Cosignatory Account", config().getCosignatoryAccount().getAddress(), listener);
    listenToAccount("Cosignatory Account 2", config().getCosignatory2Account().getAddress(), listener);
    listenToAccount("Multisign Account 2", config().getMultisigAccount().getAddress(), listener);
    config().getNemesisAccounts().forEach(account -> listenToAccount("Nemesis Account", account.getAddress(), listener));
}
Also used : Listener(io.nem.symbol.sdk.api.Listener)

Example 9 with Listener

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

the class ListenerStatusIntegrationTest method sendTransactionsReusingListener.

@Test
void sendTransactionsReusingListener() throws ExecutionException, InterruptedException {
    RepositoryType type = DEFAULT_REPOSITORY_TYPE;
    Account account1 = config().getNemesisAccount1();
    Account account2 = Account.generateNewAccount(getNetworkType());
    Account account3 = Account.generateNewAccount(getNetworkType());
    Listener listener = createListener(type);
    listener.unconfirmedRemoved(account1.getAddress()).subscribe(a -> {
        System.out.println(">>>> account 1 " + a);
    });
    listener.unconfirmedRemoved(account2.getAddress()).subscribe(a -> {
        System.out.println(">>>> account 2 " + a);
    });
    listener.unconfirmedRemoved(account3.getAddress()).subscribe(a -> {
        System.out.println(">>>> account 3  " + a);
    });
    // IT PRINTS:
    // >>>> account 1
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 2
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 3
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 1
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 2
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    // >>>> account 3
    // 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account2.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
    announceAndValidate(type, account1, transferTransaction);
    sleep(1000);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) Listener(io.nem.symbol.sdk.api.Listener) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test)

Example 10 with Listener

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

Aggregations

Listener (io.nem.symbol.sdk.api.Listener)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)15 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)13 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)12 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)11 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)9 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)9 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)8 CosignatureTransaction (io.nem.symbol.sdk.model.transaction.CosignatureTransaction)8 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)8 TransactionService (io.nem.symbol.sdk.api.TransactionService)7 Disabled (org.junit.jupiter.api.Disabled)7 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)6 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)6 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)5 Account (io.nem.symbol.sdk.model.account.Account)5 Address (io.nem.symbol.sdk.model.account.Address)4 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)4 BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)4