Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions test/functional/feature_fedpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
p2p_port,
assert_raises_rpc_error,
assert_equal,
bytes_to_hex_str,
)
from test_framework import util
from test_framework.messages import (
CBlock,
CTransaction,
CTxInWitness,
FromHex,
)
from test_framework.blocktools import (
add_witness_commitment,
)
from decimal import Decimal

def get_new_unconfidential_address(node, addr_type="p2sh-segwit"):
Expand Down Expand Up @@ -226,8 +232,11 @@ def run_test(self):

pegtxid1 = sidechain.claimpegin(raw, proof)
# Make sure it can't get accepted twice.
pegtxid2 = sidechain.claimpegin(raw, proof)
assert(pegtxid2 not in sidechain.getrawmempool())
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assert_raises_rpc_error instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also make it clearer that this is a mempool-mempool conflict, versus:

block-mempool

block-block

sidechain.claimpegin(raw, proof)
raise Exception("double spending claimpegin should not be accepted")
except JSONRPCException as e:
assert("txn-mempool-conflict" in e.error["message"])

# Will invalidate the block that confirms this transaction later
self.sync_all(self.node_groups)
Expand Down Expand Up @@ -266,11 +275,26 @@ def run_test(self):
raise Exception("Peg-in should be back to 6 confirms.")

# Make sure it can't get accepted twice.
pegtxid2 = sidechain.claimpegin(raw, proof)
assert(pegtxid2 not in sidechain.getrawmempool())
sidechain.generate(7)
if sidechain.gettransaction(pegtxid2)["confirmations"] > 0:
raise Exception("Pegin should not be able to get confirmed")
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assert_raises_rpc_error instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is block-mempool conflict

sidechain.claimpegin(raw, proof)
raise Exception("double spending claimpegin should not be accepted")
except JSONRPCException as e:
assert("pegin-already-claimed" in e.error["message"])
# Also check it won't be accepted in a block.
raw_pegin = sidechain.createrawpegin(raw, proof)["hex"]
raw_pegin = sidechain.signrawtransactionwithwallet(raw_pegin)["hex"]
raw_pegin = FromHex(CTransaction(), raw_pegin)
doublespendblock = FromHex(CBlock(), sidechain.getnewblockhex())
doublespendblock.vtx.append(raw_pegin)
util.node_fastmerkle = sidechain
doublespendblock.hashMerkleRoot = doublespendblock.calc_merkle_root()
add_witness_commitment(doublespendblock)
doublespendblock.solve()
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assert_raises_rpc_error instead

sidechain.testproposedblock(bytes_to_hex_str(doublespendblock.serialize(True)), True)
raise Exception("block should not be accepted")
except JSONRPCException as e:
assert("bad-txns-double-pegin" in e.error["message"])

# Do multiple claims in mempool
n_claims = 6
Expand Down