Search in sources :

Example 6 with MosaicAddressRestrictionTransaction

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

use of io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction 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 8 with MosaicAddressRestrictionTransaction

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

the class TransactionServiceTest method mosaicAddressRestrictionTransactionResolveAlias.

@Test
void mosaicAddressRestrictionTransactionResolveAlias() throws ExecutionException, InterruptedException {
    String transactionHash = "aaaa";
    TransactionFactory<MosaicAddressRestrictionTransaction> factory = MosaicAddressRestrictionTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), mosaicNamespace2, BigInteger.TEN, addressNamespace3, BigInteger.ONE).previousRestrictionValue(BigInteger.valueOf(3)).previousRestrictionValue(BigInteger.valueOf(3)).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    MosaicAddressRestrictionTransaction transaction = factory.build();
    simulateStatement(height, 1, 0);
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    MosaicAddressRestrictionTransaction resolvedTransaction = (MosaicAddressRestrictionTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaicId());
    Assertions.assertEquals(address3, resolvedTransaction.getTargetAddress());
}
Also used : MosaicAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Test(org.junit.jupiter.api.Test)

Aggregations

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