forked from namecoin/namecoin-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
name_pending.py
executable file
·115 lines (92 loc) · 3.86 KB
/
name_pending.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
# Copyright (c) 2015-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 name_pending call.
from test_framework.names import NameTestFramework
from test_framework.util import *
class NamePendingTest (NameTestFramework):
def set_test_params (self):
self.setup_name_test ([[]] * 2)
def run_test (self):
node = self.nodes[0]
# Register a name that can then be update'd in the mempool.
newData = node.name_new ("a")
node.generate (10)
self.firstupdateName (0, "a", newData, "old-value-a")
node.generate (10)
# Start a new name registration so we can first_update it.
newData = node.name_new ("b")
node.generate (15)
# Perform the unconfirmed updates. Include a currency transaction
# and a name_new to check that those are not shown.
txa = node.name_update ("a", "value-a")
txb = self.firstupdateName (0, "b", newData, "value-b")
addrOther = self.nodes[1].getnewaddress ()
node.sendtoaddress (addrOther, 1)
newData = node.name_new ("c")
# Check that name_show still returns the old value.
self.checkName (0, "a", "old-value-a", None, False)
# Check sizes of mempool against name_pending.
mempool = node.getrawmempool ()
assert_equal (len (mempool), 4)
pending = node.name_pending ()
assert_equal (len (pending), 2)
# Check result of full name_pending (called above).
for op in pending:
assert op['txid'] in mempool
if op['name'] == 'a':
assert_equal (op['op'], 'name_update')
assert_equal (op['value'], 'value-a')
assert_equal (op['txid'], txa)
elif op['name'] == 'b':
assert_equal (op['op'], 'name_firstupdate')
assert_equal (op['value'], 'value-b')
assert_equal (op['txid'], txb)
else:
assert False
# Check name_pending with name filter that does not match any name.
pending = node.name_pending ('does not exist')
assert_equal (pending, [])
# Check name_pending with name filter.
self.checkPendingName (0, 'a', 'name_update', 'value-a', txa)
# We don't know the golden value for vout, as this is randomised. But we
# can store the output now and then verify it with name_show after the
# update has been mined.
pending = node.name_pending ('a')
assert_equal (len (pending), 1)
pending = pending[0]
assert 'vout' in pending
# Mine a block and check that all mempool is cleared.
node.generate (1)
assert_equal (node.getrawmempool (), [])
assert_equal (node.name_pending (), [])
# Verify vout from before against name_show.
confirmed = node.name_show ('a')
assert_equal (pending['vout'], confirmed['vout'])
# Send a name and check that ismine is handled correctly.
tx = node.name_update ('a', 'sent-a', {"destAddress": addrOther})
self.sync_mempools ()
self.checkPendingName (0, 'a', 'name_update', 'sent-a', tx, False)
self.checkPendingName (1, 'a', 'name_update', 'sent-a', tx, True)
def checkPendingName (self, ind, name, op, value, txid, mine=None):
"""
Call name_pending on a given name and check that the result
matches the expected values.
"""
res = self.nodes[ind].name_pending (name)
assert_equal (len (res), 1)
obj = res[0]
assert_equal (obj['op'], op)
assert_equal (obj['name'], name)
assert_equal (obj['value'], value)
assert_equal (obj['txid'], txid)
assert isinstance (obj['ismine'], bool)
if mine is not None:
assert_equal (obj['ismine'], mine)
# There is no golden value for vout, but we can decode the transaction
# to make sure it is correct.
rawtx = self.nodes[ind].getrawtransaction (txid, 1)
assert 'nameOp' in rawtx['vout'][obj['vout']]['scriptPubKey']
if __name__ == '__main__':
NamePendingTest ().main ()