Search in sources :

Example 1 with TransactionRepository

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

the class TransactionRepositoryIntegrationTest method setup.

@BeforeAll
void setup() {
    RepositoryType type = RepositoryType.VERTX;
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    Address recipient = getRecipient();
    String message = "someMessage";
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage(message)).maxFee(maxFee).build();
    TransferTransaction processed = announceAndValidate(type, config().getDefaultAccount(), transferTransaction);
    Assertions.assertEquals(message, processed.getMessage().get().getText());
    PublicAccount account = config().getDefaultAccount().getPublicAccount();
    List<Transaction> allTransactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).order(OrderBy.DESC).signerPublicKey(account.getPublicKey()))).getData();
    List<Transaction> transactions = allTransactions.stream().filter(t -> t.getType() == TransactionType.TRANSFER).collect(Collectors.toList());
    Assertions.assertTrue(allTransactions.size() > 0);
    Assertions.assertTrue(transactions.size() > 0);
    transactionHash = transactions.get(0).getTransactionInfo().get().getHash().get();
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) TransactionStatus(io.nem.symbol.sdk.model.transaction.TransactionStatus) TransactionStatusRepository(io.nem.symbol.sdk.api.TransactionStatusRepository) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) EnumSource(org.junit.jupiter.params.provider.EnumSource) TestInstance(org.junit.jupiter.api.TestInstance) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BeforeAll(org.junit.jupiter.api.BeforeAll) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) OrderBy(io.nem.symbol.sdk.api.OrderBy) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with TransactionRepository

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

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

the class AccountRepositoryIntegrationTest method outgoingTransactionsById.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void outgoingTransactionsById(RepositoryType type) {
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    Account account = config().getDefaultAccount();
    List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).signerPublicKey(account.getPublicAccount().getPublicKey()).pageSize(10))).getData();
    Assertions.assertTrue(transactions.size() > 1);
    String id = transactions.get(1).getTransactionInfo().get().getId().get();
    List<Transaction> transactions2 = get(transactionRepository.getTransactions(TransactionGroup.CONFIRMED, Arrays.asList(id)));
    Assertions.assertEquals(1, transactions2.size());
    transactions2.forEach(t -> Assertions.assertEquals(id, t.getTransactionInfo().get().getId().get()));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TransactionRepository

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

the class AccountRepositoryIntegrationTest method getTransactionById.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getTransactionById(RepositoryType type) {
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    Account account = config().getDefaultAccount();
    List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).signerPublicKey(account.getPublicAccount().getPublicKey()).pageSize(10))).getData();
    Assertions.assertTrue(transactions.size() > 0);
    String id = transactions.get(1).getTransactionInfo().get().getId().get();
    List<Transaction> transactions2 = get(transactionRepository.getTransactions(TransactionGroup.CONFIRMED, Arrays.asList(id)));
    Assertions.assertEquals(1, transactions2.size());
    transactions2.forEach(t -> Assertions.assertEquals(id, t.getTransactionInfo().get().getId().get()));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TransactionRepository

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

the class MultisignIntegrationTest method shouldReturnCosignatureAddedViaListener2.

@Disabled
@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnCosignatureAddedViaListener2(RepositoryType type) {
    Listener listener = getListener(type);
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    TransactionRepository transactionRepository = repositoryFactory.createTransactionRepository();
    SignedTransaction signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.getAddress());
    Object finalObject = get(createHashLockTransactionAndAnnounce(type, signedAggregatedTx, cosignAccount1).flatMap(t -> {
        System.out.println("hash lock finished");
        TransactionServiceImpl transactionService = new TransactionServiceImpl(getRepositoryFactory(type));
        return transactionService.announceAggregateBonded(listener, signedAggregatedTx).flatMap(a -> {
            System.out.println("Aggregate bonded finished");
            return repositoryFactory.createTransactionRepository().search(new TransactionSearchCriteria(TransactionGroup.PARTIAL).signerPublicKey(cosignAccount1.getPublicAccount().getPublicKey())).flatMap((page) -> {
                List<Transaction> transactions = page.getData();
                System.out.println("partialTransactions " + transactions.size());
                AggregateTransaction transactionToCosign = (AggregateTransaction) transactions.get(0);
                CosignatureTransaction cosignatureTransaction = CosignatureTransaction.create(transactionToCosign);
                CosignatureSignedTransaction cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction);
                return transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction).flatMap(r -> {
                    System.out.println("announceAggregateBondedCosignature " + r);
                    return listener.cosignatureAdded(cosignAccount1.getAddress());
                });
            });
        });
    }));
    System.out.println(finalObject.getClass());
    Assertions.assertNull(finalObject);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) Arrays(java.util.Arrays) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) Account(io.nem.symbol.sdk.model.account.Account) EnumSource(org.junit.jupiter.params.provider.EnumSource) Disabled(org.junit.jupiter.api.Disabled) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) TestInstance(org.junit.jupiter.api.TestInstance) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Listener(io.nem.symbol.sdk.api.Listener) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) MultisigAccountModificationTransactionFactory(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransactionFactory) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions(org.junit.jupiter.api.Assertions) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Listener(io.nem.symbol.sdk.api.Listener) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) List(java.util.List) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) 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) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)24 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)24 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)24 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)22 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)14 TransactionPaginationStreamer (io.nem.symbol.sdk.api.TransactionPaginationStreamer)13 Account (io.nem.symbol.sdk.model.account.Account)8 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)7 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)6 TransactionGroup (io.nem.symbol.sdk.model.transaction.TransactionGroup)6 BigInteger (java.math.BigInteger)6 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)5 PublicKey (io.nem.symbol.core.crypto.PublicKey)4 Address (io.nem.symbol.sdk.model.account.Address)4 Message (io.nem.symbol.sdk.model.message.Message)4 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)4 Collections (java.util.Collections)4 List (java.util.List)4