// empty string is valid zero
@Test
    public void testSpendInputs() throws Throwable {
        ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo();
        GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo();
        final int tabPos = 0;
        // spend coins
        mActivityTestRule.runOnUiThread(() -> {
            mActivityTestRule.getActivity().setCurrentPage(tabPos);
        });
        // wait while balance be a 100
        waitForBalance(100);
        // wait while balance isn't update
        waitForBalanceUpdate();
        final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d)));
        ViewInteraction actionBtn = onView(allOf(
                withId(R.id.action),
                withText("EXCHANGE"),
                inViewPager(tabPos, R.id.pager)
        ));
        ViewInteraction actionUseMax = onView(allOf(
                withId(R.id.action_maximum),
                inViewPager(tabPos, R.id.pager)
        ));
        ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager)));
        ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager)));
        ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager)));
        ViewInteraction layoutCalculation = onView(allOf(
                withId(R.id.layout_calculation),
                inViewPager(tabPos, R.id.pager)
        ));
        ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager)));
        coinOutput.check(matches(withText(balanceString)));
        actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
        // submit disabled
        actionBtn.check(matches(not(isEnabled())));
        amountInput.check(matches(withInputLayoutHint(R.string.label_amount)));
        amountInput.check(matches(withInputLayoutError(null)));
        actionBtn.check(matches(not(isEnabled())));
        amountInput.perform(replaceText("0"));
        amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
        actionBtn.check(matches(not(isEnabled())));
        // empty string is valid zero
        amountInput.perform(replaceText(""));
        amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
        actionBtn.check(matches(not(isEnabled())));
        final String amount = "1";
        // valid value
        amountInput.perform(replaceText(amount));
        amountInput.check(matches(withInputLayoutError(null)));
        actionBtn.check(matches(not(isEnabled())));
        // @TODO potentially, may break test, as coin can be created
        coinInput.perform(replaceText("DOSNTEXIST"));
        coinInput.check(matches(withInputLayoutError("Coin to buy not exists")));
        // we can send transaction even if coin does not exists, because it can be no a true
        actionBtn.check(matches(isEnabled()));
        layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
        coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol()));
        layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
        onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager)))
                .check(matches(withText(R.string.label_you_will_get_approximately)));
        calculationSum.perform(scrollTo());
        Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute();
        assertTrue(estimate1.body().isOk());
        // amount without commission
        String expectEstimate3 = bdHuman(estimate1.body().result.getAmount());
        calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol()))));
        // visible "use max" for spend tab
        actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
        actionUseMax.perform(click());
        amountInput.check(matches(withText("100")));
        Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute();
        assertTrue(estimate2.body().isOk());
        // amount without commission
        String expectEstimate2 = bdHuman(estimate2.body().result.getAmount());
        calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol()))));
    }
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
actionBtn.check(matches(not(isEnabled())));
// empty string is valid zero
amountInput.perform(replaceText(""));
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
coinOutput.check(matches(withText(balanceString)));
actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
// submit disabled
actionBtn.check(matches(not(isEnabled())));
amountInput.check(matches(withInputLayoutHint(R.string.label_amount)));
amountInput.check(matches(withInputLayoutError(null)));
actionBtn.check(matches(not(isEnabled())));
amountInput.perform(replaceText("0"));
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
actionBtn.check(matches(not(isEnabled())));
// empty string is valid zero
amountInput.perform(replaceText(""));
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
actionBtn.check(matches(not(isEnabled())));
final String amount = "1";
// valid value
amountInput.perform(replaceText(amount));
amountInput.check(matches(withInputLayoutError(null)));
actionBtn.check(matches(not(isEnabled())));
// @TODO potentially, may break test, as coin can be created
coinInput.perform(replaceText("DOSNTEXIST"));
inViewPager(tabPos, R.id.pager)
));
ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager)));
ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager)));
ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager)));
ViewInteraction layoutCalculation = onView(allOf(
withId(R.id.layout_calculation),
inViewPager(tabPos, R.id.pager)
));
ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager)));
coinOutput.check(matches(withText(balanceString)));
actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
// submit disabled
actionBtn.check(matches(not(isEnabled())));
amountInput.check(matches(withInputLayoutHint(R.string.label_amount)));
amountInput.check(matches(withInputLayoutError(null)));
actionBtn.check(matches(not(isEnabled())));
amountInput.perform(replaceText("0"));
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
actionBtn.check(matches(not(isEnabled())));
// empty string is valid zero
amountInput.perform(replaceText(""));
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
actionBtn.check(matches(not(isEnabled())));
final String amount = "1";
// valid value
amountInput.perform(replaceText(amount));
amountInput.check(matches(withInputLayoutError(null)));
actionBtn.check(matches(not(isEnabled())));
// @TODO potentially, may break test, as coin can be created
coinInput.perform(replaceText("DOSNTEXIST"));
coinInput.check(matches(withInputLayoutError("Coin to buy not exists")));
// we can send transaction even if coin does not exists, because it can be no a true
actionBtn.check(matches(isEnabled()));
layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol()));
layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager)))
.check(matches(withText(R.string.label_you_will_get_approximately)));
calculationSum.perform(scrollTo());
Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute();