Skip to content

Commit 2dfd683

Browse files
committedAug 18, 2019
test: Add test for default maxfeerate in sendrawtransaction
This patch adds test for the following case - maxfeerate is omitted, and the actual fee rate is higher than the default value(0.1 BTC/kB)
1 parent 261843e commit 2dfd683

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed
 

‎test/functional/rpc_rawtransaction.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -432,27 +432,51 @@ def run_test(self):
432432

433433
self.log.info('sendrawtransaction/testmempoolaccept with maxfeerate')
434434

435+
# Test a transaction with small fee
435436
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
436437
rawTx = self.nodes[0].getrawtransaction(txId, True)
437438
vout = next(o for o in rawTx['vout'] if o['value'] == Decimal('1.00000000'))
438439

439440
self.sync_all()
440441
inputs = [{ "txid" : txId, "vout" : vout['n'] }]
441-
outputs = { self.nodes[0].getnewaddress() : Decimal("0.99999000") } # 1000 sat fee
442+
outputs = { self.nodes[0].getnewaddress() : Decimal("0.999990000") } # 10000 sat fee
442443
rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
443444
rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx)
444445
assert_equal(rawTxSigned['complete'], True)
445-
# 1000 sat fee, ~100 b transaction, fee rate should land around 10 sat/b = 0.00010000 BTC/kB
446+
# 10000 sat fee, ~100 b transaction, fee rate should land around 100 sat/b = 0.00100000 BTC/kB
446447
# Thus, testmempoolaccept should reject
447448
testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']], 0.00001000)[0]
448449
assert_equal(testres['allowed'], False)
449450
assert_equal(testres['reject-reason'], '256: absurdly-high-fee')
450451
# and sendrawtransaction should throw
451452
assert_raises_rpc_error(-26, "absurdly-high-fee", self.nodes[2].sendrawtransaction, rawTxSigned['hex'], 0.00001000)
452453
# And below calls should both succeed
453-
testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate='0.00070000')[0]
454+
testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']])[0]
454455
assert_equal(testres['allowed'], True)
455-
self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate='0.00070000')
456+
self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'])
457+
458+
# Test a transaction with large fee
459+
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
460+
rawTx = self.nodes[0].getrawtransaction(txId, True)
461+
vout = next(o for o in rawTx['vout'] if o['value'] == Decimal('1.00000000'))
462+
463+
self.sync_all()
464+
inputs = [{ "txid" : txId, "vout" : vout['n'] }]
465+
outputs = { self.nodes[0].getnewaddress() : Decimal("0.98000000") } # 2000000 sat fee
466+
rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
467+
rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx)
468+
assert_equal(rawTxSigned['complete'], True)
469+
# 2000000 sat fee, ~100 b transaction, fee rate should land around 20000 sat/b = 0.20000000 BTC/kB
470+
# Thus, testmempoolaccept should reject
471+
testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']])[0]
472+
assert_equal(testres['allowed'], False)
473+
assert_equal(testres['reject-reason'], '256: absurdly-high-fee')
474+
# and sendrawtransaction should throw
475+
assert_raises_rpc_error(-26, "absurdly-high-fee", self.nodes[2].sendrawtransaction, rawTxSigned['hex'])
476+
# And below calls should both succeed
477+
testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate='0.20000000')[0]
478+
assert_equal(testres['allowed'], True)
479+
self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate='0.20000000')
456480

457481

458482
if __name__ == '__main__':

0 commit comments

Comments
 (0)