Search in sources :

Example 51 with NamespaceId

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));
}
Also used : MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) BigInteger(java.math.BigInteger) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with NamespaceId

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);
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 53 with NamespaceId

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());
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 54 with NamespaceId

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());
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 55 with NamespaceId

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);
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Aggregations

NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)70 Test (org.junit.jupiter.api.Test)37 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)18 BigInteger (java.math.BigInteger)17 Account (io.nem.symbol.sdk.model.account.Account)15 Address (io.nem.symbol.sdk.model.account.Address)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)14 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)10 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)9 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)8 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)8 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)7 Observable (io.reactivex.Observable)7 List (java.util.List)7 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)6 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)6 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)6 ArrayList (java.util.ArrayList)6