use of io.nem.symbol.sdk.api.MetadataTransactionService 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);
}
use of io.nem.symbol.sdk.api.MetadataTransactionService 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());
}
use of io.nem.symbol.sdk.api.MetadataTransactionService 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);
}
use of io.nem.symbol.sdk.api.MetadataTransactionService 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