Search in sources :

Example 1 with NamespaceMetadataTransaction

use of io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction in project nem2-sdk-java by nemtech.

the class TransactionMapperVertxTest method shouldCreateAggregateNamespaceMetadataTransaction.

@Test
void shouldCreateAggregateNamespaceMetadataTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperVertx.loadTransactionInfoDTO("aggregateNamespaceMetadataTransaction.json");
    AggregateTransaction aggregateTransferTransaction = (AggregateTransaction) map(aggregateTransferTransactionDTO);
    validateAggregateTransaction(aggregateTransferTransaction, aggregateTransferTransactionDTO);
    NamespaceMetadataTransaction transaction = (NamespaceMetadataTransaction) aggregateTransferTransaction.getInnerTransactions().get(0);
    Assertions.assertEquals("90E6FF7755A80B6AA935A5C31B6D3D0CFAF82E06BF2B9CC9", transaction.getTargetAddress().encoded(transaction.getNetworkType()));
    Assertions.assertEquals(-1, transaction.getValueSizeDelta());
    Assertions.assertEquals(new BigInteger("11529215046069664444"), transaction.getScopedMetadataKey());
    Assertions.assertArrayEquals(StringEncoder.getBytes("This is the message for this account! 汉字89664"), transaction.getValue());
    Assertions.assertEquals("0003070467832AAA", transaction.getTargetNamespaceId().getIdAsHex());
}
Also used : NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 2 with NamespaceMetadataTransaction

use of io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction in project nem2-sdk-java by nemtech.

the class NamespaceMetadataServiceIntegrationTest method setAndUpdateNamespaceMetadata.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void setAndUpdateNamespaceMetadata(RepositoryType type) {
    // TODO try target != signer
    Account signerAccount = config().getDefaultAccount();
    Account targetAccount = config().getDefaultAccount();
    String namespaceName = "namespace-id-metadata-service-integration-test-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    NamespaceId targetNamespaceId = super.createRootNamespace(type, signerAccount, namespaceName);
    BigInteger key = BigInteger.valueOf(RandomUtils.generateRandomInt(100000));
    String originalMessage = "The original message";
    String newMessage = "The new Message";
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    MetadataRepository metadataRepository = repositoryFactory.createMetadataRepository();
    MetadataTransactionService service = new MetadataTransactionServiceImpl(repositoryFactory);
    NamespaceMetadataTransaction originalTransaction = get(service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), key, originalMessage, signerAccount.getAddress(), targetNamespaceId)).maxFee(maxFee).build();
    announceAggregateAndValidate(type, originalTransaction, signerAccount);
    assertMetadata(targetNamespaceId, key, originalMessage, metadataRepository, signerAccount);
    NamespaceMetadataTransaction updateTransaction = get(service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), key, newMessage, signerAccount.getAddress(), targetNamespaceId)).maxFee(maxFee).build();
    announceAggregateAndValidate(type, updateTransaction, signerAccount);
    assertMetadata(targetNamespaceId, key, newMessage, metadataRepository, signerAccount);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) Account(io.nem.symbol.sdk.model.account.Account) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with NamespaceMetadataTransaction

use of io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction in project nem2-sdk-java by nemtech.

the class NamespaceMetadataIntegrationTest method addMetadataToNamespace.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addMetadataToNamespace(RepositoryType type) {
    String namespaceName = "namespace-for-metadata-integration-test-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    NamespaceId targetNamespaceId = createRootNamespace(type, testAccount, namespaceName);
    System.out.println("Setting metadata " + targetNamespaceId.getIdAsHex());
    String message = "This is the message in the Namespace!";
    BigInteger key = BigInteger.TEN;
    Address targetAddress = testAccount.getAddress();
    MetadataTransactionService metadataTransactionService = new MetadataTransactionServiceImpl(getRepositoryFactory(type));
    Observable<NamespaceMetadataTransactionFactory> namespaceMetadataTransactionFactory = metadataTransactionService.createNamespaceMetadataTransactionFactory(targetAddress, key, message, targetAddress, targetNamespaceId);
    NamespaceMetadataTransaction transaction = get(namespaceMetadataTransactionFactory).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transaction.toAggregate(testAccount.getPublicAccount()))).maxFee(maxFee).build();
    AggregateTransaction announceCorrectly = announceAndValidate(type, testAccount, aggregateTransaction);
    Assertions.assertEquals(testAccount.getPublicAccount(), announceCorrectly.getSigner().get());
    Assertions.assertEquals(1, announceCorrectly.getInnerTransactions().size());
    Assertions.assertEquals(transaction.getType(), announceCorrectly.getInnerTransactions().get(0).getType());
    NamespaceMetadataTransaction processedTransaction = (NamespaceMetadataTransaction) announceCorrectly.getInnerTransactions().get(0);
    // TODO problem comparing namespaces, sometime they are negative big integers
    Assertions.assertEquals(transaction.getTargetNamespaceId().getIdAsHex(), processedTransaction.getTargetNamespaceId().getIdAsHex());
    Assertions.assertEquals(transaction.getValueSizeDelta(), processedTransaction.getValueSizeDelta());
    Assertions.assertEquals(transaction.getScopedMetadataKey(), processedTransaction.getScopedMetadataKey());
    System.out.println("Metadata '" + message + "' stored!");
    sleep(3000);
    List<Metadata> metadata = get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetNamespaceId).metadataType(MetadataType.NAMESPACE))).getData();
    assertMetadata(transaction, metadata);
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetNamespaceId).metadataType(MetadataType.NAMESPACE).scopedMetadataKey(key))).getData());
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetNamespaceId).metadataType(MetadataType.NAMESPACE).targetAddress(targetAddress).scopedMetadataKey(key))).getData());
    Assertions.assertEquals(message, processedTransaction.getValue());
}
Also used : NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with NamespaceMetadataTransaction

use of io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction in project nem2-sdk-java by nemtech.

the class TransactionMapperOkHttpTest method shouldCreateAggregateNamespaceMetadataTransaction.

@Test
void shouldCreateAggregateNamespaceMetadataTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateNamespaceMetadataTransaction.json");
    AggregateTransaction aggregateTransferTransaction = (AggregateTransaction) map(aggregateTransferTransactionDTO);
    validateAggregateTransaction(aggregateTransferTransaction, aggregateTransferTransactionDTO);
    NamespaceMetadataTransaction transaction = (NamespaceMetadataTransaction) aggregateTransferTransaction.getInnerTransactions().get(0);
    Assertions.assertEquals("90E6FF7755A80B6AA935A5C31B6D3D0CFAF82E06BF2B9CC9", transaction.getTargetAddress().encoded(transaction.getNetworkType()));
    Assertions.assertEquals(-1, transaction.getValueSizeDelta());
    Assertions.assertEquals(new BigInteger("11529215046069664444"), transaction.getScopedMetadataKey());
    Assertions.assertArrayEquals(StringEncoder.getBytes("This is the message for this account! 汉字89664"), transaction.getValue());
    Assertions.assertEquals("0003070467832AAA", transaction.getTargetNamespaceId().getIdAsHex());
}
Also used : NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Aggregations

NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)4 BigInteger (java.math.BigInteger)4 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)3 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)1 MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)1 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)1 Account (io.nem.symbol.sdk.model.account.Account)1 Address (io.nem.symbol.sdk.model.account.Address)1 Metadata (io.nem.symbol.sdk.model.metadata.Metadata)1 NamespaceMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory)1 TransactionInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO)1 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)1