forked from namecoin/namecoin-core
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathname_ismine.py
executable file
·88 lines (73 loc) · 3.04 KB
/
name_ismine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# Copyright (c) 2018-2019 Daniel Kraft
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
# RPC test for the "ismine" field in the various name RPCs.
from test_framework.names import NameTestFramework
from test_framework.util import *
class NameIsMineTest (NameTestFramework):
def set_test_params (self):
self.setup_clean_chain = True
self.setup_name_test ([[], ['-namehistory']])
def verifyExpectedIsMineInList (self, arr):
"""
Goes through the array of name info, as returned by name_scan or name_list.
It verifies that exactly the two expected names are there, and the
ismine field matches the expectation for them.
"""
assert_equal (len (arr), 2)
for n in arr:
if n['name'] == "d/a":
assert_equal (n['ismine'], True)
elif n['name'] == "d/b":
assert_equal (n['ismine'], False)
else:
raise AssertionError ("Unexpected name in array: %s" % n['name'])
def run_test (self):
self.node = self.nodes[1]
self.node.generate (110)
# Register two names. One of them is then sent to an address not owned
# by the node and one is updated into a pending operation. That then
# gives us the basic setup to test the "ismine" field in all the
# circumstances.
newA = self.node.name_new ("d/a")
newB = self.node.name_new ("d/b")
self.node.generate (10)
self.firstupdateName (1, "d/a", newA, "value")
self.firstupdateName (1, "d/b", newB, "value")
self.node.generate (5)
otherAddr = self.nodes[0].getnewaddress ()
self.node.name_update ("d/b", "new value", {"destAddress": otherAddr})
self.node.generate (1)
self.node.name_update ("d/a", "new value")
# name_show
assert_equal (self.node.name_show ("d/a")['ismine'], True)
assert_equal (self.node.name_show ("d/b")['ismine'], False)
# name_history
hist = self.node.name_history ("d/a")
assert_equal (len (hist), 1)
assert_equal (hist[0]['ismine'], True)
hist = self.node.name_history ("d/b")
assert_equal (len (hist), 2)
assert_equal (hist[0]['ismine'], True)
assert_equal (hist[1]['ismine'], False)
# name_pending
pending = self.node.name_pending ()
assert_equal (len (pending), 1)
p = pending[0]
assert_equal (p['name'], "d/a")
assert_equal (p['ismine'], True)
# name_scan, name_list
self.verifyExpectedIsMineInList (self.node.name_scan ())
self.verifyExpectedIsMineInList (self.node.name_list ())
# Test the multiwallet situation. If no wallet is specified for the RPC,
# then ismine should not be set at all.
self.node.createwallet ("extra")
defaultRpc = self.node.get_wallet_rpc ("")
extraRpc = self.node.get_wallet_rpc ("extra")
self.verifyExpectedIsMineInList (defaultRpc.name_list ())
for nm in ["d/a", "d/b"]:
assert 'ismine' not in self.node.name_show (nm)
assert_equal (extraRpc.name_show (nm)['ismine'], False)
if __name__ == '__main__':
NameIsMineTest ().main ()