Search in sources :

Example 6 with MosaicNonce

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

the class MosaicDefinitionTransactionTest method shouldGenerateEmbeddedBytes.

@Test
@DisplayName("SerializationEmbeddedBytes")
void shouldGenerateEmbeddedBytes() {
    String expected = "460000000000000068b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b7630000000001904d4100000000000000000a00000000000000000000000203";
    NetworkType networkType = NetworkType.MIJIN_TEST;
    MosaicId mosaicId = new MosaicId(new BigInteger("0"));
    BigInteger fee = BigInteger.ONE;
    MosaicNonce mosaicNonce = MosaicNonce.createFromBigInteger(new BigInteger("0"));
    MosaicFlags mosaicFlags = MosaicFlags.create(false, true, false);
    PublicAccount signature = PublicAccount.createFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b763", NetworkType.MIJIN_TEST);
    TransactionInfo transactionInfo = TransactionInfo.createAggregate(new BigInteger("121855"), 1, "5A3D23889CD1E800015929A9", "3D28C804EDD07D5A728E5C5FFEC01AB07AFA5766AE6997B38526D36015A4D006", "5A0069D83F17CF0001777E55");
    MosaicDefinitionTransaction transaction = MosaicDefinitionTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), mosaicNonce, mosaicId, mosaicFlags, 3, new BlockDuration(10)).maxFee(fee).signature("theSigner").signer(signature).transactionInfo(transactionInfo).build();
    assertEmbeddedSerialization(expected, transaction);
}
Also used : MosaicFlags(io.nem.symbol.sdk.model.mosaic.MosaicFlags) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with MosaicNonce

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

the class MosaicDefinitionTransactionIntegrationTest method aggregateMosaicDefinitionTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void aggregateMosaicDefinitionTransaction(RepositoryType type) {
    MosaicNonce nonce = MosaicNonce.createRandom();
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, this.account.getPublicAccount());
    MosaicDefinitionTransaction mosaicDefinitionTransaction = MosaicDefinitionTransactionFactory.create(getNetworkType(), getDeadline(), nonce, mosaicId, MosaicFlags.create(true, false, true), 4, new BlockDuration(100)).maxFee(maxFee).build();
    MosaicDefinitionTransaction processed = announceAggregateAndValidate(type, mosaicDefinitionTransaction, this.account).getLeft();
    Assertions.assertEquals(mosaicDefinitionTransaction.getMosaicNonce(), processed.getMosaicNonce());
    Assertions.assertEquals(mosaicId, processed.getMosaicId());
}
Also used : BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with MosaicNonce

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

the class AccountRestrictionIntegrationTest method addAndRemoveMosaicRestriction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addAndRemoveMosaicRestriction(RepositoryType type) {
    AccountMosaicRestrictionFlags restrictionFlags = AccountMosaicRestrictionFlags.ALLOW_INCOMING_MOSAIC;
    MosaicNonce nonce = MosaicNonce.createRandom();
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, testAccount.getPublicAccount());
    Assertions.assertNotNull(get(getRepositoryFactory(type).createAccountRepository().getAccountInfo(testAccount.getAddress())));
    if (hasRestriction(type, testAccount, restrictionFlags, mosaicId)) {
        System.out.println("Removing existing mosaic restriction!");
        sendAccountRestrictionMosaic(type, mosaicId, false, restrictionFlags);
        Assertions.assertFalse(hasRestriction(type, testAccount, restrictionFlags, mosaicId));
    }
    System.out.println("Adding mosaic restriction");
    sendAccountRestrictionMosaic(type, mosaicId, true, restrictionFlags);
    Assertions.assertTrue(hasRestriction(type, testAccount, restrictionFlags, mosaicId));
    System.out.println("Removing mosaic restriction");
    sendAccountRestrictionMosaic(type, mosaicId, false, restrictionFlags);
    Assertions.assertFalse(hasRestriction(type, testAccount, restrictionFlags, mosaicId));
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) AccountMosaicRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with MosaicNonce

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

the class MosaicDefinitionTransactionTest method createAMosaicCreationTransactionViaStaticConstructor.

@Test
void createAMosaicCreationTransactionViaStaticConstructor() {
    Account owner = Account.generateNewAccount(NetworkType.MIJIN_TEST);
    Duration epochAdjustment = Duration.ofSeconds(100);
    int nonceNumber = 12345;
    MosaicNonce nonce = MosaicNonce.createFromInteger(nonceNumber);
    MosaicDefinitionTransaction mosaicCreationTx = MosaicDefinitionTransactionFactory.create(NetworkType.MIJIN_TEST, Deadline.create(epochAdjustment), nonce, MosaicId.createFromNonce(nonce, owner.getPublicAccount()), MosaicFlags.create(true, true, true), 4, new BlockDuration(222222)).build();
    System.out.println(ConvertUtils.toHex(BinarySerializationImpl.INSTANCE.serialize(mosaicCreationTx)));
    assertEquals(NetworkType.MIJIN_TEST, mosaicCreationTx.getNetworkType());
    assertEquals(1, (int) mosaicCreationTx.getVersion());
    assertTrue(LocalDateTime.now().isBefore(mosaicCreationTx.getDeadline().getLocalDateTime(epochAdjustment)));
    assertEquals(BigInteger.valueOf(0), mosaicCreationTx.getMaxFee());
    // assertEquals(new BigInteger("0"), mosaicCreationTx.getMosaicId().getId());
    assertTrue(mosaicCreationTx.getMosaicFlags().isSupplyMutable());
    assertTrue(mosaicCreationTx.getMosaicFlags().isTransferable());
    assertTrue(mosaicCreationTx.getMosaicFlags().isRestrictable());
    assertEquals(nonceNumber, mosaicCreationTx.getMosaicNonce().getNonceAsInt());
    assertEquals(4, mosaicCreationTx.getDivisibility());
    assertEquals(new BlockDuration(222222), mosaicCreationTx.getBlockDuration());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) Duration(java.time.Duration) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)9 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)8 BlockDuration (io.nem.symbol.sdk.model.blockchain.BlockDuration)5 Test (org.junit.jupiter.api.Test)4 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)3 BigInteger (java.math.BigInteger)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Address (io.nem.symbol.sdk.model.account.Address)2 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)2 UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 HashLockInfoBuilder (io.nem.symbol.catapult.builders.HashLockInfoBuilder)1 SecretLockInfoBuilder (io.nem.symbol.catapult.builders.SecretLockInfoBuilder)1 Account (io.nem.symbol.sdk.model.account.Account)1 MosaicFlags (io.nem.symbol.sdk.model.mosaic.MosaicFlags)1 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)1 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)1 AccountMosaicRestrictionFlags (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags)1 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)1 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)1