Skip to content

Commit

Permalink
[Tests] sort exported mints by denom in zc_spends and zc_wrapped_serials
Browse files Browse the repository at this point in the history
thus remove the edge case resulting in exception ""You don't have enough
Zerocoins in your wallet" when the double.
Github-Pull: #1218
Rebased-From: 7851bc9
  • Loading branch information
random-zebra authored and Fuzzbawls committed Jan 11, 2020
1 parent 0538d25 commit 44c60dc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
13 changes: 12 additions & 1 deletion test/functional/mining_pos_reorg.py
Expand Up @@ -3,6 +3,7 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

from test_framework.authproxy import JSONRPCException
from test_framework.test_framework import PivxTestFramework
from test_framework.util import (
sync_blocks,
Expand Down Expand Up @@ -156,7 +157,17 @@ def findUtxoInList(txid, vout, utxo_list):
{"xxncEuJK27ygNh7imNfaX8JV6ZQUnoBqzN": (stakeinput_amount-0.01)})
rawtx = self.nodes[0].signrawtransaction(rawtx_unsigned)
assert(rawtx["complete"])
assert_raises_rpc_error(-26, "bad-txns-inputs-spent", self.nodes[0].sendrawtransaction, rawtx["hex"])
try:
self.nodes[0].sendrawtransaction(rawtx["hex"])
except JSONRPCException as e:
# JSONRPCException was thrown as expected. Check the code and message values are correct.
if e.error["code"] not in [-24, -25]:
raise AssertionError("Unexpected JSONRPC error code %i" % e.error["code"])
if ([x for x in ["bad-txns-inputs-spent", "Missing inputs"] if x in e.error['message']] == []):
raise e
except Exception as e:
raise AssertionError("Unexpected exception raised: " + type(e).__name__)
self.log.info("GOOD: v2 spend was not possible.")

# Spend tx_B0 and tx_B1 on the other chain
self.nodes[1].sendrawtransaction(tx_B0)
Expand Down
24 changes: 8 additions & 16 deletions test/functional/zerocoin_spends.py
Expand Up @@ -55,19 +55,7 @@ def setV4SpendEnforcement(self, fEnable=True):
assert_equal(fEnable, self.is_spork_active(1, sporkName))
self.log.info("done")

def check_double_spend(self, node_id, serial, randomness, denom, privkey, tx):
try:
self.nodes[node_id].spendrawzerocoin(serial, randomness, denom, privkey, "", tx)
except JSONRPCException as e:
# JSONRPCException was thrown as expected. Check the code and message values are correct.
if e.error["code"] != -4:
raise AssertionError("Unexpected JSONRPC error code %i" % e.error["code"])
if ([x for x in ["Trying to spend an already spent serial",
"You don't have enough Zerocoins in your wallet"] if x in e.error['message']] == []):
raise e
except Exception as e:
raise AssertionError("Unexpected exception raised: " + type(e).__name__)
self.log.info("GOOD: Double-spending transaction did not verify.")


def run_test(self):

Expand Down Expand Up @@ -104,6 +92,7 @@ def stake_4_blocks(block_time):
listmints = self.nodes[2].listmintedzerocoins(True, True)
serial_ids = [mint["serial hash"] for mint in listmints]
exported_zerocoins = [x for x in self.nodes[2].exportzerocoins(False) if x["id"] in serial_ids]
exported_zerocoins.sort(key=lambda x: x["d"], reverse=False)
assert_equal(8, len(exported_zerocoins))

# 1) Try to do a v3 spend before activation
Expand Down Expand Up @@ -159,7 +148,8 @@ def stake_4_blocks(block_time):

# 6) Check double spends - spend v3
self.log.info("Trying to spend the serial twice now...")
self.check_double_spend(2, serial_2, randomness_2, denom_2, privkey_2, tx_2)
assert_raises_rpc_error(-4, "Trying to spend an already spent serial",
self.nodes[2].spendrawzerocoin, serial_2, randomness_2, denom_2, privkey_2, "", tx_2)


# 7) Activate v4 spends with SPORK_18
Expand All @@ -177,7 +167,8 @@ def stake_4_blocks(block_time):

# 9) Check double spends - spend v4
self.log.info("Trying to spend the serial twice now...")
self.check_double_spend(2, serial_3, randomness_3, denom_3, privkey_3, tx_3)
assert_raises_rpc_error(-4, "Trying to spend an already spent serial",
self.nodes[2].spendrawzerocoin, serial_3, randomness_3, denom_3, privkey_3, "", tx_3)

# 10) Try to relay old v3 spend now (serial_1)
self.log.info("Trying to send old v3 spend now...")
Expand All @@ -187,7 +178,8 @@ def stake_4_blocks(block_time):

# 11) Try to double spend with v4 a mint already spent with v3 (serial_2)
self.log.info("Trying to double spend v4 against v3...")
self.check_double_spend(2, serial_2, randomness_2, denom_2, privkey_2, tx_2)
assert_raises_rpc_error(-4, "Trying to spend an already spent serial",
self.nodes[2].spendrawzerocoin, serial_2, randomness_2, denom_2, privkey_2, "", tx_2)
self.log.info("GOOD: Double-spending transaction did not verify.")

# 12) Reactivate v3 spends and try to spend the old saved one (serial_1) again
Expand Down
1 change: 1 addition & 0 deletions test/functional/zerocoin_wrapped_serials.py
Expand Up @@ -93,6 +93,7 @@ def stake_4_blocks(block_time):
listmints = self.nodes[2].listmintedzerocoins(True, True)
serial_ids = [mint["serial hash"] for mint in listmints]
exported_zerocoins = [x for x in self.nodes[2].exportzerocoins(False) if x["id"] in serial_ids]
exported_zerocoins.sort(key=lambda x: x["d"], reverse=False)
assert_equal(8, len(exported_zerocoins))

# 1) Spend 1 coin and mine two more blocks
Expand Down

0 comments on commit 44c60dc

Please sign in to comment.