Skip to content

Commit

Permalink
Functional test coverage + various test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed May 18, 2023
1 parent 66b6f9d commit 2d5d42b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion test/functional/mining_pos_coldStaking.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def run_test(self):
self.sync_blocks()
# lock the change output (so it's not used as stake input in generate_pos)
for x in self.nodes[1].listunspent():
assert (self.nodes[1].lockunspent(False, [{"txid": x['txid'], "vout": x['vout']}]))
assert (self.nodes[1].lockunspent(False, True, [{"txid": x['txid'], "vout": x['vout']}]))
# check that it cannot stake
sleep(1)
assert_equal(self.nodes[1].getstakingstatus()["stakeablecoins"], 0)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run_test(self):

# Lock UTXO so nodes[0] doesn't accidentally spend it
self.watchonly_vout = find_vout_for_address(self.nodes[0], self.watchonly_txid, watchonly_address)
self.nodes[0].lockunspent(False, [{"txid": self.watchonly_txid, "vout": self.watchonly_vout}])
self.nodes[0].lockunspent(False, True, [{"txid": self.watchonly_txid, "vout": self.watchonly_vout}])

self.nodes[0].sendtoaddress(self.nodes[3].getnewaddress(), float(self.watchonly_amount) / 10)

Expand Down
30 changes: 29 additions & 1 deletion test/functional/sapling_wallet_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from test_framework.test_framework import PivxTestFramework
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)


Expand All @@ -31,7 +32,7 @@ def run_test(self):
saplingAddr1 = self.nodes[1].getnewshieldaddress()

# Verify addresses
assert(saplingAddr1 in self.nodes[1].listshieldaddresses())
assert (saplingAddr1 in self.nodes[1].listshieldaddresses())
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), Decimal('0'))
assert_equal(self.nodes[1].getreceivedbyaddress(taddr1), Decimal('0'))

Expand Down Expand Up @@ -83,6 +84,33 @@ def run_test(self):
assert_equal(self.nodes[1].getreceivedbyaddress(taddr1), taddr1_bal)
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), saplingAddr1_bal)

# Test Sapling Lock Notes, at this point node0 has only 1 sapling spendable note
self.log.info("Checking lockunspent for sapling notes")

assert_equal(len(self.nodes[1].listlockunspent()["transparent"]), 0)
assert_equal(len(self.nodes[1].listlockunspent()["shielded"]), 0)

assert_equal(len(self.nodes[0].listshieldunspent()), 1)
unspent_1 = self.nodes[0].listshieldunspent()[0]
assert unspent_1["spendable"]
unspent_1 = {"txid": unspent_1["txid"], "vout": unspent_1["outindex"]}

# Lock the note and verify that you cannot spend it
self.nodes[0].lockunspent(False, False, [unspent_1])
recipient2 = [{"address": self.nodes[2].getnewshieldaddress(), "amount": Decimal('1')}]
assert_raises_rpc_error(-4, "Insufficient funds, no available notes to spend", self.nodes[0].shieldsendmany, "from_shield", recipient2)

# Verify that the sapling note is locked
output_unspent_1 = {"txid": unspent_1["txid"], "vShieldedOutput": unspent_1["vout"]}
assert_equal(len(self.nodes[0].listlockunspent()["transparent"]), 0)
assert_equal([output_unspent_1], self.nodes[0].listlockunspent()["shielded"])

# Unlock the note and send the tx
self.nodes[0].lockunspent(True, False, [unspent_1])
assert_equal(len(self.nodes[0].listlockunspent()["transparent"]), 0)
assert_equal(len(self.nodes[0].listlockunspent()["shielded"]), 0)
self.nodes[0].shieldsendmany("from_shield", recipient2)


if __name__ == '__main__':
SaplingWalletSend().main()
2 changes: 1 addition & 1 deletion test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ def setupMasternode(self,
file_object.write(confData)

# lock collateral
mnOwner.lockunspent(False, [{"txid": collateralTxId, "vout": collateralTxId_n}])
mnOwner.lockunspent(False, True, [{"txid": collateralTxId, "vout": collateralTxId_n}])

# return the collateral outpoint
return COutPoint(collateralTxId, collateralTxId_n)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def get_coinstake_address(node, expected_utxos=None):

# Deterministic masternodes
def is_coin_locked_by(node, outpoint):
return outpoint.to_json() in node.listlockunspent()
return outpoint.to_json() in node.listlockunspent()["transparent"]

def get_collateral_vout(json_tx):
funding_txidn = -1
Expand Down
2 changes: 1 addition & 1 deletion test/functional/tiertwo_deterministicmns.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def run_test(self):
self.log.info("Done. Now mine blocks till enforcement...")

# Check that no coin has been locked by the controller yet
assert_equal(len(controller.listlockunspent()), 0)
assert_equal(len(controller.listlockunspent()["transparent"]), 0)

# DIP3 activates at block 130.
miner.generate(130 - miner.getblockcount())
Expand Down
2 changes: 1 addition & 1 deletion test/functional/tiertwo_reorg_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def run_test(self):

# Lock any utxo with less than 106 confs (e.g. change), so we can resurrect everything
for x in nodeA.listunspent(0, 106):
nodeA.lockunspent(False, [{"txid": x["txid"], "vout": x["vout"]}])
nodeA.lockunspent(False, True, [{"txid": x["txid"], "vout": x["vout"]}])

# Now send a valid proReg tx to the mempool, without mining it
mempool_dmn1 = create_new_dmn(free_idx, nodeA, collateral_addr, None)
Expand Down
8 changes: 4 additions & 4 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def run_test(self):
assert unspent_0["spendable"]
assert unspent_0["safe"]
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
self.nodes[1].lockunspent(False, [unspent_0])
self.nodes[1].lockunspent(False, True, [unspent_0])
assert_raises_rpc_error(-4, "Insufficient funds", self.nodes[1].sendtoaddress, self.nodes[1].getnewaddress(), 20)
assert_equal([unspent_0], self.nodes[1].listlockunspent())
self.nodes[1].lockunspent(True, [unspent_0])
assert_equal(len(self.nodes[1].listlockunspent()), 0)
assert_equal([unspent_0], self.nodes[1].listlockunspent()["transparent"])
self.nodes[1].lockunspent(True, True, [unspent_0])
assert_equal(len(self.nodes[1].listlockunspent()["transparent"]), 0)

# Send 21 PIV from 1 to 0 using sendtoaddress call.
# Locked memory should use at least 32 bytes to sign the transaction
Expand Down

0 comments on commit 2d5d42b

Please sign in to comment.