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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations