use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.
the class NamespaceMetadataServiceIntegrationTest method assertMetadata.
private void assertMetadata(NamespaceId targetNamespaceId, BigInteger key, String value, MetadataRepository metadataRepository, Account signerAccount) {
MetadataSearchCriteria criteria = new MetadataSearchCriteria().targetId(targetNamespaceId).scopedMetadataKey(key).sourceAddress(signerAccount.getAddress());
Metadata originalMetadata = get(metadataRepository.search(criteria)).getData().get(0);
Assertions.assertEquals(value, originalMetadata.getValue());
}
use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldCreateNamespaceMetadataTransactionFactory.
@Test
void shouldCreateNamespaceMetadataTransactionFactory() throws Exception {
BigInteger metadataKey = BigInteger.valueOf(10);
String oldValue = "The original Message";
String newValue = "the new Message";
Metadata metadata = new Metadata("someId", 1, "compositeHash", sourceAddress, targetAccount.getAddress(), metadataKey, MetadataType.NAMESPACE, StringEncoder.getBytes(oldValue), namespaceId.getIdAsHex());
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(namespaceId).metadataType(MetadataType.NAMESPACE);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
NamespaceMetadataTransactionFactory result = service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, namespaceId).toFuture().get();
Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
Assertions.assertNotEquals(oldValue, StringEncoder.getString(result.getValue()));
Assertions.assertNotEquals(newValue, StringEncoder.getString(result.getValue()));
Assertions.assertEquals(StringEncoder.getBytes(newValue).length - StringEncoder.getBytes(oldValue).length, result.getValueSizeDelta());
Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
Assertions.assertEquals(namespaceId.getId(), result.getTargetNamespaceId().getId());
Mockito.verify(metadataRepositoryMock).search(criteria);
}
use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldCreateMosaicMetadataTransactionFactoryUsingAlias.
@Test
void shouldCreateMosaicMetadataTransactionFactoryUsingAlias() throws Exception {
BigInteger metadataKey = BigInteger.valueOf(10);
String oldValue = "The original Message";
String newValue = "the new Message";
Metadata metadata = new Metadata("someId", 1, "compositeHash", sourceAddress, targetAccount.getAddress(), metadataKey, MetadataType.MOSAIC, StringEncoder.getBytes(oldValue), mosaicId.getIdAsHex());
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(mosaicId).metadataType(MetadataType.MOSAIC);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
MosaicMetadataTransactionFactory result = service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, mosaicAlias).toFuture().get();
Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
Assertions.assertNotEquals(oldValue, StringEncoder.getString(result.getValue()));
Assertions.assertNotEquals(newValue, StringEncoder.getString(result.getValue()));
Assertions.assertEquals(StringEncoder.getBytes(newValue).length - StringEncoder.getBytes(oldValue).length, result.getValueSizeDelta());
Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
Assertions.assertEquals(mosaicAlias, result.getTargetMosaicId());
Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.
the class StateProofServiceTest method metadata.
@Test
void metadata() throws Exception {
MetadataRepository repository = mock(MetadataRepository.class);
when(factory.createMetadataRepository()).thenReturn(repository);
String id = "hash";
Metadata state = Mockito.mock(Metadata.class);
when(state.getCompositeHash()).thenReturn(id);
when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
when(repository.getMetadata(eq(id))).thenReturn(Observable.just(state));
when(repository.getMetadataMerkle(eq(id))).thenReturn(Observable.just(tree));
StateMerkleProof<Metadata> proof = service.metadata(id).toFuture().get();
Assertions.assertTrue(proof.isValid());
Assertions.assertEquals(state, proof.getState());
}
Aggregations