use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfo.
@Test
void aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfo() {
ArrayList<Mosaic> mosaics = new ArrayList<>();
mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
mosaics.add(new Mosaic(mosaicId3, BigInteger.valueOf(3)));
UnresolvedAddress recipient = addressNamespace1;
String transactionHash = "aaaa";
TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipient, mosaics).message(new PlainMessage("")).transactionInfo(TransactionInfo.create(height, 0, "ABC", "BBBB", ""));
// Extra transfer not aliases
TransactionFactory<TransferTransaction> extraTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), address2, Collections.singletonList(new Mosaic(mosaicId1, BigInteger.valueOf(1)))).message(new PlainMessage(""));
TransferTransaction transferTransaction = factory.build();
transferTransaction.toAggregate(Account.generateNewAccount(networkType).getPublicAccount());
TransactionFactory<AggregateTransaction> aggregateTransactionFactory = AggregateTransactionFactory.createComplete(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction, extraTransaction.build().toAggregate(Account.generateNewAccount(networkType).getPublicAccount()))).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
AggregateTransaction aggregateTransaction = aggregateTransactionFactory.build();
simulateStatement(height, 1, 1);
List<String> hashes = Collections.singletonList(transactionHash);
Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(aggregateTransaction)));
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
ExceptionUtils.propagate(service.resolveAliases(hashes).toFuture()::get);
});
Assertions.assertEquals("TransactionIndex cannot be loaded from Transaction TRANSFER", exception.getMessage());
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serialization.
@Test
@DisplayName("Serialization-public")
void serialization() {
String expected = "D400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F200000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A1400020000000000671305C6390B00002C01000000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
Mosaic mosaicId1 = new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100));
Mosaic mosaicId2 = new Mosaic(new MosaicId(new BigInteger("12342763262823")), BigInteger.valueOf(300));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Arrays.asList(mosaicId1, mosaicId2)).message(new PlainMessage("Some Message 漢字")).signer(account.getPublicAccount()).build();
assertSerialization(expected, transaction);
String embeddedExpected = "84000000000000002134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F2000000000190544190F36CA680C35D630662A0C38DC89D4978D10B511B3D241A1400020000000000671305C6390B00002C01000000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
assertEmbeddedSerialization(embeddedExpected, transaction);
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method mosaicArrayToBeSortedHex.
@Test
void mosaicArrayToBeSortedHex() {
ArrayList<Mosaic> mosaics = new ArrayList<>();
mosaics.add(new Mosaic(new MosaicId("D525AD41D95FCF29"), BigInteger.valueOf(1)));
mosaics.add(new Mosaic(new MosaicId("77A1969932D987D7"), BigInteger.valueOf(2)));
mosaics.add(new Mosaic(new MosaicId("67F2B76F28BD36BA"), BigInteger.valueOf(3)));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), mosaics).message(new PlainMessage("")).build();
assertEquals("D525AD41D95FCF29", mosaics.get(0).getId().getIdAsHex().toUpperCase());
assertEquals("77A1969932D987D7", mosaics.get(1).getId().getIdAsHex().toUpperCase());
assertEquals("67F2B76F28BD36BA", mosaics.get(2).getId().getIdAsHex().toUpperCase());
TransferTransaction deserialized = (TransferTransaction) new BinarySerializationImpl().deserialize(transaction.serialize());
assertEquals(mosaics.get(2).getId(), deserialized.getMosaics().get(0).getId());
assertEquals(mosaics.get(1).getId(), deserialized.getMosaics().get(1).getId());
assertEquals(mosaics.get(0).getId(), deserialized.getMosaics().get(2).getId());
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serializationNamespaceRecipient.
@Test
@DisplayName("Serialization-public-namespace-recipient")
void serializationNamespaceRecipient() {
String expected = "C4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001905441000000000000000001000000000000009151776168D24257D80000000000000000000000000000001400010000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
NamespaceId recipient = NamespaceId.createFromName("nem.owner");
Assertions.assertEquals("D85742D268617751", recipient.getIdAsHex());
Assertions.assertEquals("9151776168D24257D8000000000000000000000000000000", recipient.encoded(networkType));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), recipient, Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message 漢字")).build();
Assertions.assertEquals(recipient.encoded(networkType), transaction.getRecipient().encoded(networkType));
assertSerialization(expected, transaction);
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class CreatingAnEscrowContractWithAggregateBondedTransactionIntegrationTest method executeTransfer.
@Test
@Disabled
void executeTransfer() {
Account ticketDistributorAccount = this.config().getTestAccount();
Account aliceAccount = this.config().getTestAccount2();
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
MosaicId mosaicId = createMosaic(ticketDistributorAccount, type, BigInteger.ZERO, null);
TransferTransaction aliceToTicketDistributorTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), ticketDistributorAccount.getAddress(), Collections.singletonList(getNetworkCurrency().createRelative(BigInteger.valueOf(100)))).message(new PlainMessage("send 100 cat.currency to distributor")).maxFee(maxFee).build();
TransferTransaction ticketDistributorToAliceTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), aliceAccount.getAddress(), Collections.singletonList(new Mosaic(mosaicId, BigInteger.ONE))).message(new PlainMessage("send 1 museum ticket to alice")).maxFee(maxFee).build();
/* end block 01 */
/* start block 02 */
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Arrays.asList(aliceToTicketDistributorTx.toAggregate(aliceAccount.getPublicAccount()), ticketDistributorToAliceTx.toAggregate(ticketDistributorAccount.getPublicAccount()))).maxFee(maxFee).build();
String networkGenerationHash = getGenerationHash();
SignedTransaction signedTransaction = aliceAccount.sign(aggregateTransaction, networkGenerationHash);
System.out.println("Aggregate Transaction Hash: " + signedTransaction.getHash());
/* end block 02 */
/* start block 03 */
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.TEN), BigInteger.valueOf(480), signedTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = aliceAccount.sign(hashLockTransaction, networkGenerationHash);
System.out.println("Hash Transaction Hash: " + hashLockTransaction.getHash());
TransactionService transactionService = getTransactionService(type);
Transaction transaction = get(transactionService.announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedTransaction));
Assertions.assertNotNull(transaction);
}
Aggregations