Search in sources :

Example 6 with RestrictionMosaicRepository

use of io.nem.symbol.sdk.api.RestrictionMosaicRepository in project nem2-sdk-java by nemtech.

the class MosaicAddressRestrictionIntegrationTest method getMosaicAddressRestrictionWhenMosaicDoesNotExist.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicAddressRestrictionWhenMosaicDoesNotExist(RepositoryType type) {
    RestrictionMosaicRepository repository = getRepositoryFactory(type).createRestrictionMosaicRepository();
    Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
    Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().mosaicId(new MosaicId(BigInteger.valueOf(888888))).targetAddress(address).entryType(MosaicRestrictionEntryType.ADDRESS)));
    Assertions.assertTrue(page.getData().isEmpty());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with RestrictionMosaicRepository

use of io.nem.symbol.sdk.api.RestrictionMosaicRepository in project nem2-sdk-java by nemtech.

the class MosaicGlobalRestrictionIntegrationTest method createMosaicGlobalRestrictionAndValidateEndpoints.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void createMosaicGlobalRestrictionAndValidateEndpoints(RepositoryType type) {
    // 1) Create a new mosaic
    String mosaicAliasName = "MosaicRestrictionServiceIT_createMosaicGlobalRestriction".toLowerCase() + RandomUtils.generateRandomInt(100000);
    NamespaceId mosaicAlias = NamespaceId.createFromName(mosaicAliasName);
    MosaicId mosaicId = createMosaic(testAccount, type, null, mosaicAliasName);
    // 2) Create a restriction on the mosaic
    BigInteger originalValue = BigInteger.valueOf(20);
    MosaicRestrictionType originalRestrictionType = MosaicRestrictionType.GE;
    MosaicGlobalRestrictionTransaction createTransaction = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), 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, getMosaicRestriction(mosaicId, restrictionRepository));
    // 6) Modifying the restriction by sending a new transaction with the previous values.
    MosaicGlobalRestrictionTransaction updateTransaction = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey, BigInteger.valueOf(40), MosaicRestrictionType.EQ).previousRestrictionType(originalRestrictionType).previousRestrictionValue(originalValue).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, getMosaicRestriction(mosaicId, restrictionRepository));
}
Also used : MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) 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 8 with RestrictionMosaicRepository

use of io.nem.symbol.sdk.api.RestrictionMosaicRepository 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());
}
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) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with RestrictionMosaicRepository

use of io.nem.symbol.sdk.api.RestrictionMosaicRepository in project nem2-sdk-java by nemtech.

the class MosaicRestrictionServiceIntegrationTest method getMosaicGlobalRestrictionWhenMosaicDoesNotExist.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicGlobalRestrictionWhenMosaicDoesNotExist(RepositoryType type) {
    RestrictionMosaicRepository repository = getRepositoryFactory(type).createRestrictionMosaicRepository();
    Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
    Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().mosaicId(new MosaicId(BigInteger.valueOf(888888))).targetAddress(address).entryType(MosaicRestrictionEntryType.GLOBAL)));
    Assertions.assertTrue(page.getData().isEmpty());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with RestrictionMosaicRepository

use of io.nem.symbol.sdk.api.RestrictionMosaicRepository 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));
}
Also used : MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) MosaicRestrictionTransactionService(io.nem.symbol.sdk.api.MosaicRestrictionTransactionService) 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) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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