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