Search in sources :

Example 6 with AccountRestrictions

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

the class AccountRestrictionIntegrationTest method hasRestriction.

private boolean hasRestriction(RepositoryType type, Account testAccount, AccountRestrictionFlags restrictionFlags, Object value) {
    try {
        AccountRestrictions restrictions = get(getRepositoryFactory(type).createRestrictionAccountRepository().getAccountRestrictions(testAccount.getAddress()));
        Assertions.assertEquals(testAccount.getAddress(), restrictions.getAddress());
        System.out.println("Current Restrictions: " + jsonHelper().print(restrictions));
        return restrictions.getRestrictions().stream().anyMatch(r -> r.getRestrictionFlags().equals(restrictionFlags) && r.getValues().contains(value));
    } catch (Exception e) {
        // If it fails, it's because is a new account.
        Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id '" + testAccount.getAddress().plain() + "'", e.getMessage());
        return false;
    }
}
Also used : AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException)

Example 7 with AccountRestrictions

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

the class RestrictionAccountRepositoryVertxImplTest method search.

@Test
public void search() 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(toPage(info));
    AccountRestrictions accountRestrictions = repository.search(new AccountRestrictionSearchCriteria()).toFuture().get().getData().get(0);
    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) AccountRestrictionSearchCriteria(io.nem.symbol.sdk.api.AccountRestrictionSearchCriteria) 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 8 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