Search in sources :

Example 1 with MosaicGlobalRestrictionTransaction

use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction 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);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) Address(io.nem.symbol.sdk.model.account.Address) MosaicAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) 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 2 with MosaicGlobalRestrictionTransaction

use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction 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());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) MosaicAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) 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 3 with MosaicGlobalRestrictionTransaction

use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction in project nem2-sdk-java by nemtech.

the class MosaicRestrictionTransactionServiceTest method createMosaicGlobalRestrictionTransactionFactoryWhenExist.

@Test
void createMosaicGlobalRestrictionTransactionFactoryWhenExist() throws Exception {
    MosaicGlobalRestrictionTransaction transaction = service.createMosaicGlobalRestrictionTransactionFactory(mosaicId1, restrictionKey, BigInteger.valueOf(30), MosaicRestrictionType.GE).toFuture().get().build();
    Assertions.assertEquals(networkType, transaction.getNetworkType());
    Assertions.assertEquals(mosaicId1, 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.valueOf(20), transaction.getPreviousRestrictionValue());
    Assertions.assertEquals(MosaicRestrictionType.EQ, transaction.getPreviousRestrictionType());
    Assertions.assertEquals(networkType, transaction.getNetworkType());
}
Also used : MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 4 with MosaicGlobalRestrictionTransaction

use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction in project nem2-sdk-java by nemtech.

the class MosaicRestrictionTransactionServiceTest method createMosaicGlobalRestrictionTransactionFactoryWhenExistUsingAlias.

@Test
void createMosaicGlobalRestrictionTransactionFactoryWhenExistUsingAlias() throws Exception {
    MosaicGlobalRestrictionTransaction transaction = service.createMosaicGlobalRestrictionTransactionFactory(mosaicAlias1, restrictionKey, BigInteger.valueOf(30), MosaicRestrictionType.GE).toFuture().get().build();
    Assertions.assertEquals(networkType, transaction.getNetworkType());
    Assertions.assertEquals(mosaicAlias1, 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.valueOf(20), transaction.getPreviousRestrictionValue());
    Assertions.assertEquals(MosaicRestrictionType.EQ, transaction.getPreviousRestrictionType());
    Assertions.assertEquals(networkType, transaction.getNetworkType());
}
Also used : MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 5 with MosaicGlobalRestrictionTransaction

use of io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction 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)

Aggregations

MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)10 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)9 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)6 BigInteger (java.math.BigInteger)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 EnumSource (org.junit.jupiter.params.provider.EnumSource)6 MosaicAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction)4 MosaicRestrictionType (io.nem.symbol.sdk.model.transaction.MosaicRestrictionType)4 Test (org.junit.jupiter.api.Test)4 MosaicRestrictionTransactionService (io.nem.symbol.sdk.api.MosaicRestrictionTransactionService)3 Account (io.nem.symbol.sdk.model.account.Account)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)1 Address (io.nem.symbol.sdk.model.account.Address)1 MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)1 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)1 MosaicGlobalRestrictionTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory)1