Skip to content

Commit 0097740

Browse files
committed
refactor: txid to constant in rpc_rawtransaction to isolate tests
1 parent 8c19d13 commit 0097740

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

test/functional/rpc_rawtransaction.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
)
2929

3030

31+
TXID = "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000"
32+
33+
3134
class multidict(dict):
3235
"""Dictionary that allows duplicate keys.
3336
@@ -96,24 +99,23 @@ def run_test(self):
9699
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, [], {}, 0, False, 'foo')
97100

98101
# Test `createrawtransaction` invalid `inputs`
99-
txid = '1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000'
100102
assert_raises_rpc_error(-3, "Expected type array", self.nodes[0].createrawtransaction, 'foo', {})
101103
assert_raises_rpc_error(-1, "JSON value is not an object as expected", self.nodes[0].createrawtransaction, ['foo'], {})
102104
assert_raises_rpc_error(-1, "JSON value is not a string as expected", self.nodes[0].createrawtransaction, [{}], {})
103105
assert_raises_rpc_error(-8, "txid must be of length 64 (not 3, for 'foo')", self.nodes[0].createrawtransaction, [{'txid': 'foo'}], {})
104106
assert_raises_rpc_error(-8, "txid must be hexadecimal string (not 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844')", self.nodes[0].createrawtransaction, [{'txid': 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844'}], {})
105-
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid}], {})
106-
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 'foo'}], {})
107-
assert_raises_rpc_error(-8, "Invalid parameter, vout cannot be negative", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': -1}], {})
107+
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': TXID}], {})
108+
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': TXID, 'vout': 'foo'}], {})
109+
assert_raises_rpc_error(-8, "Invalid parameter, vout cannot be negative", self.nodes[0].createrawtransaction, [{'txid': TXID, 'vout': -1}], {})
108110
# sequence number out of range
109111
for invalid_seq in [-1, 4294967296]:
110-
inputs = [{'txid': txid, 'vout': 1, 'sequence': invalid_seq}]
112+
inputs = [{'txid': TXID, 'vout': 1, 'sequence': invalid_seq}]
111113
outputs = {self.nodes[0].getnewaddress(): 1}
112114
assert_raises_rpc_error(-8, 'Invalid parameter, sequence number is out of range',
113115
self.nodes[0].createrawtransaction, inputs, outputs)
114116
# with valid sequence number
115117
for valid_seq in [1000, 4294967294]:
116-
inputs = [{'txid': txid, 'vout': 1, 'sequence': valid_seq}]
118+
inputs = [{'txid': TXID, 'vout': 1, 'sequence': valid_seq}]
117119
outputs = {self.nodes[0].getnewaddress(): 1}
118120
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
119121
decrawtx = self.nodes[0].decoderawtransaction(rawtx)
@@ -146,25 +148,25 @@ def run_test(self):
146148

147149
self.log.info('Check that createrawtransaction accepts an array and object as outputs')
148150
# One output
149-
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs={address: 99}))
151+
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs={address: 99}))
150152
assert_equal(len(tx.vout), 1)
151153
assert_equal(
152154
tx.serialize().hex(),
153-
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[{address: 99}]),
155+
self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=[{address: 99}]),
154156
)
155157
# Two outputs
156-
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=OrderedDict([(address, 99), (address2, 99)])))
158+
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=OrderedDict([(address, 99), (address2, 99)])))
157159
assert_equal(len(tx.vout), 2)
158160
assert_equal(
159161
tx.serialize().hex(),
160-
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[{address: 99}, {address2: 99}]),
162+
self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=[{address: 99}, {address2: 99}]),
161163
)
162164
# Multiple mixed outputs
163-
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=multidict([(address, 99), (address2, 99), ('data', '99')])))
165+
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=multidict([(address, 99), (address2, 99), ('data', '99')])))
164166
assert_equal(len(tx.vout), 3)
165167
assert_equal(
166168
tx.serialize().hex(),
167-
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[{address: 99}, {address2: 99}, {'data': '99'}]),
169+
self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=[{address: 99}, {address2: 99}, {'data': '99'}]),
168170
)
169171

170172
for type in ["bech32", "p2sh-segwit", "legacy"]:
@@ -175,11 +177,11 @@ def run_test(self):
175177
self.log.info('sendrawtransaction with missing prevtx info (%s)' %(type))
176178

177179
# Test `signrawtransactionwithwallet` invalid `prevtxs`
178-
inputs = [ {'txid' : txid, 'vout' : 3, 'sequence' : 1000}]
180+
inputs = [ {'txid' : TXID, 'vout' : 3, 'sequence' : 1000}]
179181
outputs = { self.nodes[0].getnewaddress() : 1 }
180182
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
181183

182-
prevtx = dict(txid=txid, scriptPubKey=pubkey, vout=3, amount=1)
184+
prevtx = dict(txid=TXID, scriptPubKey=pubkey, vout=3, amount=1)
183185
succ = self.nodes[0].signrawtransactionwithwallet(rawtx, [prevtx])
184186
assert succ["complete"]
185187
if type == "legacy":
@@ -190,15 +192,15 @@ def run_test(self):
190192
if type != "legacy":
191193
assert_raises_rpc_error(-3, "Missing amount", self.nodes[0].signrawtransactionwithwallet, rawtx, [
192194
{
193-
"txid": txid,
195+
"txid": TXID,
194196
"scriptPubKey": pubkey,
195197
"vout": 3,
196198
}
197199
])
198200

199201
assert_raises_rpc_error(-3, "Missing vout", self.nodes[0].signrawtransactionwithwallet, rawtx, [
200202
{
201-
"txid": txid,
203+
"txid": TXID,
202204
"scriptPubKey": pubkey,
203205
"amount": 1,
204206
}
@@ -212,7 +214,7 @@ def run_test(self):
212214
])
213215
assert_raises_rpc_error(-3, "Missing scriptPubKey", self.nodes[0].signrawtransactionwithwallet, rawtx, [
214216
{
215-
"txid": txid,
217+
"txid": TXID,
216218
"vout": 3,
217219
"amount": 1
218220
}
@@ -223,7 +225,7 @@ def run_test(self):
223225
#########################################
224226

225227
self.log.info('sendrawtransaction with missing input')
226-
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1}] #won't exists
228+
inputs = [{'txid' : TXID, 'vout' : 1}] # won't exist
227229
outputs = { self.nodes[0].getnewaddress() : 4.998 }
228230
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
229231
rawtx = self.nodes[2].signrawtransactionwithwallet(rawtx)

0 commit comments

Comments
 (0)