2019-12-04 07:29:16 -08:00
|
|
|
#!/usr/bin/env python3
|
2018-09-25 12:48:01 -07:00
|
|
|
# Copyright (c) 2018 The Zcash developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
2019-07-18 07:16:09 -07:00
|
|
|
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2018-09-25 12:48:01 -07:00
|
|
|
|
2022-02-08 09:36:11 -08:00
|
|
|
from test_framework.authproxy import JSONRPCException
|
2018-09-25 12:48:01 -07:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2022-02-07 11:08:45 -08:00
|
|
|
from test_framework.util import (
|
|
|
|
assert_equal,
|
|
|
|
assert_true,
|
|
|
|
assert_false,
|
2022-02-08 09:36:11 -08:00
|
|
|
assert_raises_message,
|
2022-02-04 23:33:42 -08:00
|
|
|
connect_nodes_bi,
|
2022-02-07 11:08:45 -08:00
|
|
|
get_coinbase_address,
|
|
|
|
DEFAULT_FEE,
|
|
|
|
DEFAULT_FEE_ZATS
|
|
|
|
)
|
2022-02-04 23:33:42 -08:00
|
|
|
from test_framework.util import wait_and_assert_operationid_status, start_nodes
|
2018-09-25 12:48:01 -07:00
|
|
|
from decimal import Decimal
|
|
|
|
|
2019-10-18 13:47:30 -07:00
|
|
|
my_memo_str = 'c0ffee' # stay awake
|
2020-02-13 03:53:49 -08:00
|
|
|
my_memo = '633066666565'
|
2018-09-25 12:48:01 -07:00
|
|
|
my_memo = my_memo + '0'*(1024-len(my_memo))
|
|
|
|
|
|
|
|
no_memo = 'f6' + ('0'*1022) # see section 5.5 of the protocol spec
|
|
|
|
|
|
|
|
class ListReceivedTest (BitcoinTestFramework):
|
2022-02-04 23:33:42 -08:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.num_nodes = 3
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
|
|
|
|
def setup_network(self):
|
|
|
|
self.nodes = start_nodes(
|
|
|
|
self.num_nodes, self.options.tmpdir,
|
|
|
|
extra_args=[['-experimentalfeatures', '-orchardwallet']] * self.num_nodes)
|
|
|
|
connect_nodes_bi(self.nodes, 0, 1)
|
|
|
|
connect_nodes_bi(self.nodes, 1, 2)
|
|
|
|
self.is_network_split = False
|
|
|
|
self.sync_all()
|
|
|
|
|
2018-09-25 12:48:01 -07:00
|
|
|
def generate_and_sync(self, new_height):
|
2018-11-12 15:03:05 -08:00
|
|
|
current_height = self.nodes[0].getblockcount()
|
|
|
|
assert(new_height > current_height)
|
|
|
|
self.nodes[0].generate(new_height - current_height)
|
2018-09-25 12:48:01 -07:00
|
|
|
self.sync_all()
|
|
|
|
assert_equal(new_height, self.nodes[0].getblockcount())
|
|
|
|
|
2022-02-07 11:08:45 -08:00
|
|
|
def test_received_sprout(self, height):
|
|
|
|
self.generate_and_sync(height+2)
|
|
|
|
|
|
|
|
zaddr1 = self.nodes[1].z_getnewaddress('sprout')
|
|
|
|
|
|
|
|
# Send 10 ZEC each zaddr1 and zaddrExt via z_shieldcoinbase
|
2022-02-08 09:36:11 -08:00
|
|
|
result = self.nodes[0].z_shieldcoinbase(get_coinbase_address(self.nodes[0]), zaddr1, 0, 1)
|
2022-02-07 11:08:45 -08:00
|
|
|
txid_shielding1 = wait_and_assert_operationid_status(self.nodes[0], result['opid'])
|
|
|
|
|
2022-02-04 23:33:42 -08:00
|
|
|
zaddrExt = self.nodes[2].z_getnewaddress('sprout')
|
2022-02-08 09:36:11 -08:00
|
|
|
result = self.nodes[0].z_shieldcoinbase(get_coinbase_address(self.nodes[0]), zaddrExt, 0, 1)
|
|
|
|
txid_shieldingExt = wait_and_assert_operationid_status(self.nodes[0], result['opid'])
|
2022-02-07 11:08:45 -08:00
|
|
|
|
|
|
|
self.sync_all()
|
|
|
|
|
2022-02-08 09:36:11 -08:00
|
|
|
# Decrypted transaction details should not be visible on node 0
|
|
|
|
pt = self.nodes[0].z_viewtransaction(txid_shielding1)
|
|
|
|
assert_equal(pt['txid'], txid_shielding1)
|
|
|
|
assert_equal(len(pt['spends']), 0)
|
|
|
|
assert_equal(len(pt['outputs']), 0)
|
|
|
|
|
|
|
|
# Decrypted transaction details should be correct on node 1
|
|
|
|
pt = self.nodes[1].z_viewtransaction(txid_shielding1)
|
|
|
|
assert_equal(pt['txid'], txid_shielding1)
|
|
|
|
assert_equal(len(pt['spends']), 0)
|
|
|
|
assert_equal(len(pt['outputs']), 1)
|
|
|
|
assert_equal(pt['outputs'][0]['type'], 'sprout')
|
|
|
|
assert_equal(pt['outputs'][0]['js'], 0)
|
|
|
|
assert_equal(pt['outputs'][0]['address'], zaddr1)
|
|
|
|
assert_equal(pt['outputs'][0]['value'], Decimal('10'))
|
|
|
|
assert_equal(pt['outputs'][0]['valueZat'], 1000000000)
|
|
|
|
assert_equal(pt['outputs'][0]['memo'], no_memo)
|
|
|
|
jsOutputPrev = pt['outputs'][0]['jsOutput']
|
|
|
|
|
|
|
|
# Second transaction should not be known to node 1
|
|
|
|
assert_raises_message(
|
|
|
|
JSONRPCException,
|
|
|
|
"Invalid or non-wallet transaction id",
|
|
|
|
self.nodes[1].z_viewtransaction,
|
|
|
|
txid_shieldingExt)
|
|
|
|
|
2022-02-04 23:33:42 -08:00
|
|
|
# Second transaction should be visible on node0
|
|
|
|
pt = self.nodes[2].z_viewtransaction(txid_shieldingExt)
|
2022-02-08 09:36:11 -08:00
|
|
|
assert_equal(pt['txid'], txid_shieldingExt)
|
|
|
|
assert_equal(len(pt['spends']), 0)
|
|
|
|
assert_equal(len(pt['outputs']), 1)
|
|
|
|
assert_equal(pt['outputs'][0]['type'], 'sprout')
|
|
|
|
assert_equal(pt['outputs'][0]['js'], 0)
|
|
|
|
assert_equal(pt['outputs'][0]['address'], zaddrExt)
|
|
|
|
assert_equal(pt['outputs'][0]['value'], Decimal('10'))
|
|
|
|
assert_equal(pt['outputs'][0]['valueZat'], 1000000000)
|
|
|
|
assert_equal(pt['outputs'][0]['memo'], no_memo)
|
2022-02-07 11:08:45 -08:00
|
|
|
|
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(zaddr1)
|
|
|
|
assert_equal(0, len(r), "Should have received no confirmed note")
|
|
|
|
c = self.nodes[1].z_getnotescount()
|
|
|
|
assert_equal(0, c['sprout'], "Count of confirmed notes should be 0")
|
|
|
|
|
|
|
|
# No confirmation required, one note should be present
|
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(zaddr1, 0)
|
|
|
|
assert_equal(1, len(r), "Should have received one (unconfirmed) note")
|
|
|
|
assert_equal(txid_shielding1, r[0]['txid'])
|
|
|
|
assert_equal(10, r[0]['amount'])
|
|
|
|
assert_equal(1000000000, r[0]['amountZat'])
|
|
|
|
assert_false(r[0]['change'], "Note should not be change")
|
|
|
|
assert_equal(no_memo, r[0]['memo'])
|
|
|
|
assert_equal(0, r[0]['confirmations'])
|
|
|
|
assert_equal(-1, r[0]['blockindex'])
|
|
|
|
assert_equal(0, r[0]['blockheight'])
|
|
|
|
|
|
|
|
c = self.nodes[1].z_getnotescount(0)
|
|
|
|
assert_equal(1, c['sprout'], "Count of unconfirmed notes should be 1")
|
|
|
|
|
|
|
|
# Confirm transaction (10 ZEC shielded)
|
|
|
|
self.generate_and_sync(height+3)
|
|
|
|
|
|
|
|
# Require one confirmation, note should be present
|
2022-02-08 13:18:18 -08:00
|
|
|
r0 = self.nodes[1].z_listreceivedbyaddress(zaddr1)
|
|
|
|
assert_equal(1, len(r0), "Should have received one (unconfirmed) note")
|
|
|
|
assert_equal(txid_shielding1, r0[0]['txid'])
|
|
|
|
assert_equal(10, r0[0]['amount'])
|
|
|
|
assert_equal(1000000000, r0[0]['amountZat'])
|
|
|
|
assert_false(r0[0]['change'], "Note should not be change")
|
|
|
|
assert_equal(no_memo, r0[0]['memo'])
|
|
|
|
assert_equal(1, r0[0]['confirmations'])
|
|
|
|
assert_equal(height + 3, r0[0]['blockheight'])
|
2022-02-07 11:08:45 -08:00
|
|
|
|
|
|
|
taddr = self.nodes[1].getnewaddress()
|
|
|
|
# Generate some change by sending part of zaddr1 back to taddr
|
|
|
|
opid = self.nodes[1].z_sendmany(zaddr1, [{'address': taddr, 'amount': 0.6}])
|
|
|
|
txid = wait_and_assert_operationid_status(self.nodes[1], opid)
|
|
|
|
|
|
|
|
self.generate_and_sync(height+4)
|
|
|
|
|
|
|
|
# Decrypted transaction details should be correct
|
|
|
|
pt = self.nodes[1].z_viewtransaction(txid)
|
|
|
|
assert_equal(pt['txid'], txid)
|
|
|
|
assert_equal(len(pt['spends']), 1)
|
|
|
|
# TODO: enable once z_viewtransaction displays transparent elements
|
|
|
|
# assert_equal(len(pt['outputs']), 2)
|
|
|
|
assert_equal(len(pt['outputs']), 1)
|
|
|
|
|
|
|
|
assert_equal(pt['spends'][0]['type'], 'sprout')
|
|
|
|
assert_equal(pt['spends'][0]['txidPrev'], txid_shielding1)
|
|
|
|
assert_equal(pt['spends'][0]['js'], 0)
|
|
|
|
assert_equal(pt['spends'][0]['jsPrev'], 0)
|
|
|
|
assert_equal(pt['spends'][0]['jsOutputPrev'], jsOutputPrev)
|
|
|
|
assert_equal(pt['spends'][0]['address'], zaddr1)
|
|
|
|
assert_equal(pt['spends'][0]['value'], Decimal('10.0'))
|
|
|
|
assert_equal(pt['spends'][0]['valueZat'], 1000000000)
|
|
|
|
|
2022-02-08 09:36:11 -08:00
|
|
|
# We expect a transparent output and a Sprout output, but the RPC does
|
|
|
|
# not define any particular ordering of these within the returned JSON.
|
|
|
|
outputs = [{
|
|
|
|
'type': output['type'],
|
|
|
|
'address': output['address'],
|
|
|
|
'value': output['value'],
|
|
|
|
'valueZat': output['valueZat'],
|
|
|
|
} for output in pt['outputs']]
|
|
|
|
for (i, output) in enumerate(pt['outputs']):
|
|
|
|
if 'memo' in output:
|
|
|
|
outputs[i]['memo'] = output['memo']
|
2022-02-07 11:08:45 -08:00
|
|
|
|
|
|
|
# TODO: enable once z_viewtransaction displays transparent elements
|
|
|
|
# assert({
|
|
|
|
# 'type': 'transparent',
|
|
|
|
# 'address': taddr,
|
|
|
|
# 'value': Decimal('0.6'),
|
|
|
|
# 'valueZat': 60000000,
|
|
|
|
# } in outputs)
|
|
|
|
assert({
|
|
|
|
'type': 'sprout',
|
|
|
|
'address': zaddr1,
|
|
|
|
'value': Decimal('9.4') - DEFAULT_FEE,
|
|
|
|
'valueZat': 940000000 - DEFAULT_FEE_ZATS,
|
|
|
|
'memo': no_memo,
|
|
|
|
} in outputs)
|
|
|
|
|
|
|
|
# zaddr1 should have a note with change
|
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(zaddr1, 0)
|
|
|
|
r = sorted(r, key = lambda received: received['amount'])
|
|
|
|
assert_equal(2, len(r), "zaddr1 Should have received 2 notes")
|
|
|
|
|
|
|
|
assert_equal(txid, r[0]['txid'])
|
|
|
|
assert_equal(Decimal('9.4')-DEFAULT_FEE, r[0]['amount'])
|
|
|
|
assert_equal(940000000-DEFAULT_FEE_ZATS, r[0]['amountZat'])
|
|
|
|
assert_true(r[0]['change'], "Note valued at (9.4-"+str(DEFAULT_FEE)+") should be change")
|
|
|
|
assert_equal(no_memo, r[0]['memo'])
|
|
|
|
|
|
|
|
# The old note still exists (it's immutable), even though it is spent
|
|
|
|
assert_equal(Decimal('10.0'), r[1]['amount'])
|
|
|
|
assert_equal(1000000000, r[1]['amountZat'])
|
2022-02-08 09:36:11 -08:00
|
|
|
assert_false(r[1]['change'], "Note valued at 10.0 should not be change")
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(no_memo, r[1]['memo'])
|
|
|
|
|
|
|
|
def test_received_sapling(self, height):
|
2018-09-25 12:48:01 -07:00
|
|
|
self.generate_and_sync(height+1)
|
|
|
|
taddr = self.nodes[1].getnewaddress()
|
2022-02-07 11:08:45 -08:00
|
|
|
zaddr1 = self.nodes[1].z_getnewaddress('sapling')
|
2022-02-04 23:33:42 -08:00
|
|
|
zaddrExt = self.nodes[2].z_getnewaddress('sapling')
|
2018-09-25 12:48:01 -07:00
|
|
|
|
2022-02-04 23:33:42 -08:00
|
|
|
txid_taddr = self.nodes[0].sendtoaddress(taddr, 4.0)
|
2018-09-25 12:48:01 -07:00
|
|
|
self.generate_and_sync(height+2)
|
|
|
|
|
|
|
|
# Send 1 ZEC to zaddr1
|
2019-10-18 13:47:30 -07:00
|
|
|
opid = self.nodes[1].z_sendmany(taddr, [
|
|
|
|
{'address': zaddr1, 'amount': 1, 'memo': my_memo},
|
|
|
|
{'address': zaddrExt, 'amount': 2},
|
|
|
|
])
|
2018-09-25 12:48:01 -07:00
|
|
|
txid = wait_and_assert_operationid_status(self.nodes[1], opid)
|
|
|
|
self.sync_all()
|
2019-10-18 13:47:30 -07:00
|
|
|
|
|
|
|
# Decrypted transaction details should be correct
|
|
|
|
pt = self.nodes[1].z_viewtransaction(txid)
|
2022-01-25 15:32:51 -08:00
|
|
|
|
2019-10-18 13:47:30 -07:00
|
|
|
assert_equal(pt['txid'], txid)
|
|
|
|
assert_equal(len(pt['spends']), 0)
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(len(pt['outputs']), 2)
|
2019-10-18 13:47:30 -07:00
|
|
|
|
2022-01-25 15:32:51 -08:00
|
|
|
# Expect one internal output and one external.
|
|
|
|
assert_equal(len([output for output in pt['outputs'] if output['outgoing']]), 1)
|
|
|
|
|
2022-02-08 09:36:11 -08:00
|
|
|
# Outputs are not returned in a defined order so we check the output
|
2019-10-18 13:47:30 -07:00
|
|
|
# positions and contents separately
|
|
|
|
outputs = []
|
|
|
|
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(pt['outputs'][0]['type'], 'sapling')
|
|
|
|
if pt['outputs'][0]['address'] == zaddr1:
|
2022-02-04 23:33:42 -08:00
|
|
|
assert_false('jsOutput' in pt['outputs'][0])
|
2019-10-18 13:47:30 -07:00
|
|
|
assert_equal(pt['outputs'][0]['outgoing'], False)
|
|
|
|
assert_equal(pt['outputs'][0]['memoStr'], my_memo_str)
|
|
|
|
else:
|
|
|
|
assert_equal(pt['outputs'][0]['outgoing'], True)
|
|
|
|
outputs.append({
|
|
|
|
'address': pt['outputs'][0]['address'],
|
|
|
|
'value': pt['outputs'][0]['value'],
|
|
|
|
'valueZat': pt['outputs'][0]['valueZat'],
|
|
|
|
'memo': pt['outputs'][0]['memo'],
|
|
|
|
})
|
|
|
|
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(pt['outputs'][1]['type'], 'sapling')
|
|
|
|
if pt['outputs'][1]['address'] == zaddr1:
|
|
|
|
assert_equal(pt['outputs'][1]['outgoing'], False)
|
|
|
|
assert_equal(pt['outputs'][1]['memoStr'], my_memo_str)
|
|
|
|
else:
|
|
|
|
assert_equal(pt['outputs'][1]['outgoing'], True)
|
|
|
|
outputs.append({
|
|
|
|
'address': pt['outputs'][1]['address'],
|
|
|
|
'value': pt['outputs'][1]['value'],
|
|
|
|
'valueZat': pt['outputs'][1]['valueZat'],
|
|
|
|
'memo': pt['outputs'][1]['memo'],
|
|
|
|
})
|
2019-10-18 13:47:30 -07:00
|
|
|
|
|
|
|
assert({
|
|
|
|
'address': zaddr1,
|
|
|
|
'value': Decimal('1'),
|
|
|
|
'valueZat': 100000000,
|
|
|
|
'memo': my_memo,
|
|
|
|
} in outputs)
|
2022-02-07 11:08:45 -08:00
|
|
|
|
|
|
|
assert({
|
|
|
|
'address': zaddrExt,
|
|
|
|
'value': Decimal('2'),
|
|
|
|
'valueZat': 200000000,
|
|
|
|
'memo': no_memo,
|
|
|
|
} in outputs)
|
2019-10-18 13:47:30 -07:00
|
|
|
|
2018-09-25 12:48:01 -07:00
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(zaddr1)
|
|
|
|
assert_equal(0, len(r), "Should have received no confirmed note")
|
2020-04-19 16:22:06 -07:00
|
|
|
c = self.nodes[1].z_getnotescount()
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(0, c['sapling'], "Count of confirmed notes should be 0")
|
2018-09-25 12:48:01 -07:00
|
|
|
|
|
|
|
# No confirmation required, one note should be present
|
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(zaddr1, 0)
|
|
|
|
assert_equal(1, len(r), "Should have received one (unconfirmed) note")
|
|
|
|
assert_equal(txid, r[0]['txid'])
|
|
|
|
assert_equal(1, r[0]['amount'])
|
2020-01-28 16:27:31 -08:00
|
|
|
assert_equal(100000000, r[0]['amountZat'])
|
2018-09-25 12:48:01 -07:00
|
|
|
assert_false(r[0]['change'], "Note should not be change")
|
|
|
|
assert_equal(my_memo, r[0]['memo'])
|
2019-12-03 06:24:30 -08:00
|
|
|
assert_equal(0, r[0]['confirmations'])
|
|
|
|
assert_equal(-1, r[0]['blockindex'])
|
|
|
|
assert_equal(0, r[0]['blockheight'])
|
2018-09-25 12:48:01 -07:00
|
|
|
|
2020-04-19 16:22:06 -07:00
|
|
|
c = self.nodes[1].z_getnotescount(0)
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(1, c['sapling'], "Count of unconfirmed notes should be 1")
|
2020-04-19 16:22:06 -07:00
|
|
|
|
2018-09-25 12:48:01 -07:00
|
|
|
# Confirm transaction (1 ZEC from taddr to zaddr1)
|
|
|
|
self.generate_and_sync(height+3)
|
|
|
|
|
2020-03-11 09:43:47 -07:00
|
|
|
# adjust confirmations
|
|
|
|
r[0]['confirmations'] = 1
|
|
|
|
# adjust blockindex
|
2019-12-03 06:24:30 -08:00
|
|
|
r[0]['blockindex'] = 1
|
2020-03-11 09:43:47 -07:00
|
|
|
# adjust height
|
2019-12-03 06:24:30 -08:00
|
|
|
r[0]['blockheight'] = height + 3
|
|
|
|
|
2018-09-25 12:48:01 -07:00
|
|
|
# Require one confirmation, note should be present
|
|
|
|
assert_equal(r, self.nodes[1].z_listreceivedbyaddress(zaddr1))
|
|
|
|
|
|
|
|
# Generate some change by sending part of zaddr1 to zaddr2
|
2019-10-18 13:47:30 -07:00
|
|
|
txidPrev = txid
|
2022-02-07 11:08:45 -08:00
|
|
|
zaddr2 = self.nodes[1].z_getnewaddress('sapling')
|
2018-09-25 12:48:01 -07:00
|
|
|
opid = self.nodes[1].z_sendmany(zaddr1,
|
2018-10-24 07:13:56 -07:00
|
|
|
[{'address': zaddr2, 'amount': 0.6}])
|
2018-09-25 12:48:01 -07:00
|
|
|
txid = wait_and_assert_operationid_status(self.nodes[1], opid)
|
|
|
|
self.sync_all()
|
|
|
|
self.generate_and_sync(height+4)
|
|
|
|
|
2019-10-18 13:47:30 -07:00
|
|
|
# Decrypted transaction details should be correct
|
|
|
|
pt = self.nodes[1].z_viewtransaction(txid)
|
|
|
|
assert_equal(pt['txid'], txid)
|
|
|
|
assert_equal(len(pt['spends']), 1)
|
|
|
|
assert_equal(len(pt['outputs']), 2)
|
|
|
|
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(pt['spends'][0]['type'], 'sapling')
|
2019-10-18 13:47:30 -07:00
|
|
|
assert_equal(pt['spends'][0]['txidPrev'], txidPrev)
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(pt['spends'][0]['spend'], 0)
|
|
|
|
assert_equal(pt['spends'][0]['outputPrev'], 0)
|
2019-10-18 13:47:30 -07:00
|
|
|
assert_equal(pt['spends'][0]['address'], zaddr1)
|
|
|
|
assert_equal(pt['spends'][0]['value'], Decimal('1.0'))
|
|
|
|
assert_equal(pt['spends'][0]['valueZat'], 100000000)
|
|
|
|
|
2022-02-08 09:36:11 -08:00
|
|
|
# Outputs are not returned in a defined order so we check the output
|
2019-10-18 13:47:30 -07:00
|
|
|
# positions and contents separately
|
|
|
|
outputs = []
|
|
|
|
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(pt['outputs'][0]['type'], 'sapling')
|
|
|
|
assert_equal(pt['outputs'][0]['output'], 0)
|
|
|
|
assert_equal(pt['outputs'][0]['outgoing'], False)
|
2019-10-18 13:47:30 -07:00
|
|
|
outputs.append({
|
|
|
|
'address': pt['outputs'][0]['address'],
|
|
|
|
'value': pt['outputs'][0]['value'],
|
|
|
|
'valueZat': pt['outputs'][0]['valueZat'],
|
|
|
|
'memo': pt['outputs'][0]['memo'],
|
|
|
|
})
|
|
|
|
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(pt['outputs'][1]['type'], 'sapling')
|
|
|
|
assert_equal(pt['outputs'][1]['output'], 1)
|
|
|
|
assert_equal(pt['outputs'][1]['outgoing'], False)
|
2019-10-18 13:47:30 -07:00
|
|
|
outputs.append({
|
|
|
|
'address': pt['outputs'][1]['address'],
|
|
|
|
'value': pt['outputs'][1]['value'],
|
|
|
|
'valueZat': pt['outputs'][1]['valueZat'],
|
|
|
|
'memo': pt['outputs'][1]['memo'],
|
|
|
|
})
|
|
|
|
|
|
|
|
assert({
|
|
|
|
'address': zaddr2,
|
|
|
|
'value': Decimal('0.6'),
|
|
|
|
'valueZat': 60000000,
|
|
|
|
'memo': no_memo,
|
|
|
|
} in outputs)
|
|
|
|
assert({
|
|
|
|
'address': zaddr1,
|
2020-12-17 11:39:58 -08:00
|
|
|
'value': Decimal('0.4') - DEFAULT_FEE,
|
|
|
|
'valueZat': 40000000 - DEFAULT_FEE_ZATS,
|
2019-10-18 13:47:30 -07:00
|
|
|
'memo': no_memo,
|
|
|
|
} in outputs)
|
|
|
|
|
2018-09-25 12:48:01 -07:00
|
|
|
# zaddr1 should have a note with change
|
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(zaddr1, 0)
|
|
|
|
r = sorted(r, key = lambda received: received['amount'])
|
|
|
|
assert_equal(2, len(r), "zaddr1 Should have received 2 notes")
|
|
|
|
|
|
|
|
assert_equal(txid, r[0]['txid'])
|
2020-12-17 11:39:58 -08:00
|
|
|
assert_equal(Decimal('0.4')-DEFAULT_FEE, r[0]['amount'])
|
|
|
|
assert_equal(40000000-DEFAULT_FEE_ZATS, r[0]['amountZat'])
|
|
|
|
assert_true(r[0]['change'], "Note valued at (0.4-"+str(DEFAULT_FEE)+") should be change")
|
2018-10-24 07:13:56 -07:00
|
|
|
assert_equal(no_memo, r[0]['memo'])
|
2018-09-25 12:48:01 -07:00
|
|
|
|
|
|
|
# The old note still exists (it's immutable), even though it is spent
|
|
|
|
assert_equal(Decimal('1.0'), r[1]['amount'])
|
2020-01-28 16:27:31 -08:00
|
|
|
assert_equal(100000000, r[1]['amountZat'])
|
2018-09-25 12:48:01 -07:00
|
|
|
assert_false(r[1]['change'], "Note valued at 1.0 should not be change")
|
2018-10-24 07:13:56 -07:00
|
|
|
assert_equal(my_memo, r[1]['memo'])
|
2018-09-25 12:48:01 -07:00
|
|
|
|
|
|
|
# zaddr2 should not have change
|
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(zaddr2, 0)
|
|
|
|
r = sorted(r, key = lambda received: received['amount'])
|
|
|
|
assert_equal(1, len(r), "zaddr2 Should have received 1 notes")
|
|
|
|
assert_equal(txid, r[0]['txid'])
|
|
|
|
assert_equal(Decimal('0.6'), r[0]['amount'])
|
2020-01-28 16:27:31 -08:00
|
|
|
assert_equal(60000000, r[0]['amountZat'])
|
2018-09-25 12:48:01 -07:00
|
|
|
assert_false(r[0]['change'], "Note valued at 0.6 should not be change")
|
2018-10-24 07:13:56 -07:00
|
|
|
assert_equal(no_memo, r[0]['memo'])
|
2018-09-25 12:48:01 -07:00
|
|
|
|
2020-04-19 16:22:06 -07:00
|
|
|
c = self.nodes[1].z_getnotescount(0)
|
2022-02-07 11:08:45 -08:00
|
|
|
assert_equal(3, c['sapling'], "Count of unconfirmed notes should be 3(2 in zaddr1 + 1 in zaddr2)")
|
2020-04-19 16:22:06 -07:00
|
|
|
|
2022-02-04 23:33:42 -08:00
|
|
|
# As part of UA support, a transparent address is now accepted
|
|
|
|
r = self.nodes[1].z_listreceivedbyaddress(taddr, 0)
|
|
|
|
assert_equal(len(r), 1)
|
|
|
|
assert_equal(r[0]['pool'], 'transparent')
|
|
|
|
assert_equal(r[0]['txid'], txid_taddr)
|
|
|
|
assert_equal(r[0]['amount'], Decimal('4'))
|
|
|
|
assert_equal(r[0]['amountZat'], 400000000)
|
|
|
|
assert_equal(r[0]['confirmations'], 3)
|
|
|
|
assert r[0]['outindex'] < 2
|
|
|
|
|
|
|
|
# Test unified address
|
|
|
|
node = self.nodes[1]
|
|
|
|
|
|
|
|
# Create a unified address on one node, try z_listreceivedbyaddress on another node
|
|
|
|
account = self.nodes[0].z_getnewaccount()['account']
|
|
|
|
r = self.nodes[0].z_getaddressforaccount(account)
|
|
|
|
unified_addr = r['unifiedaddress']
|
|
|
|
# this address isn't in node1's wallet
|
|
|
|
assert_raises_message(
|
|
|
|
JSONRPCException,
|
|
|
|
"From address does not belong to this node",
|
|
|
|
node.z_listreceivedbyaddress, unified_addr, 0)
|
|
|
|
|
|
|
|
# create a UA on node1
|
|
|
|
r = node.z_getnewaccount()
|
|
|
|
account = r['account']
|
|
|
|
r = node.z_getaddressforaccount(account)
|
|
|
|
unified_addr = r['unifiedaddress']
|
|
|
|
receivers = node.z_listunifiedreceivers(unified_addr)
|
|
|
|
assert_equal(len(receivers), 2)
|
|
|
|
assert 'transparent' in receivers
|
|
|
|
assert 'sapling' in receivers
|
|
|
|
# Wallet contains no notes
|
|
|
|
r = node.z_listreceivedbyaddress(unified_addr, 0)
|
|
|
|
assert_equal(len(r), 0, "unified_addr should have received zero notes")
|
|
|
|
|
|
|
|
# Create a note in this UA on node1
|
|
|
|
opid = node.z_sendmany(zaddr1, [{'address': unified_addr, 'amount': 0.1}])
|
|
|
|
txid_sapling = wait_and_assert_operationid_status(node, opid)
|
|
|
|
self.generate_and_sync(height+5)
|
|
|
|
|
|
|
|
# Create a UTXO that unified_address's transparent component references, on node1
|
|
|
|
outputs = {receivers['transparent']: 0.2}
|
|
|
|
txid_taddr = node.sendmany("", outputs)
|
|
|
|
|
|
|
|
r = node.z_listreceivedbyaddress(unified_addr, 0)
|
|
|
|
assert_equal(len(r), 2, "unified_addr should have received 2 payments")
|
|
|
|
print(r)
|
|
|
|
outputs = [];
|
|
|
|
outputs.append({
|
|
|
|
'pool': r[0]['pool'],
|
|
|
|
'txid': r[0]['txid'],
|
|
|
|
'amount': r[0]['amount'],
|
|
|
|
'amountZat': r[0]['amountZat'],
|
|
|
|
'change': r[0]['change'] if 'change' in r[0] else None,
|
|
|
|
'memo': r[0]['memo'] if 'memo' in r[0] else None,
|
|
|
|
'confirmations': r[0]['confirmations']
|
|
|
|
})
|
|
|
|
outputs.append({
|
|
|
|
'pool': r[1]['pool'],
|
|
|
|
'txid': r[1]['txid'],
|
|
|
|
'amount': r[1]['amount'],
|
|
|
|
'amountZat': r[1]['amountZat'],
|
|
|
|
'change': r[1]['change'] if 'change' in r[1] else None,
|
|
|
|
'memo': r[1]['memo'] if 'memo' in r[1] else None,
|
|
|
|
'confirmations': r[1]['confirmations']
|
|
|
|
})
|
|
|
|
assert({
|
|
|
|
'pool': 'sapling',
|
|
|
|
'txid': txid_sapling,
|
|
|
|
'amount': Decimal('0.1'),
|
|
|
|
'amountZat': 10000000,
|
|
|
|
'change': False,
|
|
|
|
'memo': no_memo,
|
|
|
|
'confirmations': 0,
|
|
|
|
} in outputs)
|
|
|
|
assert({
|
|
|
|
'pool': 'transparent',
|
|
|
|
'txid': txid_taddr,
|
|
|
|
'amount': Decimal('0.2'),
|
|
|
|
'amountZat': 20000000,
|
2022-02-10 18:26:04 -08:00
|
|
|
'change': False,
|
2022-02-04 23:33:42 -08:00
|
|
|
'memo': None,
|
|
|
|
'confirmations': 0,
|
|
|
|
} in outputs)
|
|
|
|
|
2018-09-25 12:48:01 -07:00
|
|
|
def run_test(self):
|
2022-02-07 11:08:45 -08:00
|
|
|
self.test_received_sprout(200)
|
|
|
|
self.test_received_sapling(214)
|
2018-09-25 12:48:01 -07:00
|
|
|
|
2022-02-04 23:33:42 -08:00
|
|
|
|
2018-09-25 12:48:01 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
ListReceivedTest().main()
|