forked from litecoin-project/litecoin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mweb_basic.py
109 lines (87 loc) · 4.13 KB
/
mweb_basic.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
#!/usr/bin/env python3
# Copyright (c) 2021 The Litecoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Basic MWEB test"""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
class MWEBBasicTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self):
self.log.info("Create all pre-MWEB blocks")
self.nodes[0].generate(431)
self.log.info("Pegin some coins")
addr0 = self.nodes[0].getnewaddress(address_type='mweb')
self.nodes[0].sendtoaddress(addr0, 10)
self.log.info("Create some blocks - activate MWEB")
self.nodes[0].generate(10)
self.sync_all()
self.log.info("Check for MWEB UTXOs")
utxos = [x for x in self.nodes[0].listunspent() if x['address'].startswith('tmweb')]
assert_equal(len(utxos), 2)
utxos.sort(key=lambda x: x['amount'])
utxo0 = utxos[0]
utxo1 = utxos[1]
if utxos[0]['address'] != addr0:
utxo0 = utxos[1]
utxo1 = utxos[0]
assert utxo0['amount'] == 10 and utxo0['address'] == addr0
assert 2 < utxo1['amount'] < 2.5 # change from single 12.5 LTC coinbase being spent
self.log.info("Send MWEB coins to node 1")
addr1 = self.nodes[1].getnewaddress(address_type='mweb')
tx1_hash = self.nodes[0].sendtoaddress(addr1, 5)
tx1 = self.nodes[0].getmempoolentry(tx1_hash)
self.log.info("tx1: {}".format(tx1))
self.nodes[0].generate(1)
self.sync_all()
self.log.info("Check MWEB coins are spent on node 0")
utxos = [x for x in self.nodes[0].listunspent() if x['address'].startswith('tmweb')]
assert_equal(len(utxos), 2)
assert sum(x['amount'] for x in utxos) < 45
self.log.info("Check for MWEB UTXO on node 1")
utxos = [x for x in self.nodes[1].listunspent() if x['address'].startswith('tmweb')]
assert_equal(len(utxos), 1)
assert utxos[0]['amount'] == 5 and utxos[0]['address'] == addr1
self.log.info("Send MWEB coins to node 0")
self.nodes[1].sendtoaddress(addr0, 2)
self.sync_all()
self.nodes[0].generate(1)
self.sync_all()
self.log.info("Check MWEB coins are spent on node 1")
utxos = [x for x in self.nodes[1].listunspent() if x['address'].startswith('tmweb')]
assert_equal(len(utxos), 1)
assert sum(x['amount'] for x in utxos) < 3
self.log.info("UTXO amount: {}".format(utxos[0]['amount']))
self.log.info("Check for MWEB UTXO on node 0")
utxos = self.nodes[0].listunspent(addresses=[addr0])
assert_equal(len(utxos), 1)
assert utxos[0]['amount'] == 2 and utxos[0]['address'] == addr0
self.log.info("Pegout coins on node 1")
addr2 = self.nodes[1].getnewaddress()
self.nodes[1].sendtoaddress(addr2, 2)
self.sync_all()
self.nodes[1].generate(1)
self.sync_all()
self.log.info("Check MWEB coins are spent on node 1")
utxos = [x for x in self.nodes[1].listunspent() if x['address'].startswith('tmweb')]
assert_equal(len(utxos), 1)
assert sum(x['amount'] for x in utxos) < 1
self.log.info("Mine 5 blocks. Peg-out maturity is 6 blocks, so coins shouldn't be available yet.")
self.nodes[1].generate(5)
self.sync_all()
self.log.info("Check for UTXO on node 1")
utxos = self.nodes[1].listunspent(addresses=[addr2])
assert_equal(len(utxos), 0)
self.log.info("Mine 1 more block. Peg-out coins should mature.")
self.nodes[1].generate(1)
self.sync_all()
self.log.info("Check for UTXO on node 1")
utxos = self.nodes[1].listunspent(addresses=[addr2])
assert_equal(len(utxos), 1)
assert utxos[0]['amount'] == 2 and utxos[0]['address'] == addr2
if __name__ == '__main__':
MWEBBasicTest().main()