[bisq-network/bisq] Refactor fee estimation (#2251)

Bernard Labno notifications at github.com
Sun Jan 20 11:52:27 UTC 2019


blabno commented on this pull request.



> +    @Ignore
+    public void testGetEstimatedTxSize_withLargeTx() throws InsufficientMoneyException {
+        List<Coin> outputValues = List.of(Coin.valueOf(2000), Coin.valueOf(3000));
+        int initialEstimatedTxSize;
+        Coin txFeePerByte;
+        BtcWalletService btcWalletService = mock(BtcWalletService.class);
+        int result;
+        int realTxSize;
+        Coin txFee;
+
+        initialEstimatedTxSize = 260;
+        txFeePerByte = Coin.valueOf(10);
+        realTxSize = 2600;
+
+        txFee = txFeePerByte.multiply(initialEstimatedTxSize);
+        when(btcWalletService.getEstimatedFeeTxSize(outputValues, txFee)).thenReturn(realTxSize);

do/while loop inside `getEstimatedFeeTxSize` has 2 cycles because first invocation of `isInTolerance` returns `false`.
So for the first iteration we have to mock with initial `txFee`:
        
    when(btcWalletService.getEstimatedFeeTxSize(outputValues, txFee)).thenReturn(realTxSize);

And for the second iteration we have to mock with `txFee` multiplied by `txFeePerByte`.

    when(btcWalletService.getEstimatedFeeTxSize(outputValues, txFeePerByte.multiply(realTxSize))).thenReturn(realTxSize)

Alternatively we can mock `getEstimatedFeeTxSize` to return the same result for any `txFee`:

    when(btcWalletService.getEstimatedFeeTxSize(eq(outputValues), any(Coin.class))).thenReturn(realTxSize);

> +        int realTxSize;
+        Coin txFee;
+
+        initialEstimatedTxSize = 260;
+        txFeePerByte = Coin.valueOf(10);
+        realTxSize = 2600;
+
+        txFee = txFeePerByte.multiply(initialEstimatedTxSize);
+        when(btcWalletService.getEstimatedFeeTxSize(outputValues, txFee)).thenReturn(realTxSize);
+
+        // repeated calls to getEstimatedFeeTxSize do not work (returns 0 at second call in loop which cause test to fail)
+        result = TxFeeEstimationService.getEstimatedTxSize(outputValues, initialEstimatedTxSize, txFeePerByte, btcWalletService);
+        assertEquals(2600, result);
+    }
+
+    // FIXME @Bernard could you have a look?

Same as above

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/2251#pullrequestreview-194388596
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20190120/b9f003bd/attachment.html>


More information about the bisq-github mailing list