Auto merge of #4793 - str4d:faster-rpc-tests, r=str4d

test: Use default shielded address in RPC tests where the type is irrelevant

This means we are running these tests against the recommended functionality,
and that these RPC tests will now use the faster Sapling addresses.
This commit is contained in:
Homu 2020-11-19 14:15:08 +00:00
commit 10b09d483e
8 changed files with 38 additions and 64 deletions

View File

@ -12,7 +12,7 @@ class RegtestSignrawtransactionTest (BitcoinTestFramework):
self.nodes[0].generate(1)
self.sync_all()
taddr = self.nodes[1].getnewaddress()
zaddr1 = self.nodes[1].z_getnewaddress('sprout')
zaddr1 = self.nodes[1].z_getnewaddress()
self.nodes[0].sendtoaddress(taddr, 2.0)
self.nodes[0].generate(1)

View File

@ -297,7 +297,7 @@ class WalletTest (BitcoinTestFramework):
assert("joinSplitSig" not in mytxdetails)
# z_sendmany is expected to fail if tx size breaks limit
myzaddr = self.nodes[0].z_getnewaddress('sprout')
myzaddr = self.nodes[0].z_getnewaddress()
recipients = []
num_t_recipients = 1000
@ -308,7 +308,7 @@ class WalletTest (BitcoinTestFramework):
newtaddr = self.nodes[2].getnewaddress()
recipients.append({"address":newtaddr, "amount":amount_per_recipient})
for i in range(0,num_z_recipients):
newzaddr = self.nodes[2].z_getnewaddress('sprout')
newzaddr = self.nodes[2].z_getnewaddress()
recipients.append({"address":newzaddr, "amount":amount_per_recipient})
# Issue #2759 Workaround START
@ -327,7 +327,7 @@ class WalletTest (BitcoinTestFramework):
assert("size of raw transaction would be larger than limit" in errorString)
# add zaddr to node 2
myzaddr = self.nodes[2].z_getnewaddress('sprout')
myzaddr = self.nodes[2].z_getnewaddress()
# send node 2 taddr to zaddr
recipients = []
@ -367,24 +367,11 @@ class WalletTest (BitcoinTestFramework):
assert_equal(Decimal(wallet_info["shielded_unconfirmed_balance"]), Decimal('0.0'))
assert_equal(Decimal(wallet_info["shielded_balance"]), zsendmanynotevalue)
# there should be at least one joinsplit
mytxdetails = self.nodes[2].gettransaction(mytxid)
myvjoinsplits = mytxdetails["vjoinsplit"]
assert_greater_than(len(myvjoinsplits), 0)
# the first (probably only) joinsplit should take in all the public value
# there should be at least one Sapling output
mytxdetails = self.nodes[2].getrawtransaction(mytxid, 1)
myjoinsplit = mytxdetails["vjoinsplit"][0]
assert_equal(myjoinsplit["vpub_old"], zsendmanynotevalue)
assert_equal(myjoinsplit["vpub_new"], 0)
assert("onetimePubKey" in myjoinsplit.keys())
assert("randomSeed" in myjoinsplit.keys())
assert("ciphertexts" in myjoinsplit.keys())
assert(len(mytxdetails["joinSplitPubKey"]) == 64)
int(mytxdetails["joinSplitPubKey"], 16) # throws if not a hex string
assert(len(mytxdetails["joinSplitSig"]) == 128)
int(mytxdetails["joinSplitSig"], 16) # hex string
assert_greater_than(len(mytxdetails["vShieldedOutput"]), 0)
# the Sapling output should take in all the public value
assert_equal(mytxdetails["valueBalance"], -zsendmanynotevalue)
# send from private note to node 0 and node 2
node0balance = self.nodes[0].getbalance() # 25.99794745
@ -441,7 +428,7 @@ class WalletTest (BitcoinTestFramework):
assert_equal("not an integer" in errorString, True)
myzaddr = self.nodes[0].z_getnewaddress('sprout')
myzaddr = self.nodes[0].z_getnewaddress()
recipients = [ {"address": myzaddr, "amount": Decimal('0.0') } ]
errorString = ''

View File

@ -49,7 +49,7 @@ class Wallet1941RegressionTest (BitcoinTestFramework):
self.sync_all()
mytaddr = get_coinbase_address(self.nodes[0])
myzaddr = self.nodes[0].z_getnewaddress('sprout')
myzaddr = self.nodes[0].z_getnewaddress()
# Send 10 coins to our zaddr.
recipients = []
@ -77,7 +77,7 @@ class Wallet1941RegressionTest (BitcoinTestFramework):
# Start the new wallet
self.add_second_node()
self.nodes[1].getnewaddress()
self.nodes[1].z_getnewaddress('sprout')
self.nodes[1].z_getnewaddress()
self.nodes[1].generate(101)
self.sync_all()

View File

@ -8,7 +8,6 @@ from test_framework.util import assert_equal, initialize_chain_clean, \
start_nodes, stop_nodes, connect_nodes_bi, \
wait_and_assert_operationid_status, wait_bitcoinds, get_coinbase_address, \
sync_blocks, sync_mempools
from decimal import Decimal
class WalletAnchorForkTest (BitcoinTestFramework):
@ -47,7 +46,7 @@ class WalletAnchorForkTest (BitcoinTestFramework):
# Node 0 creates a joinsplit transaction
mytaddr0 = get_coinbase_address(self.nodes[0])
myzaddr0 = self.nodes[0].z_getnewaddress('sprout')
myzaddr0 = self.nodes[0].z_getnewaddress()
recipients = []
recipients.append({"address":myzaddr0, "amount": Decimal('10.0') - Decimal('0.0001')})
myopid = self.nodes[0].z_sendmany(mytaddr0, recipients)

View File

@ -18,8 +18,8 @@ class WalletChangeIndicatorTest (BitcoinTestFramework):
# Tests
def run_test(self):
taddr = self.nodes[1].getnewaddress()
zaddr1 = self.nodes[1].z_getnewaddress('sprout')
zaddr2 = self.nodes[1].z_getnewaddress('sprout')
zaddr1 = self.nodes[1].z_getnewaddress()
zaddr2 = self.nodes[1].z_getnewaddress()
self.nodes[0].sendtoaddress(taddr, Decimal('1.0'))
self.generate_and_sync()
@ -66,12 +66,12 @@ class WalletChangeIndicatorTest (BitcoinTestFramework):
received_node0 = self.nodes[0].z_listreceivedbyaddress(zaddr1, 0)
assert_equal(2, len(received_node0))
unspent_node0 = self.nodes[0].z_listunspent(1, 9999999, True)
assert_equal(2, len(unspent_node0))
# Sapling viewing keys correctly detect spends, so we only see the unspent note
assert_equal(1, len(unspent_node0))
# node 0 only has a viewing key so does not see the change field
assert_false('change' in received_node0[0])
assert_false('change' in received_node0[1])
assert_false('change' in unspent_node0[0])
assert_false('change' in unspent_node0[1])
if __name__ == '__main__':
WalletChangeIndicatorTest().main()

View File

@ -18,7 +18,7 @@ class WalletNullifiersTest (BitcoinTestFramework):
def run_test (self):
# add zaddr to node 0
myzaddr0 = self.nodes[0].z_getnewaddress('sprout')
myzaddr0 = self.nodes[0].z_getnewaddress()
# send node 0 taddr to zaddr to get out of coinbase
# Tests using the default cached chain have one address per coinbase output
@ -33,7 +33,7 @@ class WalletNullifiersTest (BitcoinTestFramework):
self.sync_all()
# add zaddr to node 2
myzaddr = self.nodes[2].z_getnewaddress('sprout')
myzaddr = self.nodes[2].z_getnewaddress()
# import node 2 zaddr into node 1
myzkey = self.nodes[2].z_exportkey(myzaddr)
@ -65,7 +65,7 @@ class WalletNullifiersTest (BitcoinTestFramework):
assert_equal(self.nodes[1].z_getbalance(myzaddr), zsendmanynotevalue)
# add zaddr to node 3
myzaddr3 = self.nodes[3].z_getnewaddress('sprout')
myzaddr3 = self.nodes[3].z_getnewaddress()
# send node 2 zaddr to note 3 zaddr
recipients = []
@ -84,15 +84,10 @@ class WalletNullifiersTest (BitcoinTestFramework):
assert_equal(self.nodes[3].z_getbalance(myzaddr3), zsendmany2notevalue)
assert_equal(self.nodes[2].z_getbalance(myzaddr), zaddrremaining)
# Parallel encrypted wallet can't cache nullifiers for received notes,
# and therefore can't detect spends. So it sees a balance corresponding
# to the sum of both notes it received (one as change).
# TODO: Devise a way to avoid this issue (#1528)
assert_equal(self.nodes[1].z_getbalance(myzaddr), zsendmanynotevalue + zaddrremaining)
# Parallel encrypted wallet can cache nullifiers for Sapling received notes
assert_equal(self.nodes[1].z_getbalance(myzaddr), zaddrremaining)
# send node 2 zaddr on node 1 to taddr
# This requires that node 1 be unlocked, which triggers caching of
# uncached nullifiers.
self.nodes[1].walletpassphrase("test", 600)
mytaddr1 = self.nodes[1].getnewaddress()
recipients = []
@ -105,9 +100,6 @@ class WalletNullifiersTest (BitcoinTestFramework):
self.sync_all()
# check zaddr balance
# Now that the encrypted wallet has been unlocked, the note nullifiers
# have been cached and spent notes can be detected. Thus the two wallets
# are in agreement once more.
zsendmany3notevalue = Decimal('1.0')
zaddrremaining2 = zaddrremaining - zsendmany3notevalue - zsendmanyfee
assert_equal(self.nodes[1].z_getbalance(myzaddr), zaddrremaining2)
@ -128,7 +120,7 @@ class WalletNullifiersTest (BitcoinTestFramework):
importvk_result = self.nodes[3].z_importviewingkey(myzvkey, 'whenkeyisnew', 1)
# Check results of z_importviewingkey
assert_equal(importvk_result["type"], "sprout")
assert_equal(importvk_result["type"], "sapling")
assert_equal(importvk_result["address"], myzaddr)
# Check the address has been imported
@ -163,19 +155,17 @@ class WalletNullifiersTest (BitcoinTestFramework):
'total': node3mined + zsendmany2notevalue,
})
# Wallet can't cache nullifiers for notes received by addresses it only has a
# viewing key for, and therefore can't detect spends. So it sees a balance
# corresponding to the sum of all notes the address received.
# TODO: Fix this during the Sapling upgrade (via #2277)
# Wallet can cache nullifiers for Sapling notes received by addresses it only has a
# viewing key for.
assert_equal({k: Decimal(v) for k, v in self.nodes[3].z_gettotalbalance(1, True).items()}, {
'transparent': node3mined + Decimal('1.0'),
'private': zsendmany2notevalue + zsendmanynotevalue + zaddrremaining + zaddrremaining2,
'total': node3mined + Decimal('1.0') + zsendmany2notevalue + zsendmanynotevalue + zaddrremaining + zaddrremaining2,
'private': zsendmany2notevalue + zaddrremaining2,
'total': node3mined + Decimal('1.0') + zsendmany2notevalue + zaddrremaining2,
})
# Check individual balances reflect the above
assert_equal(self.nodes[3].z_getbalance(mytaddr1), Decimal('1.0'))
assert_equal(self.nodes[3].z_getbalance(myzaddr), zsendmanynotevalue + zaddrremaining + zaddrremaining2)
assert_equal(self.nodes[3].z_getbalance(myzaddr), zaddrremaining2)
if __name__ == '__main__':
WalletNullifiersTest().main ()

View File

@ -35,7 +35,7 @@ class WalletTreeStateTest (BitcoinTestFramework):
self.sync_all()
mytaddr = get_coinbase_address(self.nodes[0])
myzaddr = self.nodes[0].z_getnewaddress('sprout')
myzaddr = self.nodes[0].z_getnewaddress()
# Spend coinbase utxos to create three notes of 9.99990000 each
recipients = []
@ -66,15 +66,15 @@ class WalletTreeStateTest (BitcoinTestFramework):
# Tx 1 will change the treestate while Tx 2 containing chained joinsplits is still being generated
recipients = []
recipients.append({"address":self.nodes[2].z_getnewaddress('sprout'), "amount":Decimal('10.0') - Decimal('0.0001')})
recipients.append({"address":self.nodes[2].z_getnewaddress(), "amount":Decimal('10.0') - Decimal('0.0001')})
myopid = self.nodes[0].z_sendmany(mytaddr, recipients)
wait_and_assert_operationid_status(self.nodes[0], myopid)
# Tx 2 will consume all three notes, which must take at least two joinsplits. This is regardless of
# the z_sendmany implementation because there are only two inputs per joinsplit.
recipients = []
recipients.append({"address":self.nodes[2].z_getnewaddress('sprout'), "amount":Decimal('18')})
recipients.append({"address":self.nodes[2].z_getnewaddress('sprout'), "amount":Decimal('11.9997') - Decimal('0.0001')})
recipients.append({"address":self.nodes[2].z_getnewaddress(), "amount":Decimal('18')})
recipients.append({"address":self.nodes[2].z_getnewaddress(), "amount":Decimal('11.9997') - Decimal('0.0001')})
myopid = self.nodes[0].z_sendmany(myzaddr, recipients)
# Wait for Tx 2 to begin executing...

View File

@ -54,11 +54,9 @@ class ZkeyImportExportTest (BitcoinTestFramework):
try:
assert_equal(amts, [tx["amount"] for tx in txs])
for tx in txs:
# make sure JoinSplit keys exist and have valid values
assert_equal("jsindex" in tx, True)
assert_equal("jsoutindex" in tx, True)
assert_greater_than(tx["jsindex"], -1)
assert_greater_than(tx["jsoutindex"], -1)
# make sure Sapling outputs exist and have valid values
assert_equal("outindex" in tx, True)
assert_greater_than(tx["outindex"], -1)
except AssertionError:
logging.error(
'Expected amounts: %r; txs: %r',
@ -75,7 +73,7 @@ class ZkeyImportExportTest (BitcoinTestFramework):
miner.generate(100)
self.sync_all()
# Shield Alice's coinbase funds to her zaddr
alice_zaddr = alice.z_getnewaddress('sprout')
alice_zaddr = alice.z_getnewaddress()
res = alice.z_shieldcoinbase("*", alice_zaddr)
wait_and_assert_operationid_status(alice, res['opid'])
self.sync_all()
@ -83,7 +81,7 @@ class ZkeyImportExportTest (BitcoinTestFramework):
self.sync_all()
# Now get a pristine z-address for receiving transfers:
bob_zaddr = bob.z_getnewaddress('sprout')
bob_zaddr = bob.z_getnewaddress()
verify_utxos(bob, [], bob_zaddr)
# TODO: Verify that charlie doesn't have funds in addr
# verify_utxos(charlie, [])
@ -117,8 +115,8 @@ class ZkeyImportExportTest (BitcoinTestFramework):
# z_importkey should have rescanned for new key, so this should pass:
verify_utxos(charlie, amounts[:4], ipk_zaddr["address"])
# address is sprout
assert_equal(ipk_zaddr["type"], "sprout")
# address is Sapling
assert_equal(ipk_zaddr["type"], "sapling")
# Verify idempotent behavior:
ipk_zaddr2 = charlie.z_importkey(bob_privkey)