use of io.nem.symbol.sdk.model.metadata.Metadata 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());
}
use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.
the class MosaicMetadataIntegrationTest method searchIntegration.
//
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchIntegration(RepositoryType type) {
BigInteger key = MapperUtils.fromHexToBigInteger("000000000000000A");
Address sourceAddress = Address.createFromEncoded("9852D5EAA9AB038151EEBDD34308B3B2B7D82B92955F298E");
Address targetAddress = Address.createFromEncoded("9852D5EAA9AB038151EEBDD34308B3B2B7D82B92955F298E");
MosaicId mosaicId = new MosaicId("213CED6E6BBA6689");
MetadataType metadataType = MetadataType.MOSAIC;
Page<Metadata> metadataPage = get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().scopedMetadataKey(key).targetId(mosaicId).sourceAddress(sourceAddress).targetAddress(targetAddress).metadataType(metadataType)));
System.out.println(type + "\n" + toJson(metadataPage));
}
use of io.nem.symbol.sdk.model.metadata.Metadata 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.model.metadata.Metadata in project nem2-sdk-java by nemtech.
the class MetadataRepositoryVertxImplTest method assertMetadataList.
private void assertMetadataList(MetadataPage expected, List<Metadata> resultList) {
int index = 0;
Assertions.assertEquals(expected.getData().size(), resultList.size());
Assertions.assertEquals(3, resultList.size());
for (Metadata metadata : resultList) {
MetadataInfoDTO metadataDTO = expected.getData().get(index++);
assertMetadata(metadataDTO, metadata);
}
}
use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.
the class MetadataRepositoryVertxImplTest method getMetadata.
@Test
public void getMetadata() throws Exception {
MetadataInfoDTO metadataDTO = getMetadataEntriesDTO().getData().get(0);
mockRemoteCall(metadataDTO);
Metadata metadata = repository.getMetadata("abc").toFuture().get();
assertMetadata(metadataDTO, metadata);
}
Aggregations