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;
}
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;
}
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()));
}
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);
}
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());
}
Aggregations