use of io.nem.symbol.sdk.api.RestrictionMosaicRepository 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.api.RestrictionMosaicRepository in project nem2-sdk-java by nemtech.
the class RestrictionMosaicRepositoryIntegrationTest method searchGlobalRestriction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchGlobalRestriction(RepositoryType type) {
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
RestrictionMosaicRepository repository = repositoryFactory.createRestrictionMosaicRepository();
MosaicRestrictionEntryType entryType = MosaicRestrictionEntryType.GLOBAL;
Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().entryType(entryType)));
System.out.println(page.getData().size());
page.getData().forEach(restriction -> {
Assertions.assertTrue(restriction instanceof MosaicGlobalRestriction);
Assertions.assertEquals(entryType, restriction.getEntryType());
Assertions.assertNotNull(restriction.getMosaicId());
Assertions.assertNotNull(restriction.getCompositeHash());
Assertions.assertFalse(restriction.getRestrictions().isEmpty());
});
}
use of io.nem.symbol.sdk.api.RestrictionMosaicRepository in project nem2-sdk-java by nemtech.
the class StateProofServiceTest method mosaicRestriction.
@Test
void mosaicRestriction() throws Exception {
RestrictionMosaicRepository repository = mock(RestrictionMosaicRepository.class);
when(factory.createRestrictionMosaicRepository()).thenReturn(repository);
String id = "hash";
MosaicRestriction<?> state = Mockito.mock(MosaicRestriction.class);
when(state.getCompositeHash()).thenReturn(id);
when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
when(repository.getMosaicRestrictions(eq(id))).thenReturn(Observable.just(state));
when(repository.getMosaicRestrictionsMerkle(eq(id))).thenReturn(Observable.just(tree));
StateMerkleProof<MosaicRestriction<?>> proof = service.mosaicRestriction(id).toFuture().get();
Assertions.assertTrue(proof.isValid());
Assertions.assertEquals(state, proof.getState());
}
Aggregations