Search in sources :

Example 31 with Mosaic

use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.

the class TransactionServiceTest method announceAggregateBonded.

@Test
void announceAggregateBonded() throws ExecutionException, InterruptedException {
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transaction1), Collections.emptyList()).build();
    String generationHash = "abc";
    SignedTransaction aggregateSignedTransaction = aggregateTransaction.signWith(account, generationHash);
    TransactionAnnounceResponse aggregateTransactionAnnounceResponse = new TransactionAnnounceResponse("Aggregate Some Message");
    Mockito.when(transactionRepositoryMock.announceAggregateBonded(Mockito.eq(aggregateSignedTransaction))).thenReturn(Observable.just(aggregateTransactionAnnounceResponse));
    Mockito.when(listener.aggregateBondedAddedOrError(Mockito.eq(account.getAddress()), Mockito.eq(aggregateSignedTransaction.getHash()))).thenReturn(Observable.just(aggregateTransaction));
    Observable<AggregateTransaction> announcedTransaction = service.announceAggregateBonded(listener, aggregateSignedTransaction);
    Assertions.assertEquals(aggregateTransaction, announcedTransaction.toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 32 with Mosaic

use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.

the class TransactionServiceTest method transferTransactionResolveAliasCannotMosaicAliasResolveAliases.

@Test
void transferTransactionResolveAliasCannotMosaicAliasResolveAliases() {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
    NamespaceId idontexist = NamespaceId.createFromName("idontexist");
    mosaics.add(new Mosaic(idontexist, BigInteger.valueOf(3)));
    UnresolvedAddress recipient = addressNamespace1;
    String transactionHash = "aaaa";
    TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipient, mosaics).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    simulateStatement(height, 1, 0);
    TransferTransaction transaction = factory.build();
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ExceptionUtils.propagate(() -> service.resolveAliases(hashes).toFuture().get()));
    Assertions.assertEquals("MosaicId could not be resolved for alias " + idontexist.getIdAsHex(), exception.getMessage());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) ArrayList(java.util.ArrayList) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 33 with Mosaic

use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.

the class BinarySerializationTest method testSerializationDeserialization.

@Test
void testSerializationDeserialization() {
    BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
    TransferTransaction transaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Address.generateRandom(NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).build();
    byte[] serialize = binarySerialization.serialize(transaction);
    Assertions.assertNotNull(serialize);
    TransferTransaction deserializedTransaction = (TransferTransaction) binarySerialization.deserialize(serialize);
    Assertions.assertNotNull(deserializedTransaction);
    Assertions.assertEquals("Some Message", deserializedTransaction.getMessage().get().getText());
    Assertions.assertEquals(MessageType.PLAIN_MESSAGE, deserializedTransaction.getMessage().get().getType());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 34 with Mosaic

use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.

the class BinarySerializationTest method testSignature.

@Test
void testSignature() {
    BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
    TransferTransaction transaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Address.generateRandom(NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).build();
    SignedTransaction signedTransaction = transaction.signWith(account, generationHash);
    String signature = signedTransaction.getPayload().substring(16, 128 + 16);
    // If we deserialize the signed transaction, we get everything back, include the
    // signer and
    // signature
    byte[] payloadWithSignatureAndSigner = ConvertUtils.getBytes(signedTransaction.getPayload());
    TransferTransaction deserialized = (TransferTransaction) binarySerialization.deserialize(payloadWithSignatureAndSigner);
    Assertions.assertTrue(deserialized.getSignature().isPresent());
    Assertions.assertTrue(deserialized.getSigner().isPresent());
    Assertions.assertEquals(signature.toUpperCase(), deserialized.getSignature().get());
    Assertions.assertEquals(account.getPublicAccount(), deserialized.getSigner().get());
    // Test that the payload is the same, just without the signature and signer.
    byte[] payloadWithoutSignatureAndSigner = binarySerialization.serialize(transaction);
    Assertions.assertEquals(ConvertUtils.toHex(payloadWithoutSignatureAndSigner).substring(208), ConvertUtils.toHex(payloadWithSignatureAndSigner).substring(208));
    Transaction deserializeWithoutSignature = binarySerialization.deserialize(payloadWithoutSignatureAndSigner);
    Assertions.assertFalse(deserializeWithoutSignature.getSignature().isPresent());
    Assertions.assertFalse(deserializeWithoutSignature.getSigner().isPresent());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 35 with Mosaic

use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.

the class TransactionServiceTest method announceHashLockAggregateBonded.

@Test
void announceHashLockAggregateBonded() throws ExecutionException, InterruptedException {
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transaction1), Collections.emptyList()).build();
    String generationHash = "abc";
    SignedTransaction aggregateSignedTransaction = aggregateTransaction.signWith(account, generationHash);
    HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Currency.CAT_CURRENCY.createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), aggregateSignedTransaction.getHash()).build();
    SignedTransaction hashLockSignedTranscation = hashLockTransaction.signWith(account, generationHash);
    TransactionAnnounceResponse aggregateTransactionAnnounceResponse = new TransactionAnnounceResponse("Aggregate Some Message");
    TransactionAnnounceResponse hashTransactionAnnounceResponse = new TransactionAnnounceResponse("Hash Some Message");
    Mockito.when(transactionRepositoryMock.announceAggregateBonded(Mockito.eq(aggregateSignedTransaction))).thenReturn(Observable.just(aggregateTransactionAnnounceResponse));
    Mockito.when(transactionRepositoryMock.announce(Mockito.eq(hashLockSignedTranscation))).thenReturn(Observable.just(hashTransactionAnnounceResponse));
    Mockito.when(listener.confirmedOrError(Mockito.eq(account.getAddress()), Mockito.eq(hashLockSignedTranscation.getHash()))).thenReturn(Observable.just(hashLockTransaction));
    Mockito.when(listener.aggregateBondedAddedOrError(Mockito.eq(account.getAddress()), Mockito.eq(aggregateSignedTransaction.getHash()))).thenReturn(Observable.just(aggregateTransaction));
    Observable<AggregateTransaction> announcedTransaction = service.announceHashLockAggregateBonded(listener, hashLockSignedTranscation, aggregateSignedTransaction);
    Assertions.assertEquals(aggregateTransaction, announcedTransaction.toFuture().get());
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)35 Test (org.junit.jupiter.api.Test)26 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)24 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)19 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)18 BigInteger (java.math.BigInteger)18 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)15 Address (io.nem.symbol.sdk.model.account.Address)12 ArrayList (java.util.ArrayList)12 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)8 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)6 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)6 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)5 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)5 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)4 Account (io.nem.symbol.sdk.model.account.Account)4 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)4 Currency (io.nem.symbol.sdk.model.mosaic.Currency)4 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)4