Search in sources :

Example 1 with AccountMetadataTransaction

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

the class TransactionMapperVertxTest method shouldCreateAggregateAccountMetadataTransaction.

@Test
void shouldCreateAggregateAccountMetadataTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperVertx.loadTransactionInfoDTO("aggregateAccountMetadataTransaction.json");
    AggregateTransaction aggregateTransferTransaction = (AggregateTransaction) map(aggregateTransferTransactionDTO);
    validateAggregateTransaction(aggregateTransferTransaction, aggregateTransferTransactionDTO);
    AccountMetadataTransaction transaction = (AccountMetadataTransaction) 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());
}
Also used : AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) 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 AccountMetadataTransaction

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

the class AccountMetadataIntegrationTest method addMetadataToAccount.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addMetadataToAccount(RepositoryType type) {
    BigInteger key = SerializationUtils.toUnsignedBigInteger(RandomUtils.generateRandomInt(100000) + Long.MAX_VALUE);
    Assertions.assertTrue(key.compareTo(BigInteger.ZERO) > 0);
    System.out.println("Key: " + key);
    String message = "This is the message for this account! 汉字" + key;
    System.out.println("Storing message '" + message + "' in account metadata " + testAccount.getAddress().plain());
    AccountMetadataTransaction transaction = AccountMetadataTransactionFactory.create(getNetworkType(), getDeadline(), testAccount.getAddress(), key, StringEncoder.getBytes(message)).maxFee(maxFee).build();
    AccountMetadataTransaction processedTransaction = announceAggregateAndValidate(type, transaction, testAccount).getLeft();
    Assertions.assertEquals(transaction.getValueSizeDelta(), processedTransaction.getValueSizeDelta());
    Assertions.assertEquals(transaction.getScopedMetadataKey(), processedTransaction.getScopedMetadataKey());
    sleep(1000);
    Metadata metadata = assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().metadataType(MetadataType.ACCOUNT).sourceAddress(testAccount.getAddress()))).getData());
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().metadataType(MetadataType.ACCOUNT).sourceAddress(testAccount.getAddress()).scopedMetadataKey(metadata.getScopedMetadataKey()))).getData());
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().metadataType(MetadataType.ACCOUNT).sourceAddress(testAccount.getAddress()).targetAddress(testAccount.getAddress()).scopedMetadataKey(metadata.getScopedMetadataKey()))).getData());
    Assertions.assertArrayEquals(StringEncoder.getBytes(message), processedTransaction.getValue());
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with AccountMetadataTransaction

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

the class TransactionMapperOkHttpTest method shouldCreateAggregateAccountMetadataTransaction.

@Test
void shouldCreateAggregateAccountMetadataTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateAccountMetadataTransaction.json");
    AggregateTransaction aggregateTransferTransaction = (AggregateTransaction) map(aggregateTransferTransactionDTO);
    validateAggregateTransaction(aggregateTransferTransaction, aggregateTransferTransactionDTO);
    AccountMetadataTransaction transaction = (AccountMetadataTransaction) 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());
}
Also used : AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) 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)

Example 4 with AccountMetadataTransaction

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

the class AccountMetadataServiceIntegrationTest method setAndUpdateAccountMetadata.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void setAndUpdateAccountMetadata(RepositoryType type) {
    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);
    AccountMetadataTransaction originalTransaction = get(service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), key, originalMessage, signerAccount.getAddress())).maxFee(maxFee).build();
    announceAggregateAndValidate(type, originalTransaction, signerAccount);
    sleep(1000);
    assertMetadata(key, originalMessage, metadataRepository);
    AccountMetadataTransaction updateTransaction = get(service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), key, newMessage, signerAccount.getAddress())).maxFee(maxFee).build();
    announceAggregateAndValidate(type, updateTransaction, signerAccount);
    sleep(1000);
    assertMetadata(key, newMessage, metadataRepository);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) BigInteger(java.math.BigInteger) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)4 BigInteger (java.math.BigInteger)4 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)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 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)1 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)1 Metadata (io.nem.symbol.sdk.model.metadata.Metadata)1 TransactionInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO)1 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)1