|
40 | 40 | assert_raises_rpc_error,
|
41 | 41 | get_fee,
|
42 | 42 | )
|
43 |
| -from test_framework.wallet import MiniWallet |
| 43 | +from test_framework.wallet import ( |
| 44 | + MiniWallet, |
| 45 | + MiniWalletMode, |
| 46 | +) |
44 | 47 |
|
45 | 48 |
|
46 | 49 | DIFFICULTY_ADJUSTMENT_INTERVAL = 144
|
@@ -93,6 +96,57 @@ def mine_chain(self):
|
93 | 96 | self.restart_node(0)
|
94 | 97 | self.connect_nodes(0, 1)
|
95 | 98 |
|
| 99 | + def test_fees_and_sigops(self): |
| 100 | + self.log.info("Test fees and sigops in getblocktemplate result") |
| 101 | + node = self.nodes[0] |
| 102 | + |
| 103 | + # Generate a coinbases with p2pk transactions for its sigops. |
| 104 | + wallet_sigops = MiniWallet(node, mode=MiniWalletMode.RAW_P2PK) |
| 105 | + self.generate(wallet_sigops, 1, sync_fun=self.no_op) |
| 106 | + |
| 107 | + # Mature with regular coinbases to prevent inteference with other tests |
| 108 | + self.generate(self.wallet, 100, sync_fun=self.no_op) |
| 109 | + |
| 110 | + # Generate three transactions that must be mined in sequence |
| 111 | + # |
| 112 | + # tx_a (1 sat/vbyte) |
| 113 | + # | |
| 114 | + # | |
| 115 | + # tx_b (2 sat/vbyte) |
| 116 | + # | |
| 117 | + # | |
| 118 | + # tx_c (3 sat/vbyte) |
| 119 | + # |
| 120 | + tx_a = wallet_sigops.send_self_transfer(from_node=node, |
| 121 | + fee_rate=Decimal("0.00001")) |
| 122 | + tx_b = wallet_sigops.send_self_transfer(from_node=node, |
| 123 | + fee_rate=Decimal("0.00002"), |
| 124 | + utxo_to_spend=tx_a["new_utxo"]) |
| 125 | + tx_c = wallet_sigops.send_self_transfer(from_node=node, |
| 126 | + fee_rate=Decimal("0.00003"), |
| 127 | + utxo_to_spend=tx_b["new_utxo"]) |
| 128 | + |
| 129 | + # Generate transaction without sigops. It will go first because it pays |
| 130 | + # higher fees (100 sat/vbyte) and descends from a different coinbase. |
| 131 | + tx_d = self.wallet.send_self_transfer(from_node=node, |
| 132 | + fee_rate=Decimal("0.00100")) |
| 133 | + |
| 134 | + block_template_txs = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)['transactions'] |
| 135 | + |
| 136 | + block_template_fees = [tx['fee'] for tx in block_template_txs] |
| 137 | + assert_equal(block_template_fees, [ |
| 138 | + tx_d["fee"] * COIN, |
| 139 | + tx_a["fee"] * COIN, |
| 140 | + tx_b["fee"] * COIN, |
| 141 | + tx_c["fee"] * COIN |
| 142 | + ]) |
| 143 | + |
| 144 | + block_template_sigops = [tx['sigops'] for tx in block_template_txs] |
| 145 | + assert_equal(block_template_sigops, [0, 4, 4, 4]) |
| 146 | + |
| 147 | + # Clear mempool |
| 148 | + self.generate(self.wallet, 1, sync_fun=self.no_op) |
| 149 | + |
96 | 150 | def test_blockmintxfee_parameter(self):
|
97 | 151 | self.log.info("Test -blockmintxfee setting")
|
98 | 152 | self.restart_node(0, extra_args=['-minrelaytxfee=0', '-persistmempool=0'])
|
@@ -533,6 +587,7 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
|
533 | 587 | node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex())
|
534 | 588 | assert_equal(node.submitblock(hexdata=block.serialize().hex()), 'duplicate') # valid
|
535 | 589 |
|
| 590 | + self.test_fees_and_sigops() |
536 | 591 | self.test_blockmintxfee_parameter()
|
537 | 592 | self.test_block_max_weight()
|
538 | 593 | self.test_timewarp()
|
|
0 commit comments