mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge bitcoin/bitcoin#27832: doc: Clarify -datacarriersize, add -datacarriersize=2 tests
faafc35a77doc: Clarify that -datacarriersize applies to the full raw scriptPubKey, not the data push (MarcoFalke)55550e7fe7test: Add -datacarriersize=2 tests (MarcoFalke) Pull request description: Clarify with a test that `-datacarriersize` applies to the serialized size of the scriptPubKey, not the size of the pushed data. So for example, * `-datacarriersize=2` will reject a `raw(6a01aa)`, even though only one byte is pushed * `-datacarriersize=0` (or `-datacarrier=0`) will reject a `raw(6a)`, even though no byte is pushed * `-datacarriersize=0` (or `-datacarrier=0`) will reject a `raw(6a00)`, even though zero bytes are pushed ACKs for top commit: ajtowns: ACKfaafc35a77instagibbs: ACKfaafc35a77Tree-SHA512: f01ace02798f596ac2a02461e9f2a6ef91b3b37c976ea0b3bc860e2d3efb0ace0fd8b779dd18249cee7f84ebbe5fd21d8506afd3a15edadc00b843ff3b4aacc7
This commit is contained in:
@@ -22,16 +22,18 @@ from test_framework.wallet import MiniWallet
|
||||
|
||||
class DataCarrierTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 3
|
||||
self.num_nodes = 4
|
||||
self.extra_args = [
|
||||
[],
|
||||
["-datacarrier=0"],
|
||||
["-datacarrier=1", f"-datacarriersize={MAX_OP_RETURN_RELAY - 1}"]
|
||||
["-datacarrier=1", f"-datacarriersize={MAX_OP_RETURN_RELAY - 1}"],
|
||||
["-datacarrier=1", f"-datacarriersize=2"],
|
||||
]
|
||||
|
||||
def test_null_data_transaction(self, node: TestNode, data: bytes, success: bool) -> None:
|
||||
def test_null_data_transaction(self, node: TestNode, data, success: bool) -> None:
|
||||
tx = self.wallet.create_self_transfer(fee_rate=0)["tx"]
|
||||
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, data])))
|
||||
data = [] if data is None else [data]
|
||||
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN] + data)))
|
||||
tx.vout[0].nValue -= tx.get_vsize() # simply pay 1sat/vbyte fee
|
||||
|
||||
tx_hex = tx.serialize().hex()
|
||||
@@ -49,6 +51,8 @@ class DataCarrierTest(BitcoinTestFramework):
|
||||
default_size_data = random_bytes(MAX_OP_RETURN_RELAY - 3)
|
||||
too_long_data = random_bytes(MAX_OP_RETURN_RELAY - 2)
|
||||
small_data = random_bytes(MAX_OP_RETURN_RELAY - 4)
|
||||
one_byte = random_bytes(1)
|
||||
zero_bytes = random_bytes(0)
|
||||
|
||||
self.log.info("Testing null data transaction with default -datacarrier and -datacarriersize values.")
|
||||
self.test_null_data_transaction(node=self.nodes[0], data=default_size_data, success=True)
|
||||
@@ -65,6 +69,24 @@ class DataCarrierTest(BitcoinTestFramework):
|
||||
self.log.info("Testing a null data transaction with a size smaller than accepted by -datacarriersize.")
|
||||
self.test_null_data_transaction(node=self.nodes[2], data=small_data, success=True)
|
||||
|
||||
self.log.info("Testing a null data transaction with no data.")
|
||||
self.test_null_data_transaction(node=self.nodes[0], data=None, success=True)
|
||||
self.test_null_data_transaction(node=self.nodes[1], data=None, success=False)
|
||||
self.test_null_data_transaction(node=self.nodes[2], data=None, success=True)
|
||||
self.test_null_data_transaction(node=self.nodes[3], data=None, success=True)
|
||||
|
||||
self.log.info("Testing a null data transaction with zero bytes of data.")
|
||||
self.test_null_data_transaction(node=self.nodes[0], data=zero_bytes, success=True)
|
||||
self.test_null_data_transaction(node=self.nodes[1], data=zero_bytes, success=False)
|
||||
self.test_null_data_transaction(node=self.nodes[2], data=zero_bytes, success=True)
|
||||
self.test_null_data_transaction(node=self.nodes[3], data=zero_bytes, success=True)
|
||||
|
||||
self.log.info("Testing a null data transaction with one byte of data.")
|
||||
self.test_null_data_transaction(node=self.nodes[0], data=one_byte, success=True)
|
||||
self.test_null_data_transaction(node=self.nodes[1], data=one_byte, success=False)
|
||||
self.test_null_data_transaction(node=self.nodes[2], data=one_byte, success=True)
|
||||
self.test_null_data_transaction(node=self.nodes[3], data=one_byte, success=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
DataCarrierTest().main()
|
||||
|
||||
Reference in New Issue
Block a user