Skip to content

Commit 21704f6

Browse files
committed
Check stderr when testing bitcoin-tx
1 parent eb66bf9 commit 21704f6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

test/util/bctest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ def bctest(testDir, testObj, buildenv):
102102
logging.error("Return code mismatch for " + outputFn)
103103
raise Exception
104104

105+
if "error_txt" in testObj:
106+
want_error = testObj["error_txt"]
107+
# Compare error text
108+
# TODO: ideally, we'd compare the strings exactly and also assert
109+
# That stderr is empty if no errors are expected. However, bitcoin-tx
110+
# emits DISPLAY errors when running as a windows application on
111+
# linux through wine. Just assert that the expected error text appears
112+
# somewhere in stderr.
113+
if want_error not in outs[1]:
114+
logging.error("Error mismatch:\n" + "Expected: " + want_error + "\nReceived: " + outs[1].rstrip())
115+
raise Exception
116+
105117
def bctester(testDir, input_basename, buildenv):
106118
""" Loads and parses the input file, runs all tests and reports results"""
107119
input_filename = testDir + "/" + input_basename

test/util/data/bitcoin-util-test.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"args": ["-", "delin=31"],
4343
"input": "tx394b54bb.hex",
4444
"return_code": 1,
45+
"error_txt": "error: Invalid TX input index '31'",
4546
"description": "Attempts to delete an input with a bad index from a transaction. Expected to fail."
4647
},
4748
{ "exec": "./bitcoin-tx",
@@ -60,6 +61,7 @@
6061
"args": ["-", "delout=2"],
6162
"input": "tx394b54bb.hex",
6263
"return_code": 1,
64+
"error_txt": "error: Invalid TX output index '2'",
6365
"description": "Attempts to delete an output with a bad index from a transaction. Expected to fail."
6466
},
6567
{ "exec": "./bitcoin-tx",
@@ -233,6 +235,7 @@
233235
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
234236
"outdata=4:badhexdata"],
235237
"return_code": 1,
238+
"error_txt": "error: invalid TX output data",
236239
"description": "Attempts to create a new transaction with one input and an output with malformed hex data. Expected to fail"
237240
},
238241
{ "exec": "./bitcoin-tx",
@@ -241,6 +244,7 @@
241244
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
242245
"outdata=badhexdata"],
243246
"return_code": 1,
247+
"error_txt": "error: invalid TX output data",
244248
"description": "Attempts to create a new transaction with one input and an output with no value and malformed hex data. Expected to fail"
245249
},
246250
{ "exec": "./bitcoin-tx",

0 commit comments

Comments
 (0)