Search in sources :

Example 26 with Address

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

the class TransactionStatusErrorTest method getStatus.

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

Example 27 with Address

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

the class HashLockInfoTest method constructor.

@Test
void constructor() {
    Optional<String> recordId = Optional.of("abc");
    Address ownerAddress = Address.createFromRawAddress("SDY3NFHBQAPO7ZBII3USHG2UZHJYD7G7FICKIII");
    MosaicId mosaicId = MosaicId.createFromNonce(new MosaicNonce(1), ownerAddress);
    BigInteger amount = BigInteger.ONE;
    BigInteger endHeight = BigInteger.TEN;
    LockStatus status = LockStatus.USED;
    String hash = "DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512F55";
    HashLockInfo info = new HashLockInfo(recordId.orElse(null), 1, ownerAddress, mosaicId, amount, endHeight, status, hash);
    Assertions.assertEquals(recordId, info.getRecordId());
    Assertions.assertEquals(ownerAddress, info.getOwnerAddress());
    Assertions.assertEquals(mosaicId, info.getMosaicId());
    Assertions.assertEquals(amount, info.getAmount());
    Assertions.assertEquals(endHeight, info.getEndHeight());
    Assertions.assertEquals(status, info.getStatus());
    Assertions.assertEquals(hash, info.getHash());
    byte[] serializedState = info.serialize();
    String expectedHex = "010090F1B694E1801EEFE42846E9239B54C9D381FCDF2A04A421E9F49B9E5199FC7601000000000000000A0000000000000001DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512F55";
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(serializedState));
    HashLockInfoBuilder builder = HashLockInfoBuilder.loadFromBinary(SerializationUtils.toDataInput(serializedState));
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(builder.serialize()));
}
Also used : HashLockInfoBuilder(io.nem.symbol.catapult.builders.HashLockInfoBuilder) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) Test(org.junit.jupiter.api.Test)

Example 28 with Address

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

the class SecretLockInfoTest method constructor.

@Test
void constructor() {
    Optional<String> recordId = Optional.of("abc");
    Address ownerAddress = Address.createFromRawAddress("SDY3NFHBQAPO7ZBII3USHG2UZHJYD7G7FICKIII");
    Address recipientAddress = Address.createFromRawAddress("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ");
    MosaicId mosaicId = MosaicId.createFromNonce(new MosaicNonce(1), ownerAddress);
    BigInteger amount = BigInteger.ONE;
    BigInteger endHeight = BigInteger.TEN;
    LockStatus status = LockStatus.USED;
    String hash = "ABC";
    LockHashAlgorithm hashAlgorithm = LockHashAlgorithm.HASH_256;
    String secret = "DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512AAA";
    SecretLockInfo info = new SecretLockInfo(recordId.get(), 1, ownerAddress, mosaicId, amount, endHeight, status, hashAlgorithm, secret, recipientAddress, hash);
    Assertions.assertEquals(recordId, info.getRecordId());
    Assertions.assertEquals(ownerAddress, info.getOwnerAddress());
    Assertions.assertEquals(mosaicId, info.getMosaicId());
    Assertions.assertEquals(amount, info.getAmount());
    Assertions.assertEquals(endHeight, info.getEndHeight());
    Assertions.assertEquals(status, info.getStatus());
    Assertions.assertEquals(hash, info.getCompositeHash());
    Assertions.assertEquals(hashAlgorithm, info.getHashAlgorithm());
    Assertions.assertEquals(recipientAddress, info.getRecipientAddress());
    byte[] serializedState = info.serialize();
    String expectedHex = "010090F1B694E1801EEFE42846E9239B54C9D381FCDF2A04A421E9F49B9E5199FC7601000000000000000A000000000000000102DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512AAA90F36CA680C35D630662A0C38DC89D4978D10B511B3D241A";
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(serializedState));
    SecretLockInfoBuilder builder = SecretLockInfoBuilder.loadFromBinary(SerializationUtils.toDataInput(serializedState));
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(builder.serialize()));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) SecretLockInfoBuilder(io.nem.symbol.catapult.builders.SecretLockInfoBuilder) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) Test(org.junit.jupiter.api.Test)

Example 29 with Address

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

the class VertxAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.

@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
    Address address = Address.generateRandom(networkType);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", networkType)))).build();
    Account cosignatoryAccount = Account.generateNewAccount(this.networkType);
    Account cosignatoryAccount2 = Account.generateNewAccount(this.networkType);
    Account cosignatoryAccount3 = Account.generateNewAccount(this.networkType);
    SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2, cosignatoryAccount3), generationHash);
    BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
    AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
    Assertions.assertEquals(2, deserialized.getCosignatures().size());
    Assertions.assertEquals(cosignatoryAccount2.getPublicAccount(), deserialized.getCosignatures().get(0).getSigner());
    Assertions.assertEquals(cosignatoryAccount3.getPublicAccount(), deserialized.getCosignatures().get(1).getSigner());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 30 with Address

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

the class VertxAggregateTransactionTest method serialization.

@Test
@DisplayName("Serialization")
void serialization() {
    Address address = Address.generateRandom(networkType);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), address, Collections.singletonList(createAbsolute(BigInteger.valueOf(10000000)))).message(new PlainMessage("")).build();
    PublicAccount signer = Account.generateNewAccount(networkType).getPublicAccount();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTx.toAggregate(signer))).build();
    byte[] actual = aggregateTx.serialize();
    BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
    AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(actual);
    assertEquals(signer, deserialized.getInnerTransactions().get(0).getSigner().get());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

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