52 lines
2.1 KiB
Python
Executable File
52 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2020 The Zcash developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal, connect_nodes_bi, start_nodes
|
|
from decimal import Decimal
|
|
|
|
# Test wallet address behaviour across network upgrades
|
|
class WalletZeroValueTest(BitcoinTestFramework):
|
|
def setup_network(self, split=False):
|
|
self.nodes = start_nodes(2, self.options.tmpdir, extra_args=[[
|
|
'-allowdeprecated=getnewaddress',
|
|
]] * 2)
|
|
connect_nodes_bi(self.nodes,0,1)
|
|
self.is_network_split=False
|
|
self.sync_all()
|
|
|
|
def run_test(self):
|
|
#check if we can list zero value tx as available coins
|
|
#1. create rawtx
|
|
#2. hex-changed one output to 0.0
|
|
#3. sign and send
|
|
#4. check if recipient (node0) can list the zero value tx
|
|
usp = self.nodes[1].listunspent()
|
|
inputs = [{"txid":usp[0]['txid'], "vout":usp[0]['vout']}]
|
|
outputs = {self.nodes[1].getnewaddress(): 9.998, self.nodes[0].getnewaddress(): 11.11}
|
|
|
|
rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32)
|
|
decRawTx = self.nodes[1].decoderawtransaction(rawTx)
|
|
signedRawTx = self.nodes[1].signrawtransaction(rawTx)
|
|
decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex'])
|
|
zeroValueTxid= decRawTx['txid']
|
|
self.nodes[1].sendrawtransaction(signedRawTx['hex'])
|
|
|
|
self.sync_all()
|
|
self.nodes[1].generate(1) #mine a block
|
|
self.sync_all()
|
|
|
|
unspentTxs = self.nodes[0].listunspent() #zero value tx must be in listunspents output
|
|
found = False
|
|
for uTx in unspentTxs:
|
|
if uTx['txid'] == zeroValueTxid:
|
|
found = True
|
|
assert_equal(uTx['amount'], Decimal('0.00000000'))
|
|
assert_equal(uTx['amountZat'], 0)
|
|
assert(found)
|
|
|
|
if __name__ == '__main__':
|
|
WalletZeroValueTest().main()
|