Search in sources :

Example 21 with RepositoryCallException

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

the class TransactionRepositoryIntegrationTest method throwExceptionWhenTransactionDoesNotExists.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void throwExceptionWhenTransactionDoesNotExists(RepositoryType type) {
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(getTransactionRepository(type).getTransaction(TransactionGroup.CONFIRMED, invalidTransactionHash)));
    Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id '" + invalidTransactionHash + "'", exception.getMessage());
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with RepositoryCallException

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

the class TestHelper method isMultisig.

public boolean isMultisig(RepositoryType type, Account multisigAccount) {
    try {
        MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
        MultisigAccountInfo multisigAccountInfo = get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
        return multisigAccountInfo != null;
    } catch (RepositoryCallException e) {
        Assertions.assertEquals(404, e.getStatusCode());
        return false;
    }
}
Also used : MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo)

Example 23 with RepositoryCallException

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

the class TestHelper method createMultisigAccountComplete.

public MultisigAccountInfo createMultisigAccountComplete(RepositoryType type, Account multisigAccount, Account... accounts) {
    AccountRepository accountRepository = getRepositoryFactory(type).createAccountRepository();
    MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
    AccountInfo accountInfo = get(accountRepository.getAccountInfo(multisigAccount.getAddress()));
    System.out.println(getJsonHelper().print(accountInfo));
    try {
        MultisigAccountInfo multisigAccountInfo = get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
        System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " already exist");
        System.out.println(getJsonHelper().print(multisigAccountInfo));
        return multisigAccountInfo;
    } catch (RepositoryCallException e) {
        System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " does not exist. Creating");
    }
    System.out.println("Creating multisg account " + multisigAccount.getAddress().plain());
    List<UnresolvedAddress> additions = Arrays.stream(accounts).map(Account::getAddress).collect(Collectors.toList());
    MultisigAccountModificationTransaction convertIntoMultisigTransaction = MultisigAccountModificationTransactionFactory.create(getNetworkType(), getDeadline(), (byte) 1, (byte) 1, additions, Collections.emptyList()).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(convertIntoMultisigTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(accounts), getGenerationHash());
    Transaction aggregateTransaciton = get(getTransactionService(type).announce(getListener(type), signedAggregateTransaction));
    sleep(1000);
    Assertions.assertEquals(aggregateTransaciton.getTransactionInfo().get().getHash().get(), signedAggregateTransaction.getHash());
    return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
Also used : MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction)

Example 24 with RepositoryCallException

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

the class NamespaceRepositoryIntegrationTest method throwExceptionWhenNamespaceDoesNotExists.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void throwExceptionWhenNamespaceDoesNotExists(RepositoryType type) {
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(getNamespaceRepository(type).getNamespace(NamespaceId.createFromName("nonregisterednamespace"))));
    Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id 'F75CF605C224A9E7'", exception.getMessage());
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with RepositoryCallException

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

the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenNoNamespaceError.

@Test
void getNetworkCurrencyFromMosaicIdWhenNoNamespaceError() throws Exception {
    MosaicId mosaicId = new MosaicId(BigInteger.TEN);
    Account account = Account.generateNewAccount(NetworkType.MAIN_NET);
    BigInteger supply = BigInteger.valueOf(12);
    MosaicInfo mosaicInfo = new MosaicInfo("abc", 1, mosaicId, supply, BigInteger.ONE, account.getAddress(), 4L, MosaicFlags.create(true, true, true), 10, BigInteger.TEN);
    Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(mosaicInfo)));
    Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.error(new RepositoryCallException("Not found", 404, null)));
    Currency currency = service.getCurrency(mosaicId).toFuture().get();
    Assertions.assertEquals(10, currency.getDivisibility());
    Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
    Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
    Assertions.assertFalse(currency.getNamespaceId().isPresent());
    Assertions.assertTrue(currency.isTransferable());
    Assertions.assertTrue(currency.isSupplyMutable());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) Currency(io.nem.symbol.sdk.model.mosaic.Currency) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Aggregations

RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)13 Test (org.junit.jupiter.api.Test)10 BigInteger (java.math.BigInteger)4 MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)3 Address (io.nem.symbol.sdk.model.account.Address)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 AccountRepository (io.nem.symbol.sdk.api.AccountRepository)2 CurrencyService (io.nem.symbol.sdk.api.CurrencyService)2 HashLockRepository (io.nem.symbol.sdk.api.HashLockRepository)2 MultisigRepository (io.nem.symbol.sdk.api.MultisigRepository)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 TestHelperVertx.loadTransactionInfoDTO (io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO)2 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)2 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)2 AnnounceTransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO)2 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)2 TransactionMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)2 AccountSearchCriteria (io.nem.symbol.sdk.api.AccountSearchCriteria)1