@Test
public void shouldRequestSuccessOnNonceRefresh() throws Exception {

  // given
  final AccountOperation mockAccountOperation = mock(AccountOperation.class);
  when(mockAccountOperation.getState(any(AccountAddress.class)))
      .thenReturn(AccountState.newBuilder().nonce(1L).build());
  final AergoClient mockClient = mock(AergoClient.class);
  when(mockClient.getAccountOperation()).thenReturn(mockAccountOperation);
  // then
  final int count = 3;
  final AtomicInteger countDown = new AtomicInteger(count);
  final TryCountAndInterval tryCountAndInterval = TryCountAndInterval.of(count, Time.of(100L));
  final TxRequester txRequester = new NonceRefreshingTxRequester(tryCountAndInterval,
      new SimpleNonceProvider());
  final AergoKey signer = new AergoKeyGenerator().create();
  final TxHash expected = TxHash.of(BytesValue.of(randomUUID().toString().getBytes()));
  final TxRequestFunction requestFunction = new TxRequestFunction() {
    @Override
    public TxHash apply(Signer signer, Long aLong) {
      if (countDown.get() <= 1) {
        return expected;
      }
      countDown.decrementAndGet();
      throw new CommitException(types.Rpc.CommitStatus.TX_HAS_SAME_NONCE, "");
    }
  };
  final TxHash actual = txRequester.request(mockClient, signer, requestFunction);
  assertEquals(expected, actual);
}