Search in sources :

Example 1 with MosaicMetadataTransaction

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

the class TransactionMapperVertxTest method shouldCreateAggregateMosaicMetadataTransaction.

@Test
void shouldCreateAggregateMosaicMetadataTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicMetadataTransaction.json");
    AggregateTransaction aggregateTransferTransaction = (AggregateTransaction) map(aggregateTransferTransactionDTO);
    validateAggregateTransaction(aggregateTransferTransaction, aggregateTransferTransactionDTO);
    MosaicMetadataTransaction transaction = (MosaicMetadataTransaction) aggregateTransferTransaction.getInnerTransactions().get(0);
    Assertions.assertEquals("9103B60AAF27626883000000000000000000000000000000", 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.getTargetMosaicId().getIdAsHex());
}
Also used : TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 2 with MosaicMetadataTransaction

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

the class TransactionMapperOkHttpTest method shouldCreateAggregateMosaicMetadataTransaction.

@Test
void shouldCreateAggregateMosaicMetadataTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicMetadataTransaction.json");
    AggregateTransaction aggregateTransferTransaction = (AggregateTransaction) map(aggregateTransferTransactionDTO);
    validateAggregateTransaction(aggregateTransferTransaction, aggregateTransferTransactionDTO);
    MosaicMetadataTransaction transaction = (MosaicMetadataTransaction) aggregateTransferTransaction.getInnerTransactions().get(0);
    Assertions.assertEquals("9103B60AAF27626883000000000000000000000000000000", 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.getTargetMosaicId().getIdAsHex());
}
Also used : TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 3 with MosaicMetadataTransaction

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

the class TransactionServiceTest method mosaicMetadataTransactionResolveAlias.

@Test
void mosaicMetadataTransactionResolveAlias() throws ExecutionException, InterruptedException {
    String transactionHash = "aaaa";
    TransactionFactory<MosaicMetadataTransaction> factory = MosaicMetadataTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Account.generateNewAccount(networkType).getAddress(), mosaicNamespace2, BigInteger.TEN, StringEncoder.getBytes("Value")).transactionInfo(TransactionInfo.create(height, 4, "ABC", transactionHash, ""));
    MosaicMetadataTransaction transaction = factory.build();
    simulateStatement(height, 5, 0);
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    MosaicMetadataTransaction resolvedTransaction = (MosaicMetadataTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(mosaicId2, resolvedTransaction.getTargetMosaicId());
}
Also used : Deadline(io.nem.symbol.sdk.model.transaction.Deadline) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Test(org.junit.jupiter.api.Test)

Example 4 with MosaicMetadataTransaction

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

the class MosaicMetadataIntegrationTest method addMetadataToMosaic.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addMetadataToMosaic(RepositoryType type) {
    MosaicId targetMosaicId = createMosaic(type);
    NamespaceId alias = setMosaicAlias(type, targetMosaicId, "mosaicalias" + targetMosaicId.getIdAsHex().toLowerCase());
    String message = "This is the message in the mosaic!";
    BigInteger key = BigInteger.TEN;
    MosaicMetadataTransaction transaction = MosaicMetadataTransactionFactory.create(getNetworkType(), getDeadline(), testAccount.getAddress(), alias, key, StringEncoder.getBytes(message)).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transaction.toAggregate(testAccount.getPublicAccount()))).maxFee(maxFee).build();
    AggregateTransaction announceCorrectly = announceAndValidate(type, testAccount, aggregateTransaction);
    Assertions.assertEquals(aggregateTransaction.getType(), announceCorrectly.getType());
    Assertions.assertEquals(testAccount.getPublicAccount(), announceCorrectly.getSigner().get());
    Assertions.assertEquals(1, announceCorrectly.getInnerTransactions().size());
    Assertions.assertEquals(transaction.getType(), announceCorrectly.getInnerTransactions().get(0).getType());
    MosaicMetadataTransaction processedTransaction = (MosaicMetadataTransaction) announceCorrectly.getInnerTransactions().get(0);
    Assertions.assertEquals(transaction.getTargetMosaicId(), processedTransaction.getTargetMosaicId());
    Assertions.assertEquals(transaction.getValueSizeDelta(), processedTransaction.getValueSizeDelta());
    Assertions.assertEquals(transaction.getScopedMetadataKey(), processedTransaction.getScopedMetadataKey());
    System.out.println(targetMosaicId.getIdAsHex());
    System.out.println(key);
    sleep(5000);
    List<Metadata> metadata = get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetMosaicId).metadataType(MetadataType.MOSAIC))).getData();
    assertMetadata(targetMosaicId, transaction, metadata);
    assertMetadata(targetMosaicId, transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetMosaicId).metadataType(MetadataType.MOSAIC).scopedMetadataKey(key))).getData());
    assertMetadata(targetMosaicId, transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().sourceAddress(testAccount.getAddress()).targetId(targetMosaicId).metadataType(MetadataType.MOSAIC).scopedMetadataKey(key))).getData());
    assertMetadata(targetMosaicId, transaction, metadata);
    Assertions.assertArrayEquals(StringEncoder.getBytes(message), processedTransaction.getValue());
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with MosaicMetadataTransaction

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

the class MosaicMetadataServiceIntegrationTest method setAndUpdateMosaicMetadata.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void setAndUpdateMosaicMetadata(RepositoryType type) {
    // TODO FIX THIS ONE when target != signerAccount
    Account signerAccount = config().getDefaultAccount();
    Account targetAccount = config().getDefaultAccount();
    Assertions.assertFalse(helper().isMultisig(type, signerAccount));
    Assertions.assertFalse(helper().isMultisig(type, targetAccount));
    MosaicId targetMosaicId = super.createMosaic(signerAccount, type, BigInteger.ZERO, null);
    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);
    MosaicMetadataTransaction originalTransaction = get(service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), key, originalMessage, signerAccount.getAddress(), targetMosaicId)).maxFee(maxFee).build();
    Assertions.assertEquals(targetAccount.getAddress(), originalTransaction.getTargetAddress());
    Assertions.assertEquals(targetMosaicId, originalTransaction.getTargetMosaicId());
    Assertions.assertEquals(key, originalTransaction.getScopedMetadataKey());
    Assertions.assertEquals(originalMessage, originalTransaction.getValue());
    helper().announceAggregateAndValidate(type, originalTransaction, signerAccount);
    assertMetadata(targetMosaicId, key, originalMessage, metadataRepository, signerAccount, targetAccount);
    MosaicMetadataTransaction updateTransaction = get(service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), key, newMessage, signerAccount.getAddress(), targetMosaicId)).maxFee(maxFee).build();
    Assertions.assertEquals(targetAccount.getAddress(), updateTransaction.getTargetAddress());
    Assertions.assertEquals(targetMosaicId, updateTransaction.getTargetMosaicId());
    Assertions.assertEquals(key, updateTransaction.getScopedMetadataKey());
    Pair<String, Integer> xorAndDelta = ConvertUtils.xorValues(originalMessage, newMessage);
    Assertions.assertEquals(xorAndDelta.getLeft(), updateTransaction.getValue());
    Assertions.assertEquals(xorAndDelta.getRight(), updateTransaction.getValueSizeDelta());
    helper().announceAggregateAndValidate(type, updateTransaction, signerAccount);
    assertMetadata(targetMosaicId, key, newMessage, metadataRepository, signerAccount, targetAccount);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) BigInteger(java.math.BigInteger) Account(io.nem.symbol.sdk.model.account.Account) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) 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

MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)5 BigInteger (java.math.BigInteger)4 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)3 Test (org.junit.jupiter.api.Test)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)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 Account (io.nem.symbol.sdk.model.account.Account)1 Metadata (io.nem.symbol.sdk.model.metadata.Metadata)1 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)1 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)1 TransactionInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO)1 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)1