|
3 | 3 | # Distributed under the MIT software license, see the accompanying
|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 |
|
6 |
| -from subprocess import check_output |
7 |
| -import json |
8 |
| - |
| 6 | +import subprocess |
9 | 7 | import os
|
| 8 | +import json |
| 9 | +import sys |
| 10 | +import buildenv |
| 11 | +import shutil |
10 | 12 |
|
11 | 13 | def assert_equal(thing1, thing2):
|
12 | 14 | if thing1 != thing2:
|
13 | 15 | raise AssertionError("%s != %s"%(str(thing1),str(thing2)))
|
14 | 16 |
|
15 | 17 | if __name__ == '__main__':
|
16 | 18 | datadir = os.environ["srcdir"] + "/test/data"
|
17 |
| - command = os.environ["srcdir"] + "/wallet-utility" |
18 |
| - |
19 |
| - output = json.loads(check_output([command, "-datadir=" + datadir])) |
20 |
| - |
21 |
| - assert_equal(output[0], "13EngsxkRi7SJPPqCyJsKf34U8FoX9E9Av"); |
22 |
| - assert_equal(output[1], "1FKCLGTpPeYBUqfNxktck8k5nqxB8sjim8"); |
23 |
| - assert_equal(output[2], "13cdtE9tnNeXCZJ8KQ5WELgEmLSBLnr48F"); |
24 |
| - |
25 |
| - |
26 |
| - |
| 19 | + execprog = './wallet-utility' + buildenv.exeext |
| 20 | + execargs = '-datadir=' + datadir |
| 21 | + execrun = execprog + ' ' + execargs |
| 22 | + |
| 23 | + proc = subprocess.Popen(execrun, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True) |
| 24 | + try: |
| 25 | + outs = proc.communicate() |
| 26 | + except OSError: |
| 27 | + print("OSError, Failed to execute " + execprog) |
| 28 | + sys.exit(1) |
| 29 | + |
| 30 | + output = json.loads(outs[0]) |
| 31 | + |
| 32 | + assert_equal(output[0], "13EngsxkRi7SJPPqCyJsKf34U8FoX9E9Av") |
| 33 | + assert_equal(output[1], "1FKCLGTpPeYBUqfNxktck8k5nqxB8sjim8") |
| 34 | + assert_equal(output[2], "13cdtE9tnNeXCZJ8KQ5WELgEmLSBLnr48F") |
| 35 | + |
| 36 | + execargs = '-datadir=' + datadir + ' -dumppass' |
| 37 | + execrun = execprog + ' ' + execargs |
| 38 | + |
| 39 | + proc = subprocess.Popen(execrun, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True) |
| 40 | + try: |
| 41 | + outs = proc.communicate() |
| 42 | + except OSError: |
| 43 | + print("OSError, Failed to execute " + execprog) |
| 44 | + sys.exit(1) |
| 45 | + |
| 46 | + output = json.loads(outs[0]) |
| 47 | + |
| 48 | + assert_equal(output[0]['addr'], "13EngsxkRi7SJPPqCyJsKf34U8FoX9E9Av") |
| 49 | + assert_equal(output[0]['pkey'], "5Jz5BWE2WQxp1hGqDZeisQFV1mRFR2AVBAgiXCbNcZyXNjD9aUd") |
| 50 | + assert_equal(output[1]['addr'], "1FKCLGTpPeYBUqfNxktck8k5nqxB8sjim8") |
| 51 | + assert_equal(output[1]['pkey'], "5HsX2b3v2GjngYQ5ZM4mLp2b2apw6aMNVaPELV1YmpiYR1S4jzc") |
| 52 | + assert_equal(output[2]['addr'], "13cdtE9tnNeXCZJ8KQ5WELgEmLSBLnr48F") |
| 53 | + assert_equal(output[2]['pkey'], "5KCWAs1wX2ESiL4PfDR8XYVSSETHFd2jaRGxt1QdanBFTit4XcH") |
| 54 | + |
| 55 | + if os.path.exists(datadir + '/database'): |
| 56 | + if os.path.isdir(datadir + '/database'): |
| 57 | + shutil.rmtree(datadir + '/database') |
| 58 | + |
| 59 | + if os.path.exists(datadir + '/db.log'): |
| 60 | + os.remove(datadir + '/db.log') |
| 61 | + sys.exit(0) |
0 commit comments