15
15
16
16
# Create one-input, one-output, no-fee transaction:
17
17
class RawTransactionsTest (BitcoinTestFramework ):
18
-
18
+
19
19
def setup_chain (self ):
20
20
print ("Initializing test directory " + self .options .tmpdir )
21
21
initialize_chain_clean (self .options .tmpdir , 3 )
@@ -28,16 +28,16 @@ def setup_network(self, split=False):
28
28
#proxy = AuthServiceProxy(url)
29
29
#proxy.url = url # store URL on proxy for info
30
30
#self.nodes.append(proxy)
31
-
31
+
32
32
connect_nodes_bi (self .nodes ,0 ,1 )
33
33
connect_nodes_bi (self .nodes ,1 ,2 )
34
34
connect_nodes_bi (self .nodes ,0 ,2 )
35
-
35
+
36
36
self .is_network_split = False
37
37
self .sync_all ()
38
-
38
+
39
39
def run_test (self ):
40
-
40
+
41
41
#prepare some coins for multiple *rawtransaction commands
42
42
self .nodes [2 ].generate (1 )
43
43
self .nodes [0 ].generate (101 )
@@ -56,14 +56,89 @@ def run_test(self):
56
56
outputs = { self .nodes [0 ].getnewaddress () : 4.998 }
57
57
rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
58
58
rawtx = self .nodes [2 ].signrawtransaction (rawtx )
59
-
59
+
60
60
errorString = ""
61
61
try :
62
62
rawtx = self .nodes [2 ].sendrawtransaction (rawtx ['hex' ])
63
63
except JSONRPCException ,e :
64
64
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
65
133
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
67
142
68
143
if __name__ == '__main__' :
69
144
RawTransactionsTest ().main ()
0 commit comments