Search in sources :

Example 31 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class MosaicRepositoryIntegrationTest method throwExceptionWhenMosaicDoesNotExists.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void throwExceptionWhenMosaicDoesNotExists(RepositoryType type) {
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(getMosaicRepository(type).getMosaic(new MosaicId("AAAAAE18BE375DA2"))));
    Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id 'AAAAAE18BE375DA2'", exception.getMessage());
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class TestHelper method createMosaic.

protected MosaicId createMosaic(Account account, RepositoryType type, BigInteger initialSupply, String alias) {
    MosaicNonce nonce = MosaicNonce.createRandom();
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, account.getPublicAccount());
    MosaicDefinitionTransaction mosaicDefinitionTransaction = MosaicDefinitionTransactionFactory.create(getNetworkType(), getDeadline(), nonce, mosaicId, MosaicFlags.create(true, true, true), 4, new BlockDuration(100)).maxFee(maxFee).build();
    MosaicDefinitionTransaction validateTransaction = announceAndValidate(type, account, mosaicDefinitionTransaction);
    Assertions.assertEquals(mosaicId, validateTransaction.getMosaicId());
    UnresolvedMosaicId unresolvedMosaicId = mosaicId;
    if (alias != null) {
        NamespaceId rootNamespaceId = createRootNamespace(type, account, alias);
        unresolvedMosaicId = rootNamespaceId;
        MosaicAliasTransaction addressAliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
        announceAggregateAndValidate(type, addressAliasTransaction, account);
    }
    if (initialSupply != null && initialSupply.longValue() > 0) {
        MosaicSupplyChangeTransaction mosaicSupplyChangeTransaction = MosaicSupplyChangeTransactionFactory.create(getNetworkType(), getDeadline(), unresolvedMosaicId, MosaicSupplyChangeActionType.INCREASE, initialSupply).maxFee(maxFee).build();
        announceAndValidate(type, account, mosaicSupplyChangeTransaction);
    }
    return mosaicId;
}
Also used : MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)

Example 33 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId 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 34 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId 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 35 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class MosaicDefinitionTransactionIntegrationTest method aggregateMosaicSupplyChangeTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void aggregateMosaicSupplyChangeTransaction(RepositoryType type) {
    MosaicId mosaicId = createMosaic(type);
    MosaicSupplyChangeTransaction mosaicSupplyChangeTransaction = MosaicSupplyChangeTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, MosaicSupplyChangeActionType.INCREASE, BigInteger.valueOf(12)).maxFee(maxFee).build();
    announceAggregateAndValidate(type, mosaicSupplyChangeTransaction, account);
}
Also used : MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)138 Test (org.junit.jupiter.api.Test)92 Address (io.nem.symbol.sdk.model.account.Address)53 BigInteger (java.math.BigInteger)53 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)23 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)19 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)18 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)17 Account (io.nem.symbol.sdk.model.account.Account)16 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)15 ArrayList (java.util.ArrayList)13 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)12 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)10 MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)10 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)10 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)7 Currency (io.nem.symbol.sdk.model.mosaic.Currency)7 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)7 MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)7