Search in sources :

Example 11 with MosaicRestrictionSearchCriteria

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

the class MosaicAddressRestrictionIntegrationTest method assertMosaicAddressRestriction.

private void assertMosaicAddressRestriction(RestrictionMosaicRepository restrictionRepository, Address address, MosaicAddressRestrictionTransaction transaction, Address targetAddress, MosaicId mosaicId) {
    Page<MosaicRestriction<?>> page = get(restrictionRepository.search(new MosaicRestrictionSearchCriteria().entryType(MosaicRestrictionEntryType.ADDRESS).targetAddress(targetAddress).mosaicId(mosaicId)));
    Assertions.assertEquals(1, page.getData().size(), "Cannot find restriction target address " + targetAddress.plain() + " encoded: " + targetAddress.encoded() + " mosaicId " + mosaicId.getIdAsHex());
    MosaicAddressRestriction restriction = (MosaicAddressRestriction) page.getData().get(0);
    BigInteger restrictionKey = transaction.getRestrictionKey();
    BigInteger newRestrictionValue = transaction.getNewRestrictionValue();
    Assertions.assertEquals(Collections.singleton(restrictionKey), restriction.getRestrictions().keySet());
    Assertions.assertEquals(address, restriction.getTargetAddress());
    Assertions.assertEquals(1, restriction.getRestrictions().size());
    Assertions.assertEquals(newRestrictionValue, restriction.getRestrictions().get(restrictionKey));
    Assertions.assertEquals(transaction.getNewRestrictionValue(), restriction.getRestrictions().get(restrictionKey));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) BigInteger(java.math.BigInteger) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)

Example 12 with MosaicRestrictionSearchCriteria

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

the class MosaicAddressRestrictionIntegrationTest method getMosaicAddressRestrictionWhenMosaicDoesNotExist.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicAddressRestrictionWhenMosaicDoesNotExist(RepositoryType type) {
    RestrictionMosaicRepository repository = getRepositoryFactory(type).createRestrictionMosaicRepository();
    Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
    Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().mosaicId(new MosaicId(BigInteger.valueOf(888888))).targetAddress(address).entryType(MosaicRestrictionEntryType.ADDRESS)));
    Assertions.assertTrue(page.getData().isEmpty());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with MosaicRestrictionSearchCriteria

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

the class RestrictionMosaicRepositoryVertxImplTest method shouldGetMosaicAddressRestriction.

@Test
public void shouldGetMosaicAddressRestriction() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicAddressRestrictionDTO dto = new MosaicAddressRestrictionDTO();
    MosaicAddressRestrictionEntryWrapperDTO wrapperDTO = new MosaicAddressRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicAddressRestrictionEntryDTO entryDTO = new MosaicAddressRestrictionEntryDTO();
    wrapperDTO.setVersion(1);
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    entryDTO.setValue("2222");
    List<MosaicAddressRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_0);
    wrapperDTO.setTargetAddress(address.encoded());
    mockRemoteCall(toPage(dto));
    MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) repository.search(new MosaicRestrictionSearchCriteria().targetAddress(address).mosaicId(mosaicId).entryType(MosaicRestrictionEntryType.ADDRESS)).toFuture().get().getData().get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicAddressRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.ADDRESS, mosaicAddressRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicAddressRestriction.getMosaicId());
    Assertions.assertEquals(address, mosaicAddressRestriction.getTargetAddress());
    Assertions.assertEquals(1, mosaicAddressRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(2222), mosaicAddressRestriction.getRestrictions().get((BigInteger.valueOf(1111))));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Address(io.nem.symbol.sdk.model.account.Address) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicAddressRestrictionEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryDTO) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO) Test(org.junit.jupiter.api.Test)

Example 14 with MosaicRestrictionSearchCriteria

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

the class RestrictionMosaicRepositoryVertxImplTest method shouldGetMosaicAddressRestrictions.

@Test
public void shouldGetMosaicAddressRestrictions() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicAddressRestrictionDTO dto = new MosaicAddressRestrictionDTO();
    MosaicAddressRestrictionEntryWrapperDTO wrapperDTO = new MosaicAddressRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicAddressRestrictionEntryDTO entryDTO = new MosaicAddressRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    entryDTO.setValue("2222");
    List<MosaicAddressRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_0);
    wrapperDTO.setVersion(1);
    wrapperDTO.setTargetAddress(address.encoded());
    mockRemoteCall(toPage(dto));
    List<MosaicRestriction<?>> mosaicAddressRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
    Assertions.assertEquals(1, mosaicAddressRestrictions.size());
    MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) mosaicAddressRestrictions.get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicAddressRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.ADDRESS, mosaicAddressRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicAddressRestriction.getMosaicId());
    Assertions.assertEquals(address, mosaicAddressRestriction.getTargetAddress());
    Assertions.assertEquals(1, mosaicAddressRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(2222), mosaicAddressRestriction.getRestrictions().get(BigInteger.valueOf(1111)));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Address(io.nem.symbol.sdk.model.account.Address) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicAddressRestrictionEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryDTO) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO) Test(org.junit.jupiter.api.Test)

Example 15 with MosaicRestrictionSearchCriteria

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

the class RestrictionMosaicRepositoryVertxImplTest method shouldMosaicGlobalRestriction.

@Test
public void shouldMosaicGlobalRestriction() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicGlobalRestrictionDTO dto = new MosaicGlobalRestrictionDTO();
    MosaicGlobalRestrictionEntryWrapperDTO wrapperDTO = new MosaicGlobalRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicGlobalRestrictionEntryDTO entryDTO = new MosaicGlobalRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    MosaicGlobalRestrictionEntryRestrictionDTO entryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO();
    entryRestrictionDto.setRestrictionType(MosaicRestrictionTypeEnum.NUMBER_5);
    entryRestrictionDto.setReferenceMosaicId("456");
    entryRestrictionDto.setRestrictionValue(BigInteger.valueOf(3333));
    entryDTO.setRestriction(entryRestrictionDto);
    List<MosaicGlobalRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setVersion(1);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_1);
    mockRemoteCall(toPage(dto));
    MosaicGlobalRestriction mosaicGlobalRestriction = (MosaicGlobalRestriction) repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData().get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicGlobalRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.GLOBAL, mosaicGlobalRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicGlobalRestriction.getMosaicId());
    Assertions.assertEquals(1, mosaicGlobalRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(3333), mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionValue());
    Assertions.assertEquals("0000000000000456", mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getReferenceMosaicId().getIdAsHex());
    Assertions.assertEquals(MosaicRestrictionType.GT, mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf((1111))).getRestrictionType());
}
Also used : MosaicGlobalRestrictionEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)17 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)11 MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)11 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)8 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)8 MosaicAddressRestriction (io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction)7 Address (io.nem.symbol.sdk.model.account.Address)6 MosaicGlobalRestriction (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)4 MosaicRestrictionEntryType (io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType)3 MosaicAddressRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO)3 MosaicAddressRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO)3 MosaicGlobalRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO)3 MosaicGlobalRestrictionEntryRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO)3 MosaicGlobalRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO)3 BigInteger (java.math.BigInteger)3 MosaicAddressRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionDTO)2