Search in sources :

Example 11 with RestrictionMosaicRepository

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());
}
Also used : MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) MosaicRestrictionTransactionService(io.nem.symbol.sdk.api.MosaicRestrictionTransactionService) MosaicAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) BigInteger(java.math.BigInteger) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with RestrictionMosaicRepository

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());
    });
}
Also used : MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with RestrictionMosaicRepository

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());
}
Also used : RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) Test(org.junit.jupiter.api.Test)

Aggregations

RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 EnumSource (org.junit.jupiter.params.provider.EnumSource)10 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)8 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)7 MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)6 MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)6 BigInteger (java.math.BigInteger)6 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)4 MosaicAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction)4 MosaicRestrictionType (io.nem.symbol.sdk.model.transaction.MosaicRestrictionType)4 MosaicRestrictionTransactionService (io.nem.symbol.sdk.api.MosaicRestrictionTransactionService)3 Address (io.nem.symbol.sdk.model.account.Address)3 Account (io.nem.symbol.sdk.model.account.Account)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 MosaicRestrictionEntryType (io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType)2 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)1 MosaicAddressRestriction (io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction)1 MosaicGlobalRestriction (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1