Search in sources :

Example 1 with NamespaceRepository

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

the class CurrencyServiceTest method setup.

@BeforeEach
void setup() {
    RepositoryFactory factory = mock(RepositoryFactory.class);
    namespaceRepository = mock(NamespaceRepository.class);
    when(factory.createNamespaceRepository()).thenReturn(namespaceRepository);
    mosaicRepository = mock(MosaicRepository.class);
    when(factory.createMosaicRepository()).thenReturn(mosaicRepository);
    networkRepository = mock(NetworkRepository.class);
    when(factory.createNetworkRepository()).thenReturn(networkRepository);
    service = new CurrencyServiceImpl(factory);
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) NetworkRepository(io.nem.symbol.sdk.api.NetworkRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with NamespaceRepository

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

the class MosaicRestrictionTransactionServiceTest method setup.

@BeforeEach
void setup() {
    RepositoryFactory factory = mock(RepositoryFactory.class);
    restrictionMosaicRepository = mock(RestrictionMosaicRepository.class);
    when(factory.createRestrictionMosaicRepository()).thenReturn(restrictionMosaicRepository);
    namespaceRepository = mock(NamespaceRepository.class);
    when(factory.createNamespaceRepository()).thenReturn(namespaceRepository);
    when(factory.getNetworkType()).thenReturn(Observable.just(networkType));
    when(factory.getEpochAdjustment()).thenReturn(Observable.just(Duration.ofSeconds(10)));
    service = new MosaicRestrictionTransactionServiceImpl(factory);
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId1).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.just(toPage(mockGlobalRestriction())));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId2).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.just(toPage(mockGlobalRestriction())));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdWrongKey).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.error(() -> new IllegalStateException("Not a nice mosaic id")));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdNotFound).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.just(toPage()));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId1).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.just(toPage(mockAddressRestriction())));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId2).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.just(toPage()));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdWrongKey).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.error(() -> new IllegalStateException("Not a nice mosaic id")));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdNotFound).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.just(toPage()));
    when(namespaceRepository.getNamespace(Mockito.any())).thenReturn(Observable.error(new IllegalStateException("Alias does not exist")));
    when(namespaceRepository.getNamespace(accountAlias1)).thenReturn(Observable.just(createAlias(account1.getAddress())));
    when(namespaceRepository.getNamespace(accountAlias2)).thenReturn(Observable.just(createAlias(account2.getAddress())));
    when(namespaceRepository.getNamespace(mosaicAlias1)).thenReturn(Observable.just(createAlias(mosaicId1)));
    when(namespaceRepository.getNamespace(mosaicAlias2)).thenReturn(Observable.just(createAlias(mosaicId2)));
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with NamespaceRepository

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

the class StateProofServiceTest method namespace.

@Test
void namespace() throws Exception {
    NamespaceRepository repository = mock(NamespaceRepository.class);
    when(factory.createNamespaceRepository()).thenReturn(repository);
    NamespaceId id = NamespaceId.createFromId(BigInteger.ONE);
    NamespaceInfo state = Mockito.mock(NamespaceInfo.class);
    when(state.getId()).thenReturn(id);
    when(state.serialize(any())).thenReturn(ConvertUtils.fromHexToBytes(serialized));
    when(repository.streamer()).thenReturn(new PaginationStreamer<>(repository));
    when(repository.search(any())).thenReturn(Observable.just(new Page<>(new ArrayList<>())));
    when(repository.getNamespace(eq(id))).thenReturn(Observable.just(state));
    when(repository.getNamespaceMerkle(eq(id))).thenReturn(Observable.just(tree));
    StateMerkleProof<NamespaceInfo> proof = service.namespace(id).toFuture().get();
    Assertions.assertTrue(proof.isValid());
    Assertions.assertEquals(state, proof.getState());
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) Page(io.nem.symbol.sdk.api.Page) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 4 with NamespaceRepository

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

the class StateProofServiceImpl method namespace.

@Override
public Observable<StateMerkleProof<NamespaceInfo>> namespace(NamespaceInfo state) {
    NamespaceId id = state.getId();
    NamespaceRepository namespaceRepository = this.repositoryFactory.createNamespaceRepository();
    PaginationStreamer<NamespaceInfo, NamespaceSearchCriteria> streamer = namespaceRepository.streamer();
    return namespaceRepository.getNamespaceMerkle(id).flatMap(merkle -> streamer.search(new NamespaceSearchCriteria().level0(state.getId().getIdAsHex()).registrationType(NamespaceRegistrationType.SUB_NAMESPACE)).toList().toObservable().map(state::serialize).map(s -> toStateMerkleProof(state, merkle, s)));
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Hashes(io.nem.symbol.core.crypto.Hashes) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) StateProofService(io.nem.symbol.sdk.api.StateProofService) StateMerkleProof(io.nem.symbol.sdk.model.state.StateMerkleProof) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) PaginationStreamer(io.nem.symbol.sdk.api.PaginationStreamer) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) NamespaceRegistrationType(io.nem.symbol.sdk.model.namespace.NamespaceRegistrationType) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria) AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) Observable(io.reactivex.Observable) Address(io.nem.symbol.sdk.model.account.Address) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria)

Example 5 with NamespaceRepository

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

the class MerkleLoaderIntegrationTest method namespaces.

public List<Arguments> namespaces() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    NamespaceRepository repository = repositoryFactory.createNamespaceRepository();
    return getArguments(repository, new NamespaceSearchCriteria().order(ORDER_BY).registrationType(NamespaceRegistrationType.ROOT_NAMESPACE));
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria)

Aggregations

NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)7 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)6 BeforeEach (org.junit.jupiter.api.BeforeEach)4 NamespaceSearchCriteria (io.nem.symbol.sdk.api.NamespaceSearchCriteria)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 NamespaceInfo (io.nem.symbol.sdk.model.namespace.NamespaceInfo)2 Hashes (io.nem.symbol.core.crypto.Hashes)1 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)1 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)1 MosaicRepository (io.nem.symbol.sdk.api.MosaicRepository)1 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)1 NetworkRepository (io.nem.symbol.sdk.api.NetworkRepository)1 Page (io.nem.symbol.sdk.api.Page)1 PaginationStreamer (io.nem.symbol.sdk.api.PaginationStreamer)1 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)1 StateProofService (io.nem.symbol.sdk.api.StateProofService)1 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)1 AccountRestrictions (io.nem.symbol.sdk.model.account.AccountRestrictions)1 Address (io.nem.symbol.sdk.model.account.Address)1 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)1