use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicRestrictionServiceIntegrationTest method createUpdateMosaicAddressRestrictionTransactionFactory.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createUpdateMosaicAddressRestrictionTransactionFactory(RepositoryType type) {
// 1) Create a new mosaic
MosaicId mosaicId = createMosaic(testAccount, type, null, null);
// 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(mosaicId, 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(mosaicId, 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(mosaicId, 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.transaction.MosaicGlobalRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicRestrictionServiceIntegrationTest method createUpdateMosaicGlobalRestrictionTransactionFactory.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createUpdateMosaicGlobalRestrictionTransactionFactory(RepositoryType type) {
// 1) Create a new mosaic
MosaicId mosaicId = createMosaic(testAccount, type, null, null);
// 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(mosaicId, 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) Modifying the restriction by sending a new transaction with the previous values.
MosaicGlobalRestrictionTransaction updateTransaction = get(restrictionService.createMosaicGlobalRestrictionTransactionFactory(mosaicId, restrictionKey, BigInteger.valueOf(40), MosaicRestrictionType.EQ)).maxFee(maxFee).build();
// 7) Announcing the update restriction transaction and checking the processed one.
MosaicGlobalRestrictionTransaction processedUpdateTransaction = announceAndValidate(type, testAccount, updateTransaction);
assertTransaction(updateTransaction, processedUpdateTransaction);
// 8) Validating that the endpoints show the new value and type.
assertMosaicGlobalRestriction(updateTransaction, getMosaicGlobalRestriction(restrictionRepository, mosaicId));
}
use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction 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.transaction.MosaicGlobalRestrictionTransaction in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method mosaicGlobalRestrictionTransactionResolveAlias.
@Test
void mosaicGlobalRestrictionTransactionResolveAlias() throws ExecutionException, InterruptedException {
String transactionHash = "aaaa";
MosaicGlobalRestrictionTransactionFactory mosaicGlobalRestrictionTransactionFactory = MosaicGlobalRestrictionTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), mosaicNamespace2, BigInteger.TEN, BigInteger.ONE, MosaicRestrictionType.GT);
mosaicGlobalRestrictionTransactionFactory.referenceMosaicId(mosaicNamespace3);
mosaicGlobalRestrictionTransactionFactory.previousRestrictionType(MosaicRestrictionType.EQ);
mosaicGlobalRestrictionTransactionFactory.previousRestrictionValue(BigInteger.valueOf(3));
TransactionFactory<MosaicGlobalRestrictionTransaction> factory = mosaicGlobalRestrictionTransactionFactory.transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
MosaicGlobalRestrictionTransaction transaction = factory.build();
simulateStatement(height, 1, 0);
List<String> hashes = Collections.singletonList(transactionHash);
Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
MosaicGlobalRestrictionTransaction resolvedTransaction = (MosaicGlobalRestrictionTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaicId());
Assertions.assertEquals(mosaicId3, resolvedTransaction.getReferenceMosaicId());
}
use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicRestrictionTransactionServiceTest method createMosaicGlobalRestrictionTransactionFactoryWhenDoesNotExist.
@Test
void createMosaicGlobalRestrictionTransactionFactoryWhenDoesNotExist() throws Exception {
MosaicGlobalRestrictionTransaction transaction = service.createMosaicGlobalRestrictionTransactionFactory(mosaicIdNotFound, restrictionKey, BigInteger.valueOf(30), MosaicRestrictionType.GE).toFuture().get().build();
Assertions.assertEquals(networkType, transaction.getNetworkType());
Assertions.assertEquals(mosaicIdNotFound, transaction.getMosaicId());
Assertions.assertEquals(restrictionKey, transaction.getRestrictionKey());
Assertions.assertEquals(new MosaicId(BigInteger.ZERO), transaction.getReferenceMosaicId());
Assertions.assertEquals(BigInteger.valueOf(30), transaction.getNewRestrictionValue());
Assertions.assertEquals(MosaicRestrictionType.GE, transaction.getNewRestrictionType());
Assertions.assertEquals(BigInteger.ZERO, transaction.getPreviousRestrictionValue());
Assertions.assertEquals(MosaicRestrictionType.NONE, transaction.getPreviousRestrictionType());
Assertions.assertEquals(networkType, transaction.getNetworkType());
}
Aggregations