Search in sources :

Example 1 with AccountRestrictions

use of io.nem.symbol.sdk.model.account.AccountRestrictions in project nem2-sdk-java by nemtech.

the class AccountRestrictionIntegrationTest method addRestrictionsToRandomAddress.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addRestrictionsToRandomAddress(RepositoryType type) {
    Account testAccount = this.helper().createTestAccount(type);
    Account testAccount2 = this.helper().createTestAccount(type);
    Account testAccount3 = this.helper().createTestAccount(type);
    Account testAccount4 = this.helper().createTestAccount(type);
    AccountOperationRestrictionTransaction operationRestrictions = AccountOperationRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), AccountOperationRestrictionFlags.BLOCK_OUTGOING_TRANSACTION_TYPE, Arrays.asList(TransactionType.HASH_LOCK, TransactionType.SECRET_LOCK), Collections.emptyList()).maxFee(maxFee).build();
    AccountAddressRestrictionTransaction accountRestrictions1 = AccountAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), AccountAddressRestrictionFlags.BLOCK_ADDRESS, Arrays.asList(testAccount2.getAddress(), testAccount3.getAddress()), Collections.emptyList()).maxFee(maxFee).build();
    AccountAddressRestrictionTransaction accountRestrictions2 = AccountAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), AccountAddressRestrictionFlags.BLOCK_OUTGOING_ADDRESS, Collections.singletonList(testAccount4.getAddress()), Collections.emptyList()).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Arrays.asList(operationRestrictions.toAggregate(testAccount.getPublicAccount()), accountRestrictions1.toAggregate(testAccount.getPublicAccount()), accountRestrictions2.toAggregate(testAccount.getPublicAccount()))).maxFee(maxFee).build();
    helper().announceAndValidate(type, testAccount, aggregateTransaction);
    sleep(1000);
    AccountRestrictions accountRestrictions = get(getRepositoryFactory(type).createRestrictionAccountRepository().getAccountRestrictions(testAccount.getAddress()));
    Assertions.assertEquals(3, accountRestrictions.getRestrictions().size());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AccountRestrictions

use of io.nem.symbol.sdk.model.account.AccountRestrictions in project nem2-sdk-java by nemtech.

the class RestrictionAccountRepositoryVertxImplTest method shouldGetAccountRestrictions.

@Test
public void shouldGetAccountRestrictions() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    AccountRestrictionsDTO dto = new AccountRestrictionsDTO();
    dto.setAddress(address.encoded());
    AccountRestrictionDTO restriction = new AccountRestrictionDTO();
    restriction.setRestrictionFlags(AccountRestrictionFlagsEnum.NUMBER_32770);
    restriction.setValues(Collections.singletonList("9636553580561478212"));
    dto.setRestrictions(Collections.singletonList(restriction));
    dto.setVersion(1);
    AccountRestrictionsInfoDTO info = new AccountRestrictionsInfoDTO();
    info.setAccountRestrictions(dto);
    mockRemoteCall(info);
    AccountRestrictions accountRestrictions = repository.getAccountRestrictions(address).toFuture().get();
    Assertions.assertEquals(address, accountRestrictions.getAddress());
    Assertions.assertEquals(1, accountRestrictions.getRestrictions().size());
    Assertions.assertEquals(AccountMosaicRestrictionFlags.BLOCK_MOSAIC, accountRestrictions.getRestrictions().get(0).getRestrictionFlags());
    Assertions.assertEquals(Collections.singletonList(MapperUtils.toMosaicId("9636553580561478212")), accountRestrictions.getRestrictions().get(0).getValues());
}
Also used : AccountRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionDTO) AccountRestrictionsDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionsDTO) Address(io.nem.symbol.sdk.model.account.Address) AccountRestrictionsInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionsInfoDTO) AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) Test(org.junit.jupiter.api.Test)

Example 3 with AccountRestrictions

use of io.nem.symbol.sdk.model.account.AccountRestrictions in project nem2-sdk-java by nemtech.

the class RestrictionAccountRepositoryOkHttpImplTest method shouldGetAccountRestrictions.

@Test
public void shouldGetAccountRestrictions() throws Exception {
    Address address = Address.generateRandom(networkType);
    AccountRestrictionsDTO dto = new AccountRestrictionsDTO();
    dto.setAddress(address.encoded());
    AccountRestrictionDTO restriction = new AccountRestrictionDTO();
    restriction.setRestrictionFlags(AccountRestrictionFlagsEnum.NUMBER_32770);
    restriction.setValues(Arrays.asList("9636553580561478212"));
    dto.setRestrictions(Collections.singletonList(restriction));
    dto.setVersion(1);
    AccountRestrictionsInfoDTO info = new AccountRestrictionsInfoDTO();
    info.setAccountRestrictions(dto);
    mockRemoteCall(info);
    AccountRestrictions accountRestrictions = repository.getAccountRestrictions(address).toFuture().get();
    Assertions.assertEquals(address, accountRestrictions.getAddress());
    Assertions.assertEquals(1, accountRestrictions.getRestrictions().size());
    Assertions.assertEquals(AccountMosaicRestrictionFlags.BLOCK_MOSAIC, accountRestrictions.getRestrictions().get(0).getRestrictionFlags());
    Assertions.assertEquals(Arrays.asList(MapperUtils.toMosaicId("9636553580561478212")), accountRestrictions.getRestrictions().get(0).getValues());
}
Also used : AccountRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionDTO) AccountRestrictionsDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionsDTO) Address(io.nem.symbol.sdk.model.account.Address) AccountRestrictionsInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionsInfoDTO) AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) Test(org.junit.jupiter.api.Test)

Example 4 with AccountRestrictions

use of io.nem.symbol.sdk.model.account.AccountRestrictions in project nem2-sdk-java by nemtech.

the class RestrictionAccountRepositoryVertxImpl method search.

@Override
public Observable<Page<AccountRestrictions>> search(AccountRestrictionSearchCriteria criteria) {
    String address = toDto(criteria.getAddress());
    Integer pageSize = criteria.getPageSize();
    Integer pageNumber = criteria.getPageNumber();
    String offset = criteria.getOffset();
    Order order = toDto(criteria.getOrder());
    Consumer<Handler<AsyncResult<AccountRestrictionsPage>>> handlerConsumer = (h) -> getClient().searchAccountRestrictions(address, pageSize, pageNumber, offset, order, h);
    return this.call(handlerConsumer, this::toPage);
}
Also used : Order(io.nem.symbol.sdk.openapi.vertx.model.Order) AccountRestrictionsPage(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionsPage) RestrictionAccountRepository(io.nem.symbol.sdk.api.RestrictionAccountRepository) MapperUtils(io.nem.symbol.core.utils.MapperUtils) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) RestrictionAccountRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.RestrictionAccountRoutesApi) AccountRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountRestrictionFlags) AccountRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionDTO) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) AccountRestrictionSearchCriteria(io.nem.symbol.sdk.api.AccountRestrictionSearchCriteria) AccountRestrictionsPage(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionsPage) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) ObjectUtils(org.apache.commons.lang3.ObjectUtils) AccountRestriction(io.nem.symbol.sdk.model.account.AccountRestriction) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) Observable(io.reactivex.Observable) AccountRestrictionsInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionsInfoDTO) AsyncResult(io.vertx.core.AsyncResult) Address(io.nem.symbol.sdk.model.account.Address) RestrictionAccountRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.RestrictionAccountRoutesApiImpl) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) Handler(io.vertx.core.Handler)

Example 5 with AccountRestrictions

use of io.nem.symbol.sdk.model.account.AccountRestrictions in project nem2-sdk-java by nemtech.

the class StateProofServiceTest method accountRestrictions.

@Test
void accountRestrictions() throws Exception {
    RestrictionAccountRepository repository = mock(RestrictionAccountRepository.class);
    when(factory.createRestrictionAccountRepository()).thenReturn(repository);
    Address id = Address.generateRandom(NetworkType.MIJIN_TEST);
    AccountRestrictions state = Mockito.mock(AccountRestrictions.class);
    when(state.getAddress()).thenReturn(id);
    when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
    when(repository.getAccountRestrictions(eq(id))).thenReturn(Observable.just(state));
    when(repository.getAccountRestrictionsMerkle(eq(id))).thenReturn(Observable.just(tree));
    StateMerkleProof<AccountRestrictions> proof = service.accountRestrictions(id).toFuture().get();
    Assertions.assertTrue(proof.isValid());
    Assertions.assertEquals(state, proof.getState());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) RestrictionAccountRepository(io.nem.symbol.sdk.api.RestrictionAccountRepository) AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) Test(org.junit.jupiter.api.Test)

Aggregations

AccountRestrictions (io.nem.symbol.sdk.model.account.AccountRestrictions)8 Address (io.nem.symbol.sdk.model.account.Address)6 Test (org.junit.jupiter.api.Test)5 AccountRestrictionSearchCriteria (io.nem.symbol.sdk.api.AccountRestrictionSearchCriteria)3 AccountRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionDTO)3 AccountRestrictionsInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionsInfoDTO)3 RestrictionAccountRepository (io.nem.symbol.sdk.api.RestrictionAccountRepository)2 AccountRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionDTO)2 AccountRestrictionsDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionsDTO)2 AccountRestrictionsInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionsInfoDTO)2 AccountRestrictionsDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionsDTO)2 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1 Page (io.nem.symbol.sdk.api.Page)1 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)1 Account (io.nem.symbol.sdk.model.account.Account)1 AccountRestriction (io.nem.symbol.sdk.model.account.AccountRestriction)1 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)1 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)1 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)1 AccountRestrictionFlags (io.nem.symbol.sdk.model.transaction.AccountRestrictionFlags)1