Search in sources :

Example 1 with MetadataRepository

use of io.nem.symbol.sdk.api.MetadataRepository 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);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) Account(io.nem.symbol.sdk.model.account.Account) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with MetadataRepository

use of io.nem.symbol.sdk.api.MetadataRepository in project nem2-sdk-java by nemtech.

the class MerkleLoaderIntegrationTest method metadatas.

public List<Arguments> metadatas() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    MetadataRepository repository = repositoryFactory.createMetadataRepository();
    return getArguments(repository, new MetadataSearchCriteria().order(ORDER_BY));
}
Also used : MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory)

Example 3 with MetadataRepository

use of io.nem.symbol.sdk.api.MetadataRepository 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);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) BigInteger(java.math.BigInteger) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with MetadataRepository

use of io.nem.symbol.sdk.api.MetadataRepository 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)

Example 5 with MetadataRepository

use of io.nem.symbol.sdk.api.MetadataRepository 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());
}
Also used : MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) Test(org.junit.jupiter.api.Test)

Aggregations

MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)5 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)4 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)3 BigInteger (java.math.BigInteger)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 Account (io.nem.symbol.sdk.model.account.Account)2 MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)1 Metadata (io.nem.symbol.sdk.model.metadata.Metadata)1 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)1 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)1 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)1 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)1 Test (org.junit.jupiter.api.Test)1