Skip to content

Commit

Permalink
test: Check wallet name in -walletnotify script
Browse files Browse the repository at this point in the history
  • Loading branch information
promag authored and ryanofsky committed Jan 31, 2020
1 parent 9a5b5ee commit 4e9efac
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions test/functional/feature_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@
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):
self.num_nodes = 2
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")
Expand All @@ -33,7 +44,8 @@ def setup_network(self):
"-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):
Expand All @@ -53,7 +65,7 @@ def run_test(self):
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):
Expand All @@ -67,7 +79,7 @@ def run_test(self):
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
Expand Down

0 comments on commit 4e9efac

Please sign in to comment.