Search in sources :

Example 1 with MosaicNonce

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

the class MosaicDefinitionTransactionIntegrationTest method createMosaic.

private MosaicId createMosaic(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, true, true), 4, new BlockDuration(100)).maxFee(maxFee).build();
    MosaicDefinitionTransaction processed = announceAndValidate(type, this.account, mosaicDefinitionTransaction);
    Assertions.assertEquals(mosaicId, processed.getMosaicId());
    Assertions.assertEquals(mosaicDefinitionTransaction.getMosaicNonce(), processed.getMosaicNonce());
    return mosaicId;
}
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)

Example 2 with MosaicNonce

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

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

the class HashLockInfoTest method constructor.

@Test
void constructor() {
    Optional<String> recordId = Optional.of("abc");
    Address ownerAddress = Address.createFromRawAddress("SDY3NFHBQAPO7ZBII3USHG2UZHJYD7G7FICKIII");
    MosaicId mosaicId = MosaicId.createFromNonce(new MosaicNonce(1), ownerAddress);
    BigInteger amount = BigInteger.ONE;
    BigInteger endHeight = BigInteger.TEN;
    LockStatus status = LockStatus.USED;
    String hash = "DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512F55";
    HashLockInfo info = new HashLockInfo(recordId.orElse(null), 1, ownerAddress, mosaicId, amount, endHeight, status, hash);
    Assertions.assertEquals(recordId, info.getRecordId());
    Assertions.assertEquals(ownerAddress, info.getOwnerAddress());
    Assertions.assertEquals(mosaicId, info.getMosaicId());
    Assertions.assertEquals(amount, info.getAmount());
    Assertions.assertEquals(endHeight, info.getEndHeight());
    Assertions.assertEquals(status, info.getStatus());
    Assertions.assertEquals(hash, info.getHash());
    byte[] serializedState = info.serialize();
    String expectedHex = "010090F1B694E1801EEFE42846E9239B54C9D381FCDF2A04A421E9F49B9E5199FC7601000000000000000A0000000000000001DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512F55";
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(serializedState));
    HashLockInfoBuilder builder = HashLockInfoBuilder.loadFromBinary(SerializationUtils.toDataInput(serializedState));
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(builder.serialize()));
}
Also used : HashLockInfoBuilder(io.nem.symbol.catapult.builders.HashLockInfoBuilder) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) Test(org.junit.jupiter.api.Test)

Example 4 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 5 with MosaicNonce

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

the class MosaicVectorTester method testMosaics.

@ParameterizedTest
@MethodSource("testMosaics")
void testMosaics(NetworkType networkType, long mosaicNonce, String plain, String mosaicHex) {
    Address address = Address.createFromRawAddress(plain);
    Assertions.assertEquals(networkType, address.getNetworkType());
    MosaicNonce nonce = MosaicNonce.createFromBigInteger(BigInteger.valueOf(mosaicNonce));
    MosaicNonce nonce2 = MosaicNonce.createFromInteger((int) mosaicNonce);
    Assertions.assertEquals(mosaicNonce, nonce.getNonceAsLong());
    Assertions.assertEquals(mosaicNonce, nonce2.getNonceAsLong());
    Assertions.assertEquals(nonce2, nonce);
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, address);
    Assertions.assertEquals(mosaicHex, mosaicId.getIdAsHex());
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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