qa: Fix some tests to work on native windows

This commit is contained in:
MarcoFalke 2018-03-06 18:43:50 -05:00
parent 8a98dfeebf
commit fa3528a85b
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548
3 changed files with 19 additions and 12 deletions

View File

@ -66,7 +66,9 @@ class MempoolPersistTest(BitcoinTestFramework):
self.log.debug("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions.") self.log.debug("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions.")
self.stop_nodes() self.stop_nodes()
self.start_node(1) # Give this one a head-start, so we can be "extra-sure" that it didn't load anything later # Give this node a head-start, so we can be "extra-sure" that it didn't load anything later
# Also don't store the mempool, to keep the datadir clean
self.start_node(1, extra_args=["-persistmempool=0"])
self.start_node(0) self.start_node(0)
self.start_node(2) self.start_node(2)
# Give bitcoind a second to reload the mempool # Give bitcoind a second to reload the mempool

View File

@ -9,7 +9,6 @@ Roughly based on http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-l
import sys import sys
import socket import socket
import fcntl
import struct import struct
import array import array
import os import os
@ -90,6 +89,8 @@ def all_interfaces():
''' '''
Return all interfaces that are up Return all interfaces that are up
''' '''
import fcntl # Linux only, so only import when required
is_64bits = sys.maxsize > 2**32 is_64bits = sys.maxsize > 2**32
struct_size = 40 if is_64bits else 32 struct_size = 40 if is_64bits else 32
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

View File

@ -7,7 +7,10 @@
import os import os
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, assert_raises_rpc_error) from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)
def read_dump(file_name, addrs, script_addrs, hd_master_addr_old): def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
@ -88,7 +91,8 @@ class WalletDumpTest(BitcoinTestFramework):
self.start_nodes() self.start_nodes()
def run_test (self): def run_test (self):
tmpdir = self.options.tmpdir wallet_unenc_dump = os.path.join(self.nodes[0].datadir, "wallet.unencrypted.dump")
wallet_enc_dump = os.path.join(self.nodes[0].datadir, "wallet.encrypted.dump")
# generate 20 addresses to compare against the dump # generate 20 addresses to compare against the dump
# but since we add a p2sh-p2wpkh address for the first pubkey in the # but since we add a p2sh-p2wpkh address for the first pubkey in the
@ -108,11 +112,11 @@ class WalletDumpTest(BitcoinTestFramework):
script_addrs = [witness_addr, multisig_addr] script_addrs = [witness_addr, multisig_addr]
# dump unencrypted wallet # dump unencrypted wallet
result = self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump") result = self.nodes[0].dumpwallet(wallet_unenc_dump)
assert_equal(result['filename'], os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump")) assert_equal(result['filename'], wallet_unenc_dump)
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc, witness_addr_ret = \ found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc, witness_addr_ret = \
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, script_addrs, None) read_dump(wallet_unenc_dump, addrs, script_addrs, None)
assert_equal(found_addr, test_addr_count) # all keys must be in the dump assert_equal(found_addr, test_addr_count) # all keys must be in the dump
assert_equal(found_script_addr, 2) # all scripts must be in the dump assert_equal(found_script_addr, 2) # all scripts must be in the dump
assert_equal(found_addr_chg, 50) # 50 blocks where mined assert_equal(found_addr_chg, 50) # 50 blocks where mined
@ -125,10 +129,10 @@ class WalletDumpTest(BitcoinTestFramework):
self.nodes[0].walletpassphrase('test', 10) self.nodes[0].walletpassphrase('test', 10)
# Should be a no-op: # Should be a no-op:
self.nodes[0].keypoolrefill() self.nodes[0].keypoolrefill()
self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.encrypted.dump") self.nodes[0].dumpwallet(wallet_enc_dump)
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _, witness_addr_ret = \ found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _, witness_addr_ret = \
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, script_addrs, hd_master_addr_unenc) read_dump(wallet_enc_dump, addrs, script_addrs, hd_master_addr_unenc)
assert_equal(found_addr, test_addr_count) assert_equal(found_addr, test_addr_count)
assert_equal(found_script_addr, 2) assert_equal(found_script_addr, 2)
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
@ -136,7 +140,7 @@ class WalletDumpTest(BitcoinTestFramework):
assert_equal(witness_addr_ret, witness_addr) assert_equal(witness_addr_ret, witness_addr)
# Overwriting should fail # Overwriting should fail
assert_raises_rpc_error(-8, "already exists", self.nodes[0].dumpwallet, tmpdir + "/node0/wallet.unencrypted.dump") assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
# Restart node with new wallet, and test importwallet # Restart node with new wallet, and test importwallet
self.stop_node(0) self.stop_node(0)
@ -146,11 +150,11 @@ class WalletDumpTest(BitcoinTestFramework):
result = self.nodes[0].getaddressinfo(multisig_addr) result = self.nodes[0].getaddressinfo(multisig_addr)
assert(result['ismine'] == False) assert(result['ismine'] == False)
self.nodes[0].importwallet(os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump")) self.nodes[0].importwallet(wallet_unenc_dump)
# Now check IsMine is true # Now check IsMine is true
result = self.nodes[0].getaddressinfo(multisig_addr) result = self.nodes[0].getaddressinfo(multisig_addr)
assert(result['ismine'] == True) assert(result['ismine'] == True)
if __name__ == '__main__': if __name__ == '__main__':
WalletDumpTest().main () WalletDumpTest().main()