Search in sources :

Example 21 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method mosaicArrayToBeSorted.

@Test
void mosaicArrayToBeSorted() {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(new MosaicId(new BigInteger("200")), BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(new MosaicId(new BigInteger("100")), BigInteger.valueOf(2)));
    TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), mosaics).message(new PlainMessage("")).build();
    assertEquals(mosaics.get(0).getId().getIdAsLong(), new BigInteger("200").longValue());
    assertEquals(mosaics.get(1).getId().getIdAsLong(), new BigInteger("100").longValue());
    TransferTransaction deserialized = (TransferTransaction) new BinarySerializationImpl().deserialize(transaction.serialize());
    assertEquals(mosaics.get(1).getId(), deserialized.getMosaics().get(0).getId());
    assertEquals(mosaics.get(0).getId(), deserialized.getMosaics().get(1).getId());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Example 22 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method serializeAndSignTransaction.

@Test
void serializeAndSignTransaction() {
    TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("")).build();
    SignedTransaction signedTransaction = transaction.signWith(account, generationHash);
    String payload = signedTransaction.getPayload();
    assertEquals("B10000000000000013193EF4F0D94DE26249D196A0575944877D5572CE13B80E4E8380FA34F9F54FF936F96162473857546F7B624A6248D8F7B3D0142DC85BBB06EB7BFEE125880B2134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F200000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0100010000000000672B0000CE560000640000000000000000", payload);
    assertEquals("58D649ABF9A26AFB3F070E26F157920DAB6423415B4344108B93EDD80DE330E5", signedTransaction.getHash());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 23 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class AccountRepositoryOkHttpImpl method getAccountsInfo.

@Override
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
    AccountIds accountIds = new AccountIds().addresses(addresses.stream().map(Address::plain).collect(Collectors.toList()));
    Callable<List<AccountInfoDTO>> callback = () -> getClient().getAccountsInfo(accountIds);
    return exceptionHandling(call(callback).flatMapIterable(item -> item).map(this::toAccountInfo).toList().toObservable());
}
Also used : AccountIds(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountIds) MapperUtils.toAddress(io.nem.symbol.core.utils.MapperUtils.toAddress) Address(io.nem.symbol.sdk.model.account.Address) List(java.util.List)

Example 24 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class AccountRepositoryOkHttpImplTest method shouldProcessExceptionWhenNotFound.

@Test
public void shouldProcessExceptionWhenNotFound() throws Exception {
    Address address = Address.generateRandom(networkType);
    AccountDTO accountDTO = new AccountDTO();
    accountDTO.setAccountType(AccountTypeEnum.NUMBER_1);
    accountDTO.setAddress(encodeAddress(address));
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    mockErrorCode(404, "Account not found!");
    Assertions.assertEquals("ApiException: Not Found - 404 - Code Not Found - Account not found!", Assertions.assertThrows(RepositoryCallException.class, () -> {
        ExceptionUtils.propagate(() -> repository.getAccountInfo(address).toFuture().get());
    }).getMessage());
}
Also used : AccountInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) Test(org.junit.jupiter.api.Test)

Example 25 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class TransactionStatusErrorTest method getAddress.

@Test
void getAddress() {
    Address address = Address.generateRandom(NetworkType.MIJIN_TEST);
    Deadline deadline = new Deadline(BigInteger.valueOf(1));
    final TransactionStatusError transactionStatusError = new TransactionStatusError(address, "hash", "error", deadline);
    assertEquals(address, transactionStatusError.getAddress());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Test(org.junit.jupiter.api.Test)

Aggregations

Address (io.nem.symbol.sdk.model.account.Address)172 Test (org.junit.jupiter.api.Test)124 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)53 BigInteger (java.math.BigInteger)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 ArrayList (java.util.ArrayList)28 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)27 EnumSource (org.junit.jupiter.params.provider.EnumSource)26 Account (io.nem.symbol.sdk.model.account.Account)20 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)19 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)19 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)16 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)16 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)15 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)14 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)13 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)13 Observable (io.reactivex.Observable)13 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)12 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)10