22
22
23
23
class DataCarrierTest (BitcoinTestFramework ):
24
24
def set_test_params (self ):
25
- self .num_nodes = 3
25
+ self .num_nodes = 4
26
26
self .extra_args = [
27
27
[],
28
28
["-datacarrier=0" ],
29
- ["-datacarrier=1" , f"-datacarriersize={ MAX_OP_RETURN_RELAY - 1 } " ]
29
+ ["-datacarrier=1" , f"-datacarriersize={ MAX_OP_RETURN_RELAY - 1 } " ],
30
+ ["-datacarrier=1" , f"-datacarriersize=2" ],
30
31
]
31
32
32
- def test_null_data_transaction (self , node : TestNode , data : bytes , success : bool ) -> None :
33
+ def test_null_data_transaction (self , node : TestNode , data , success : bool ) -> None :
33
34
tx = self .wallet .create_self_transfer (fee_rate = 0 )["tx" ]
34
- tx .vout .append (CTxOut (nValue = 0 , scriptPubKey = CScript ([OP_RETURN , data ])))
35
+ data = [] if data is None else [data ]
36
+ tx .vout .append (CTxOut (nValue = 0 , scriptPubKey = CScript ([OP_RETURN ] + data )))
35
37
tx .vout [0 ].nValue -= tx .get_vsize () # simply pay 1sat/vbyte fee
36
38
37
39
tx_hex = tx .serialize ().hex ()
@@ -49,6 +51,8 @@ def run_test(self):
49
51
default_size_data = random_bytes (MAX_OP_RETURN_RELAY - 3 )
50
52
too_long_data = random_bytes (MAX_OP_RETURN_RELAY - 2 )
51
53
small_data = random_bytes (MAX_OP_RETURN_RELAY - 4 )
54
+ one_byte = random_bytes (1 )
55
+ zero_bytes = random_bytes (0 )
52
56
53
57
self .log .info ("Testing null data transaction with default -datacarrier and -datacarriersize values." )
54
58
self .test_null_data_transaction (node = self .nodes [0 ], data = default_size_data , success = True )
@@ -65,6 +69,24 @@ def run_test(self):
65
69
self .log .info ("Testing a null data transaction with a size smaller than accepted by -datacarriersize." )
66
70
self .test_null_data_transaction (node = self .nodes [2 ], data = small_data , success = True )
67
71
72
+ self .log .info ("Testing a null data transaction with no data." )
73
+ self .test_null_data_transaction (node = self .nodes [0 ], data = None , success = True )
74
+ self .test_null_data_transaction (node = self .nodes [1 ], data = None , success = False )
75
+ self .test_null_data_transaction (node = self .nodes [2 ], data = None , success = True )
76
+ self .test_null_data_transaction (node = self .nodes [3 ], data = None , success = True )
77
+
78
+ self .log .info ("Testing a null data transaction with zero bytes of data." )
79
+ self .test_null_data_transaction (node = self .nodes [0 ], data = zero_bytes , success = True )
80
+ self .test_null_data_transaction (node = self .nodes [1 ], data = zero_bytes , success = False )
81
+ self .test_null_data_transaction (node = self .nodes [2 ], data = zero_bytes , success = True )
82
+ self .test_null_data_transaction (node = self .nodes [3 ], data = zero_bytes , success = True )
83
+
84
+ self .log .info ("Testing a null data transaction with one byte of data." )
85
+ self .test_null_data_transaction (node = self .nodes [0 ], data = one_byte , success = True )
86
+ self .test_null_data_transaction (node = self .nodes [1 ], data = one_byte , success = False )
87
+ self .test_null_data_transaction (node = self .nodes [2 ], data = one_byte , success = True )
88
+ self .test_null_data_transaction (node = self .nodes [3 ], data = one_byte , success = False )
89
+
68
90
69
91
if __name__ == '__main__' :
70
92
DataCarrierTest ().main ()
0 commit comments