use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class MosaicGlobalRestrictionIntegrationTest method createMosaicGlobalRestrictionAndValidateEndpoints.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createMosaicGlobalRestrictionAndValidateEndpoints(RepositoryType type) {
// 1) Create a new mosaic
String mosaicAliasName = "MosaicRestrictionServiceIT_createMosaicGlobalRestriction".toLowerCase() + RandomUtils.generateRandomInt(100000);
NamespaceId mosaicAlias = NamespaceId.createFromName(mosaicAliasName);
MosaicId mosaicId = createMosaic(testAccount, type, null, mosaicAliasName);
// 2) Create a restriction on the mosaic
BigInteger originalValue = BigInteger.valueOf(20);
MosaicRestrictionType originalRestrictionType = MosaicRestrictionType.GE;
MosaicGlobalRestrictionTransaction createTransaction = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), 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, getMosaicRestriction(mosaicId, restrictionRepository));
// 6) Modifying the restriction by sending a new transaction with the previous values.
MosaicGlobalRestrictionTransaction updateTransaction = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey, BigInteger.valueOf(40), MosaicRestrictionType.EQ).previousRestrictionType(originalRestrictionType).previousRestrictionValue(originalValue).maxFee(maxFee).build();
// 7) Announcing the update restriction transaction and checking the processed one.
MosaicGlobalRestrictionTransaction processedUpdateTransaction = announceAndValidate(type, testAccount, updateTransaction);
assertTransaction(updateTransaction, processedUpdateTransaction);
// 8) Validating that the endpoints show the new value and type.
assertMosaicGlobalRestriction(updateTransaction, getMosaicRestriction(mosaicId, restrictionRepository));
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serializationNamespaceRecipient.
@Test
@DisplayName("Serialization-public-namespace-recipient")
void serializationNamespaceRecipient() {
String expected = "C4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001905441000000000000000001000000000000009151776168D24257D80000000000000000000000000000001400010000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
NamespaceId recipient = NamespaceId.createFromName("nem.owner");
Assertions.assertEquals("D85742D268617751", recipient.getIdAsHex());
Assertions.assertEquals("9151776168D24257D8000000000000000000000000000000", recipient.encoded(networkType));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), recipient, Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message 漢字")).build();
Assertions.assertEquals(recipient.encoded(networkType), transaction.getRecipient().encoded(networkType));
assertSerialization(expected, transaction);
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class NamespaceRegistrationTransactionTest method createANamespaceCreationRootNamespaceTransactionViaStaticConstructor.
@Test
void createANamespaceCreationRootNamespaceTransactionViaStaticConstructor() {
NamespaceId namespaceId = NamespaceId.createFromName("root-test-namespace");
NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(networkType, new Deadline(BigInteger.ONE), "root-test-namespace", BigInteger.valueOf(1000)).build();
assertEquals("00000000E803000000000000CFCBE72D994BE69B0013726F6F742D746573742D6E616D657370616365", ConvertUtils.toHex(namespaceRegistrationTransaction.serialize()).toUpperCase().substring(248));
SignedTransaction signedTransaction = namespaceRegistrationTransaction.signWith(testAccount, generationHash);
assertEquals("00000000E803000000000000CFCBE72D994BE69B0013726F6F742D746573742D6E616D657370616365", signedTransaction.getPayload().substring(248));
assertEquals(networkType, namespaceRegistrationTransaction.getNetworkType());
assertEquals(1, (int) namespaceRegistrationTransaction.getVersion());
assertEquals(BigInteger.valueOf(0), namespaceRegistrationTransaction.getMaxFee());
assertEquals("root-test-namespace", namespaceRegistrationTransaction.getNamespaceName());
assertEquals(NamespaceRegistrationType.ROOT_NAMESPACE, namespaceRegistrationTransaction.getNamespaceRegistrationType());
assertEquals(BigInteger.valueOf(1000), namespaceRegistrationTransaction.getDuration().get());
assertEquals(namespaceId.getIdAsHex(), namespaceRegistrationTransaction.getNamespaceId().getIdAsHex());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class NamespaceMetadataTransactionTest method shouldBuild.
@Test
void shouldBuild() {
NamespaceId namespaceId = NamespaceId.createFromId(BigInteger.valueOf(1000));
NamespaceMetadataTransaction transaction = NamespaceMetadataTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), account.getPublicAccount().getAddress(), namespaceId, BigInteger.TEN, StringEncoder.getBytes("ABC123")).valueSizeDelta(10).build();
assertEquals("ABC123", StringEncoder.getString(transaction.getValue()));
assertEquals(namespaceId, transaction.getTargetNamespaceId());
assertEquals(NetworkType.MIJIN_TEST, transaction.getNetworkType());
assertEquals(10, transaction.getValueSizeDelta());
assertEquals(BigInteger.TEN, transaction.getScopedMetadataKey());
assertEquals(account.getAddress(), transaction.getTargetAddress());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class NamespaceMetadataTransactionTest method shouldGenerateBytes.
@Test
void shouldGenerateBytes() {
NamespaceId namespaceId = NamespaceId.createFromId(BigInteger.valueOf(1000));
NamespaceMetadataTransaction transaction = NamespaceMetadataTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), account.getAddress(), namespaceId, BigInteger.TEN, StringEncoder.getBytes("ABC123")).valueSizeDelta(10).signer(account.getPublicAccount()).build();
String expectedHash = "B20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E60000000001904443000000000000000001000000000000009083025FF3A8AB5AD104631FB370F290004952CD1FDDC4C90A00000000000000E8030000000000000A000600414243313233";
assertSerialization(expectedHash, transaction);
String expectedEmbeddedHash = "6200000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E600000000019044439083025FF3A8AB5AD104631FB370F290004952CD1FDDC4C90A00000000000000E8030000000000000A000600414243313233";
assertEmbeddedSerialization(expectedEmbeddedHash, transaction);
}
Aggregations