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;
}
}
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());
}
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());
}
Aggregations