v30.3-roots.1 · Commit 3: [PATCH 03/68] feat(policy): preserve Roots relay and network controls on Core 30.3
test/functional/mempool_datacarrier.py
Before: test/functional/mempool_datacarrier.py · After: test/functional/mempool_datacarrier.py
File metadata
index ca113fcbcebbf936bb37bff50f3c479950586e31..ca7265d832c6a05c03bb91661bbb3d6c0b08de3e 100755
Download original patch · Release notes
Diff rows 1–74 of 74. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/mempool_datacarrier.py
CHANGED
|
@@ -3,9 +3,9 @@
|
|
| 3 |
# Distributed under the MIT software license, see the accompanying
|
| 4 |
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
"""Test datacarrier functionality"""
|
|
|
|
| 6 |
from test_framework.messages import (
|
| 7 |
CTxOut,
|
| 8 |
-
MAX_OP_RETURN_RELAY,
|
| 9 |
)
|
| 10 |
from test_framework.script import (
|
| 11 |
CScript,
|
|
@@ -28,13 +28,13 @@ class DataCarrierTest(BitcoinTestFramework):
|
|
| 28 |
def set_test_params(self):
|
| 29 |
self.num_nodes = 4
|
| 30 |
self.extra_args = [
|
| 31 |
-
[], # default is uncapped
|
| 32 |
["-datacarrier=0"], # no relay of datacarrier
|
| 33 |
["-datacarrier=1", f"-datacarriersize={CUSTOM_DATACARRIER_ARG}"],
|
| 34 |
["-datacarrier=1", "-datacarriersize=2"],
|
| 35 |
]
|
| 36 |
|
| 37 |
-
def test_null_data_transaction(self, node: TestNode, data, success: bool) -> None:
|
| 38 |
tx = self.wallet.create_self_transfer(fee_rate=0)["tx"]
|
| 39 |
data = [] if data is None else [data]
|
| 40 |
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN] + data)))
|
|
@@ -47,31 +47,32 @@ class DataCarrierTest(BitcoinTestFramework):
|
|
| 47 |
assert tx.txid_hex in node.getrawmempool(True), f'{tx_hex} not in mempool'
|
| 48 |
else:
|
| 49 |
assert_raises_rpc_error(-26, "datacarrier", self.wallet.sendrawtransaction, from_node=node, tx_hex=tx_hex)
|
|
|
|
| 50 |
|
| 51 |
def run_test(self):
|
| 52 |
self.wallet = MiniWallet(self.nodes[0])
|
| 53 |
|
| 54 |
-
# Test that bare multisig is allowed by default. Do it here rather than create a new test for it.
|
| 55 |
-
assert_equal(self.nodes[0].getmempoolinfo()["permitbaremultisig"], True)
|
| 56 |
|
| 57 |
-
assert_equal(self.nodes[0].getmempoolinfo()["maxdatacarriersize"], MAX_OP_RETURN_RELAY)
|
| 58 |
assert_equal(self.nodes[1].getmempoolinfo()["maxdatacarriersize"], 0)
|
| 59 |
assert_equal(self.nodes[2].getmempoolinfo()["maxdatacarriersize"], CUSTOM_DATACARRIER_ARG)
|
| 60 |
assert_equal(self.nodes[3].getmempoolinfo()["maxdatacarriersize"], 2)
|
| 61 |
|
| 62 |
-
# By default, any size is allowed.
|
| 63 |
|
| 64 |
# If it is custom set to 83, the historical value,
|
| 65 |
# only 80 bytes are used for data (+1 for OP_RETURN, +2 for the pushdata opcodes).
|
| 66 |
custom_size_data = randbytes(CUSTOM_DATACARRIER_ARG - 3)
|
| 67 |
too_long_data = randbytes(CUSTOM_DATACARRIER_ARG - 2)
|
| 68 |
-
extremely_long_data = randbytes(MAX_OP_RETURN_RELAY - 200)
|
| 69 |
one_byte = randbytes(1)
|
| 70 |
zero_bytes = randbytes(0)
|
| 71 |
|
| 72 |
-
self.log.info("Testing a null data transaction succeeds for default arg regardless of size.")
|
| 73 |
-
self.test_null_data_transaction(node=self.nodes[0], data=too_long_data, success=True)
|
| 74 |
-
self.test_null_data_transaction(node=self.nodes[0], data=extremely_long_data, success=True)
|
|
|
|
|
|
|
| 75 |
|
| 76 |
self.log.info("Testing a null data transaction with -datacarrier=false.")
|
| 77 |
self.test_null_data_transaction(node=self.nodes[1], data=custom_size_data, success=False)
|
|
@@ -100,5 +101,9 @@ class DataCarrierTest(BitcoinTestFramework):
|
|
| 100 |
self.test_null_data_transaction(node=self.nodes[2], data=one_byte, success=True)
|
| 101 |
self.test_null_data_transaction(node=self.nodes[3], data=one_byte, success=False)
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
if __name__ == '__main__':
|
| 104 |
DataCarrierTest(__file__).main()
|
|
|
|
| 3 |
# Distributed under the MIT software license, see the accompanying
|
| 4 |
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
"""Test datacarrier functionality"""
|
| 6 |
+
from test_framework.blocktools import MAX_STANDARD_TX_WEIGHT
|
| 7 |
from test_framework.messages import (
|
| 8 |
CTxOut,
|
|
|
|
| 9 |
)
|
| 10 |
from test_framework.script import (
|
| 11 |
CScript,
|
|
|
|
| 28 |
def set_test_params(self):
|
| 29 |
self.num_nodes = 4
|
| 30 |
self.extra_args = [
|
| 31 |
+
[], # default aggregate size is 83 bytes
|
| 32 |
["-datacarrier=0"], # no relay of datacarrier
|
| 33 |
["-datacarrier=1", f"-datacarriersize={CUSTOM_DATACARRIER_ARG}"],
|
| 34 |
["-datacarrier=1", "-datacarriersize=2"],
|
| 35 |
]
|
| 36 |
|
| 37 |
+
def test_null_data_transaction(self, node: TestNode, data, success: bool) -> str:
|
| 38 |
tx = self.wallet.create_self_transfer(fee_rate=0)["tx"]
|
| 39 |
data = [] if data is None else [data]
|
| 40 |
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN] + data)))
|
|
|
|
| 47 |
assert tx.txid_hex in node.getrawmempool(True), f'{tx_hex} not in mempool'
|
| 48 |
else:
|
| 49 |
assert_raises_rpc_error(-26, "datacarrier", self.wallet.sendrawtransaction, from_node=node, tx_hex=tx_hex)
|
| 50 |
+
return tx_hex
|
| 51 |
|
| 52 |
def run_test(self):
|
| 53 |
self.wallet = MiniWallet(self.nodes[0])
|
| 54 |
|
| 55 |
+
# Roots rejects bare multisig by default; report the actual configured policy.
|
| 56 |
+
assert_equal(self.nodes[0].getmempoolinfo()["permitbaremultisig"], False)
|
| 57 |
|
| 58 |
+
assert_equal(self.nodes[0].getmempoolinfo()["maxdatacarriersize"], CUSTOM_DATACARRIER_ARG)
|
| 59 |
assert_equal(self.nodes[1].getmempoolinfo()["maxdatacarriersize"], 0)
|
| 60 |
assert_equal(self.nodes[2].getmempoolinfo()["maxdatacarriersize"], CUSTOM_DATACARRIER_ARG)
|
| 61 |
assert_equal(self.nodes[3].getmempoolinfo()["maxdatacarriersize"], 2)
|
| 62 |
|
|
|
|
| 63 |
|
| 64 |
# If it is custom set to 83, the historical value,
|
| 65 |
# only 80 bytes are used for data (+1 for OP_RETURN, +2 for the pushdata opcodes).
|
| 66 |
custom_size_data = randbytes(CUSTOM_DATACARRIER_ARG - 3)
|
| 67 |
too_long_data = randbytes(CUSTOM_DATACARRIER_ARG - 2)
|
|
|
|
| 68 |
one_byte = randbytes(1)
|
| 69 |
zero_bytes = randbytes(0)
|
| 70 |
|
| 71 |
+
self.log.info("Testing null data with the default 83-byte aggregate limit.")
|
| 72 |
+
self.test_null_data_transaction(node=self.nodes[0], data=custom_size_data, success=True)
|
| 73 |
+
rejected_tx = self.test_null_data_transaction(node=self.nodes[0], data=too_long_data, success=False)
|
| 74 |
+
# Relay limits do not alter block validity.
|
| 75 |
+
self.generateblock(self.nodes[0], output="raw(42)", transactions=[rejected_tx], sync_fun=self.no_op)
|
| 76 |
|
| 77 |
self.log.info("Testing a null data transaction with -datacarrier=false.")
|
| 78 |
self.test_null_data_transaction(node=self.nodes[1], data=custom_size_data, success=False)
|
|
|
|
| 101 |
self.test_null_data_transaction(node=self.nodes[2], data=one_byte, success=True)
|
| 102 |
self.test_null_data_transaction(node=self.nodes[3], data=one_byte, success=False)
|
| 103 |
|
| 104 |
+
self.log.info("Testing an explicit large data-carrier limit below the standard transaction weight boundary.")
|
| 105 |
+
self.restart_node(0, extra_args=["-datacarriersize=100000", "-maxscriptsize=100000", "-datacarriercost=1"])
|
| 106 |
+
self.test_null_data_transaction(node=self.nodes[0], data=randbytes(MAX_STANDARD_TX_WEIGHT // 4 - 200), success=True)
|
| 107 |
+
|
| 108 |
if __name__ == '__main__':
|
| 109 |
DataCarrierTest(__file__).main()
|