mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
test: Check wallet name in -walletnotify script
This commit is contained in:
parent
9a5b5ee81f
commit
4e9efac678
1 changed files with 15 additions and 3 deletions
|
@ -13,6 +13,16 @@ from test_framework.util import (
|
|||
connect_nodes,
|
||||
)
|
||||
|
||||
# Linux allow all characters other than \x00
|
||||
# Windows disallow control characters (0-31) and /\?%:|"<>
|
||||
FILE_CHAR_START = 32 if os.name == 'nt' else 1
|
||||
FILE_CHAR_END = 128
|
||||
FILE_CHAR_BLACKLIST = '/\\?%*:|"<>' if os.name == 'nt' else '/'
|
||||
|
||||
|
||||
def notify_outputname(walletname, txid):
|
||||
return txid if os.name == 'nt' else '{}_{}'.format(walletname, txid)
|
||||
|
||||
|
||||
class NotificationsTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
|
@ -20,6 +30,7 @@ class NotificationsTest(BitcoinTestFramework):
|
|||
self.setup_clean_chain = True
|
||||
|
||||
def setup_network(self):
|
||||
self.wallet = ''.join(chr(i) for i in range(FILE_CHAR_START, FILE_CHAR_END) if chr(i) not in FILE_CHAR_BLACKLIST)
|
||||
self.alertnotify_dir = os.path.join(self.options.tmpdir, "alertnotify")
|
||||
self.blocknotify_dir = os.path.join(self.options.tmpdir, "blocknotify")
|
||||
self.walletnotify_dir = os.path.join(self.options.tmpdir, "walletnotify")
|
||||
|
@ -33,7 +44,8 @@ class NotificationsTest(BitcoinTestFramework):
|
|||
"-blocknotify=echo > {}".format(os.path.join(self.blocknotify_dir, '%s'))],
|
||||
["-blockversion=211",
|
||||
"-rescan",
|
||||
"-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, '%s'))]]
|
||||
"-wallet={}".format(self.wallet),
|
||||
"-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s')))]]
|
||||
super().setup_network()
|
||||
|
||||
def run_test(self):
|
||||
|
@ -53,7 +65,7 @@ class NotificationsTest(BitcoinTestFramework):
|
|||
wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
|
||||
|
||||
# directory content should equal the generated transaction hashes
|
||||
txids_rpc = list(map(lambda t: t['txid'], self.nodes[1].listtransactions("*", block_count)))
|
||||
txids_rpc = list(map(lambda t: notify_outputname(self.wallet, t['txid']), self.nodes[1].listtransactions("*", block_count)))
|
||||
assert_equal(sorted(txids_rpc), sorted(os.listdir(self.walletnotify_dir)))
|
||||
self.stop_node(1)
|
||||
for tx_file in os.listdir(self.walletnotify_dir):
|
||||
|
@ -67,7 +79,7 @@ class NotificationsTest(BitcoinTestFramework):
|
|||
wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
|
||||
|
||||
# directory content should equal the generated transaction hashes
|
||||
txids_rpc = list(map(lambda t: t['txid'], self.nodes[1].listtransactions("*", block_count)))
|
||||
txids_rpc = list(map(lambda t: notify_outputname(self.wallet, t['txid']), self.nodes[1].listtransactions("*", block_count)))
|
||||
assert_equal(sorted(txids_rpc), sorted(os.listdir(self.walletnotify_dir)))
|
||||
|
||||
# TODO: add test for `-alertnotify` large fork notifications
|
||||
|
|
Loading…
Add table
Reference in a new issue