Skip to content

Commit 9ef00c3

Browse files
committed
Merge pull request #5958
231072f [QA] add multisig rpc tests (Jonas Schnelli)
2 parents 6a877e8 + 231072f commit 9ef00c3

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

qa/pull-tester/rpc-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ testScripts=(
3131
'proxy_test.py'
3232
'merkle_blocks.py'
3333
'signrawtransactions.py'
34-
# 'forknotify.py'
3534
'maxblocksinflight.py'
3635
'invalidblockrequest.py'
36+
'rawtransactions.py'
37+
# 'forknotify.py'
3738
);
3839
if [ "x${ENABLE_BITCOIND}${ENABLE_UTILS}${ENABLE_WALLET}" = "x111" ]; then
3940
for (( i = 0; i < ${#testScripts[@]}; i++ ))

qa/rpc-tests/rawtransactions.py

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# Create one-input, one-output, no-fee transaction:
1717
class RawTransactionsTest(BitcoinTestFramework):
18-
18+
1919
def setup_chain(self):
2020
print("Initializing test directory "+self.options.tmpdir)
2121
initialize_chain_clean(self.options.tmpdir, 3)
@@ -28,16 +28,16 @@ def setup_network(self, split=False):
2828
#proxy = AuthServiceProxy(url)
2929
#proxy.url = url # store URL on proxy for info
3030
#self.nodes.append(proxy)
31-
31+
3232
connect_nodes_bi(self.nodes,0,1)
3333
connect_nodes_bi(self.nodes,1,2)
3434
connect_nodes_bi(self.nodes,0,2)
35-
35+
3636
self.is_network_split=False
3737
self.sync_all()
38-
38+
3939
def run_test(self):
40-
40+
4141
#prepare some coins for multiple *rawtransaction commands
4242
self.nodes[2].generate(1)
4343
self.nodes[0].generate(101)
@@ -56,14 +56,89 @@ def run_test(self):
5656
outputs = { self.nodes[0].getnewaddress() : 4.998 }
5757
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
5858
rawtx = self.nodes[2].signrawtransaction(rawtx)
59-
59+
6060
errorString = ""
6161
try:
6262
rawtx = self.nodes[2].sendrawtransaction(rawtx['hex'])
6363
except JSONRPCException,e:
6464
errorString = e.error['message']
65+
66+
assert_equal("Missing inputs" in errorString, True);
67+
68+
#########################
69+
# RAW TX MULTISIG TESTS #
70+
#########################
71+
# 2of2 test
72+
addr1 = self.nodes[2].getnewaddress()
73+
addr2 = self.nodes[2].getnewaddress()
74+
75+
addr1Obj = self.nodes[2].validateaddress(addr1)
76+
addr2Obj = self.nodes[2].validateaddress(addr2)
77+
78+
mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
79+
mSigObjValid = self.nodes[2].validateaddress(mSigObj)
80+
81+
#use balance deltas instead of absolute values
82+
bal = self.nodes[2].getbalance()
83+
84+
# send 1.2 BTC to msig adr
85+
txId = self.nodes[0].sendtoaddress(mSigObj, 1.2);
86+
self.sync_all()
87+
self.nodes[0].generate(1)
88+
self.sync_all()
89+
assert_equal(self.nodes[2].getbalance(), bal+Decimal('1.20000000')) #node2 has both keys of the 2of2 ms addr., tx should affect the balance
90+
91+
92+
93+
94+
# 2of3 test from different nodes
95+
bal = self.nodes[2].getbalance()
96+
addr1 = self.nodes[1].getnewaddress()
97+
addr2 = self.nodes[2].getnewaddress()
98+
addr3 = self.nodes[2].getnewaddress()
99+
100+
addr1Obj = self.nodes[1].validateaddress(addr1)
101+
addr2Obj = self.nodes[2].validateaddress(addr2)
102+
addr3Obj = self.nodes[2].validateaddress(addr3)
103+
104+
mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey'], addr3Obj['pubkey']])
105+
mSigObjValid = self.nodes[2].validateaddress(mSigObj)
106+
107+
txId = self.nodes[0].sendtoaddress(mSigObj, 2.2);
108+
decTx = self.nodes[0].gettransaction(txId)
109+
rawTx = self.nodes[0].decoderawtransaction(decTx['hex'])
110+
sPK = rawTx['vout'][0]['scriptPubKey']['hex']
111+
self.sync_all()
112+
self.nodes[0].generate(1)
113+
self.sync_all()
114+
115+
#THIS IS A INCOMPLETE FEATURE
116+
#NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION
117+
assert_equal(self.nodes[2].getbalance(), bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable
118+
119+
txDetails = self.nodes[0].gettransaction(txId, True)
120+
rawTx = self.nodes[0].decoderawtransaction(txDetails['hex'])
121+
vout = False
122+
for outpoint in rawTx['vout']:
123+
if outpoint['value'] == Decimal('2.20000000'):
124+
vout = outpoint
125+
break;
126+
127+
bal = self.nodes[0].getbalance()
128+
inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex']}]
129+
outputs = { self.nodes[0].getnewaddress() : 2.19 }
130+
rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
131+
rawTxPartialSigned = self.nodes[1].signrawtransaction(rawTx, inputs)
132+
assert_equal(rawTxPartialSigned['complete'], False) #node1 only has one key, can't comp. sign the tx
65133

66-
assert_equal("Missing inputs" in errorString, True);
134+
rawTxSigned = self.nodes[2].signrawtransaction(rawTx, inputs)
135+
assert_equal(rawTxSigned['complete'], True) #node2 can sign the tx compl., own two of three keys
136+
self.nodes[2].sendrawtransaction(rawTxSigned['hex'])
137+
rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex'])
138+
self.sync_all()
139+
self.nodes[0].generate(1)
140+
self.sync_all()
141+
assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx
67142

68143
if __name__ == '__main__':
69144
RawTransactionsTest().main()

0 commit comments

Comments
 (0)