use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class TransactionServiceIntegrationTest method transferUsingAliases.
private TransferTransaction transferUsingAliases(Account sender, RepositoryType type, String mosaicAlias, String recipientAlias, BigInteger amount) {
NamespaceId recipientNamespace = NamespaceId.createFromName(recipientAlias);
NamespaceId mosaicNamespace = NamespaceId.createFromName(mosaicAlias);
System.out.println("Sending " + amount + " Mosaic to: " + mosaicAlias);
TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipientNamespace, Collections.singletonList(new Mosaic(mosaicNamespace, amount))).message(new PlainMessage("E2ETest:TransactionServiceIntegrationTest"));
factory.maxFee(maxFee);
TransferTransaction transferTransaction = factory.build();
Assertions.assertTrue(transferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
Assertions.assertTrue(transferTransaction.getRecipient() instanceof NamespaceId);
TransferTransaction processedTransferTransaction = announceAndValidate(type, sender, transferTransaction);
Assertions.assertEquals(amount, processedTransferTransaction.getMosaics().get(0).getAmount());
System.out.println(toJson(processedTransferTransaction));
Assertions.assertTrue(processedTransferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
Assertions.assertTrue(processedTransferTransaction.getRecipient() instanceof NamespaceId);
return processedTransferTransaction;
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class MosaicRestrictionServiceIntegrationTest method createUpdateMosaicAddressRestrictionTransactionFactoryUsingAlias.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createUpdateMosaicAddressRestrictionTransactionFactoryUsingAlias(RepositoryType type) {
// 1) Create mosaic and alias
String mosaicAliasName = "createUpdateMosaicAddressRestrictionAlias".toLowerCase() + RandomUtils.generateRandomInt(100000);
NamespaceId mosaicAlias = NamespaceId.createFromName(mosaicAliasName);
MosaicId mosaicId = createMosaic(testAccount, type, null, mosaicAliasName);
// 2) Create a restriction on the mosaic
MosaicRestrictionTransactionService restrictionService = getMosaicRestrictionTransactionService(type);
BigInteger originalValue = BigInteger.valueOf(20);
MosaicRestrictionType originalRestrictionType = MosaicRestrictionType.GE;
MosaicGlobalRestrictionTransaction createTransaction = get(restrictionService.createMosaicGlobalRestrictionTransactionFactory(mosaicAlias, restrictionKey, originalValue, originalRestrictionType)).maxFee(maxFee).build();
// 3) Announce the create restriction transaction
MosaicGlobalRestrictionTransaction processedCreateTransaction = announceAndValidate(type, testAccount, createTransaction);
// 4) Validate that the received processedCreateTransaction and the create transaction are the
// same
assertTransaction(createTransaction, processedCreateTransaction);
// 5) Validate the data from the endpoints
RestrictionMosaicRepository restrictionRepository = getRepositoryFactory(type).createRestrictionMosaicRepository();
assertMosaicGlobalRestriction(createTransaction, getMosaicGlobalRestriction(restrictionRepository, mosaicId));
// 6) Create the restriction by sending a new transaction
MosaicAddressRestrictionTransaction createAddressTransaction = get(restrictionService.createMosaicAddressRestrictionTransactionFactory(mosaicAlias, restrictionKey, testAccount.getAddress(), BigInteger.valueOf(40))).maxFee(maxFee).build();
announceAndValidate(type, testAccount, createAddressTransaction);
// 7) Announcing the update restriction transaction and checking the processed one.
MosaicAddressRestrictionTransaction updateAddressTransaction = get(restrictionService.createMosaicAddressRestrictionTransactionFactory(mosaicAlias, restrictionKey, testAccount.getAddress(), BigInteger.valueOf(50))).maxFee(maxFee).build();
MosaicAddressRestrictionTransaction finalTransaction = announceAndValidate(type, testAccount, updateAddressTransaction);
Assertions.assertEquals(BigInteger.valueOf(50), finalTransaction.getNewRestrictionValue());
Assertions.assertEquals(BigInteger.valueOf(40), finalTransaction.getPreviousRestrictionValue());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class SerializationUtilsTest method toUnresolvedAddressFromNamespaceId.
@Test
void toUnresolvedAddressFromNamespaceId() {
NamespaceId namespaceId = NamespaceId.createFromName("this.currency");
Assertions.assertEquals("BDED68013AAEE068", namespaceId.getIdAsHex());
Assertions.assertEquals("9168E0AE3A0168EDBD000000000000000000000000000000", ConvertUtils.toHex(SerializationUtils.fromUnresolvedAddressToByteBuffer(namespaceId, NetworkType.MIJIN_TEST).array()));
Assertions.assertEquals("6968E0AE3A0168EDBD000000000000000000000000000000", ConvertUtils.toHex(SerializationUtils.fromUnresolvedAddressToByteBuffer(namespaceId, NetworkType.MAIN_NET).array()));
Assertions.assertEquals("6168E0AE3A0168EDBD000000000000000000000000000000", ConvertUtils.toHex(SerializationUtils.fromUnresolvedAddressToByteBuffer(namespaceId, NetworkType.MIJIN).array()));
Assertions.assertEquals("6968E0AE3A0168EDBD000000000000000000000000000000", ConvertUtils.toHex(SerializationUtils.fromUnresolvedAddressToByteBuffer(namespaceId, NetworkType.MAIN_NET).array()));
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId 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());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class CurrencyTest method createMosaicWithDecimals.
@Test
void createMosaicWithDecimals() {
NamespaceId namespaceId = NamespaceId.createFromName("mycurrency");
Currency currency = new CurrencyBuilder(namespaceId, 3).withSupplyMutable(false).withTransferable(true).build();
Mosaic mosaic1 = currency.createRelative(15.2);
Mosaic mosaic2 = currency.createRelative(BigDecimal.valueOf(15.2));
Mosaic mosaic3 = currency.createAbsolute(15200);
Mosaic mosaic4 = currency.createRelative(15.2004);
Mosaic mosaic5 = currency.createRelative(BigDecimal.valueOf(15.2004));
Assertions.assertEquals(mosaic1, mosaic2);
Assertions.assertEquals(mosaic1, mosaic3);
Assertions.assertEquals(mosaic1, mosaic4);
Assertions.assertEquals(mosaic1, mosaic5);
}
Aggregations