mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
pytest: Use the bitcoind proxy to mock feerates
This commit is contained in:
parent
aa80a330f1
commit
16869e3fe6
4 changed files with 29 additions and 7 deletions
|
@ -19,7 +19,7 @@ class DecimalEncoder(json.JSONEncoder):
|
|||
"""
|
||||
def default(self, o):
|
||||
if isinstance(o, decimal.Decimal):
|
||||
return str(o)
|
||||
return "{:.8f}".format(float(o))
|
||||
return super(DecimalEncoder, self).default(o)
|
||||
|
||||
|
||||
|
|
|
@ -1108,8 +1108,11 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind):
|
|||
@unittest.skipIf(not DEVELOPER, "needs dev_fail")
|
||||
def test_no_fee_estimate(node_factory, bitcoind, executor):
|
||||
l1 = node_factory.get_node(start=False)
|
||||
l1.bitcoind_cmd_override(cmd='estimatesmartfee',
|
||||
failscript="""echo '{ "errors": [ "Insufficient data or no feerate found" ], "blocks": 0 }'; exit 0""")
|
||||
|
||||
# Fail any fee estimation requests until we allow them further down
|
||||
l1.daemon.rpcproxy.mock_rpc('estimatesmartfee', {
|
||||
'error': {"errors": ["Insufficient data or no feerate found"], "blocks": 0}
|
||||
})
|
||||
l1.start()
|
||||
|
||||
l2 = node_factory.get_node()
|
||||
|
|
|
@ -858,8 +858,9 @@ def test_ipv4_and_ipv6(node_factory):
|
|||
|
||||
def test_feerates(node_factory):
|
||||
l1 = node_factory.get_node(options={'log-level': 'io'}, start=False)
|
||||
l1.bitcoind_cmd_override(cmd='estimatesmartfee',
|
||||
failscript="""echo '{ "errors": [ "Insufficient data or no feerate found" ], "blocks": 0 }'; exit 0""")
|
||||
l1.daemon.rpcproxy.mock_rpc('estimatesmartfee', {
|
||||
'error': {"errors": ["Insufficient data or no feerate found"], "blocks": 0}
|
||||
})
|
||||
l1.start()
|
||||
|
||||
# Query feerates (shouldn't give any!)
|
||||
|
|
|
@ -623,8 +623,26 @@ class LightningNode(object):
|
|||
# it on a running daemon may not give expected result!
|
||||
def set_feerates(self, feerates, wait_for_effect=True):
|
||||
# (bitcoind returns bitcoin per kb, so these are * 4)
|
||||
self.bitcoind_cmd_override("""case "$*" in *2\ CONSERVATIVE*) FEERATE={};; *4\ ECONOMICAL*) FEERATE={};; *100\ ECONOMICAL*) FEERATE={};; *) exit 98;; esac; echo '{{ "feerate": '$(printf 0.%08u $FEERATE)' }}'; exit 0""".format(feerates[0] * 4, feerates[1] * 4, feerates[2] * 4),
|
||||
'estimatesmartfee')
|
||||
|
||||
def mock_estimatesmartfee(r):
|
||||
params = r['params']
|
||||
if params == [2, 'CONSERVATIVE']:
|
||||
feerate = feerates[0] * 4
|
||||
elif params == [4, 'ECONOMICAL']:
|
||||
feerate = feerates[1] * 4
|
||||
elif params == [100, 'ECONOMICAL']:
|
||||
feerate = feerates[2] * 4
|
||||
else:
|
||||
raise ValueError()
|
||||
return {
|
||||
'id': r['id'],
|
||||
'error': None,
|
||||
'result': {
|
||||
'feerate': Decimal(feerate) / 10**8
|
||||
},
|
||||
}
|
||||
self.daemon.rpcproxy.mock_rpc('estimatesmartfee', mock_estimatesmartfee)
|
||||
|
||||
if wait_for_effect:
|
||||
self.daemon.wait_for_log('Feerate estimate for .* set to')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue