use of io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicAddressRestrictionIntegrationTest method createMosaicAddressRestrictionAndValidateEndpoints.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createMosaicAddressRestrictionAndValidateEndpoints(RepositoryType type) {
Account testAccount = helper().createTestAccount(type);
Account testAccount2 = config().getTestAccount2();
// 1) Create a mosaic
MosaicId mosaicId = createMosaic(type, testAccount);
BigInteger restrictionKey = BigInteger.valueOf(22222);
// 2) Create a global restriction on the mosaic
MosaicGlobalRestrictionTransaction mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey, BigInteger.valueOf(20), MosaicRestrictionType.GE).maxFee(maxFee).build();
announceAndValidate(type, testAccount, mosaicGlobalRestrictionTransaction);
sleep(1000);
// 3)Create a new MosaicAddressRestrictionTransaction
BigInteger originalRestrictionValue = BigInteger.valueOf(30);
Address targetAddress = testAccount2.getAddress();
MosaicAddressRestrictionTransaction createTransaction = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey, targetAddress, originalRestrictionValue).maxFee(maxFee).build();
// 4)Announce and validate
MosaicAddressRestrictionTransaction announce1 = announceAggregateAndValidate(type, createTransaction, testAccount).getLeft();
sleep(1000);
assertTransaction(restrictionKey, createTransaction, announce1);
// 5) Validate that endpoints have the data.
sleep(1000);
RestrictionMosaicRepository restrictionRepository = getRepositoryFactory(type).createRestrictionMosaicRepository();
assertMosaicAddressRestriction(restrictionRepository, targetAddress, createTransaction, targetAddress, mosaicId);
// 6) Update the restriction
MosaicAddressRestrictionTransaction updateTransaction = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey, targetAddress, BigInteger.valueOf(40)).previousRestrictionValue(originalRestrictionValue).maxFee(maxFee).build();
// 7) Announce and validate.
MosaicAddressRestrictionTransaction announced = announceAggregateAndValidate(type, updateTransaction, testAccount).getLeft();
sleep(1000);
assertTransaction(restrictionKey, updateTransaction, announced);
assertMosaicAddressRestriction(restrictionRepository, targetAddress, updateTransaction, targetAddress, mosaicId);
}
use of io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicAddressRestrictionIntegrationTest method createMultiAddressRestrictions.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createMultiAddressRestrictions(RepositoryType type) {
Account testAccount = helper().createTestAccount(type);
Account testAccount2 = config().getTestAccount2();
Account testAccount3 = config().getTestAccount3();
// 1) Create a mosaic
MosaicId mosaicId = createMosaic(type, testAccount);
BigInteger restrictionKey1 = BigInteger.valueOf(11);
BigInteger restrictionKey2 = BigInteger.valueOf(22);
// 2) Create a global restriction on the mosaic
MosaicGlobalRestrictionTransaction mosaicGlobalRestrictionTransaction1 = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey1, BigInteger.valueOf(20), MosaicRestrictionType.GE).maxFee(maxFee).build();
// 2) Create a global restriction on the mosaic
MosaicGlobalRestrictionTransaction mosaicGlobalRestrictionTransaction2 = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey2, BigInteger.valueOf(10), MosaicRestrictionType.GT).maxFee(maxFee).build();
announceAndValidate(type, testAccount, mosaicGlobalRestrictionTransaction1);
announceAndValidate(type, testAccount, mosaicGlobalRestrictionTransaction2);
sleep(1000);
// 3)Create a new MosaicAddressRestrictionTransaction
MosaicAddressRestrictionTransaction createTransaction1 = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey1, testAccount2.getAddress(), BigInteger.valueOf(30)).maxFee(maxFee).build();
MosaicAddressRestrictionTransaction createTransaction2 = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey1, testAccount3.getAddress(), BigInteger.valueOf(20)).maxFee(maxFee).build();
MosaicAddressRestrictionTransaction createTransaction3 = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey2, testAccount3.getAddress(), BigInteger.valueOf(70)).maxFee(maxFee).build();
announceAndValidate(type, testAccount, createTransaction1);
announceAndValidate(type, testAccount, createTransaction2);
announceAndValidate(type, testAccount, createTransaction3);
sleep(1000);
RestrictionMosaicRepository restrictionRepository = getRepositoryFactory(type).createRestrictionMosaicRepository();
PaginationStreamer<MosaicRestriction<?>, MosaicRestrictionSearchCriteria> streamer = restrictionRepository.streamer();
List<MosaicRestriction<?>> restrictions = get(streamer.search(new MosaicRestrictionSearchCriteria().targetAddress(testAccount.getAddress())).toList().toObservable());
Assertions.assertEquals(1, restrictions.size());
}
use of io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicRestrictionTransactionServiceTest method createMosaicAddressRestrictionTransactionFactoryWhenDoesNotExist.
@Test
void createMosaicAddressRestrictionTransactionFactoryWhenDoesNotExist() throws Exception {
MosaicAddressRestrictionTransaction transaction = service.createMosaicAddressRestrictionTransactionFactory(mosaicId2, restrictionKey, account1.getAddress(), BigInteger.valueOf(40)).toFuture().get().build();
Assertions.assertEquals(networkType, transaction.getNetworkType());
Assertions.assertEquals(mosaicId2, transaction.getMosaicId());
Assertions.assertEquals(restrictionKey, transaction.getRestrictionKey());
Assertions.assertEquals(account1.getAddress(), transaction.getTargetAddress());
Assertions.assertEquals(BigInteger.valueOf(40), transaction.getNewRestrictionValue());
Assertions.assertEquals(new BigInteger("FFFFFFFFFFFFFFFF", 16), transaction.getPreviousRestrictionValue());
Assertions.assertEquals(networkType, transaction.getNetworkType());
}
use of io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicRestrictionTransactionServiceTest method createMosaicAddressRestrictionTransactionFactoryWhenExist.
@Test
void createMosaicAddressRestrictionTransactionFactoryWhenExist() throws Exception {
MosaicAddressRestrictionTransaction transaction = service.createMosaicAddressRestrictionTransactionFactory(mosaicId1, restrictionKey, account1.getAddress(), BigInteger.valueOf(40)).toFuture().get().build();
Assertions.assertEquals(networkType, transaction.getNetworkType());
Assertions.assertEquals(mosaicId1, transaction.getMosaicId());
Assertions.assertEquals(restrictionKey, transaction.getRestrictionKey());
Assertions.assertEquals(account1.getAddress(), transaction.getTargetAddress());
Assertions.assertEquals(BigInteger.valueOf(40), transaction.getNewRestrictionValue());
Assertions.assertEquals(BigInteger.valueOf(30), transaction.getPreviousRestrictionValue());
Assertions.assertEquals(networkType, transaction.getNetworkType());
}
use of io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction in project nem2-sdk-java by nemtech.
the class MosaicRestrictionTransactionServiceTest method createMosaicAddressRestrictionTransactionFactoryWhenExistUsingAlias.
@Test
void createMosaicAddressRestrictionTransactionFactoryWhenExistUsingAlias() throws Exception {
MosaicAddressRestrictionTransaction transaction = service.createMosaicAddressRestrictionTransactionFactory(mosaicAlias1, restrictionKey, accountAlias1, BigInteger.valueOf(40)).toFuture().get().build();
Assertions.assertEquals(networkType, transaction.getNetworkType());
Assertions.assertEquals(mosaicAlias1, transaction.getMosaicId());
Assertions.assertEquals(restrictionKey, transaction.getRestrictionKey());
Assertions.assertEquals(accountAlias1, transaction.getTargetAddress());
Assertions.assertEquals(BigInteger.valueOf(40), transaction.getNewRestrictionValue());
Assertions.assertEquals(BigInteger.valueOf(30), transaction.getPreviousRestrictionValue());
Assertions.assertEquals(networkType, transaction.getNetworkType());
}
Aggregations