Skip to content

Commit

Permalink
func-test: debug withdrawal op_return - return of jedi
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Jan 20, 2025
1 parent 521f91e commit 4beb409
Showing 1 changed file with 32 additions and 44 deletions.
76 changes: 32 additions & 44 deletions functional-tests/tests/bridge_withdraw_happy_op_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from strata_utils import get_balance, string_to_opreturn_descriptor

from envs import net_settings, testenv
from utils import check_initial_eth_balance, generate_n_blocks, get_bridge_pubkey, wait_until
from utils import check_initial_eth_balance, get_bridge_pubkey, wait_until

# Local constants
# Gas for the withdrawal transaction
Expand Down Expand Up @@ -34,11 +34,9 @@ def __init__(self, ctx: flexitest.InitContext):
def main(self, ctx: flexitest.RunContext):
btc = ctx.get_service("bitcoin")
seq = ctx.get_service("sequencer")
reth = ctx.get_service("reth")
# create both btc and sequencer RPC
btcrpc: BitcoindClient = btc.create_rpc()
seqrpc = seq.create_rpc()
rethrpc = reth.create_rpc()

# Wait for seq
wait_until(
Expand Down Expand Up @@ -76,49 +74,39 @@ def main(self, ctx: flexitest.RunContext):
self.deposit(ctx, el_address, bridge_pk)

# Withdraw
l2_tx_hash, _tx_receipt, _total_gas_used = self.withdraw(ctx, el_address, bosd)

return True

# FIXME: Test that the actual payload is being withdrawn in L1
l2_block_hash = rethrpc.eth_getTransactionByHash(l2_tx_hash)["blockHash"]

# Make sure that the OP_RETURN is in the Strata block execution update
# FIXME: I have no idea how to do this
exec_update = seqrpc.strata_getExecUpdateById(l2_block_hash)
self.debug(f"Exec update: {exec_update}")
print(f"Exec update: {exec_update}") # FIXME: REMOVE ME
update_idx = exec_update["update_idx"]
self.debug(f"Exec update index: {update_idx}")
print(f"Exec update index: {update_idx}") # FIXME: REMOVE ME
sync_event = seqrpc.strata_getSyncEvent(update_idx)
self.debug(f"Sync event: {sync_event}")
print(f"Sync event: {sync_event}") # FIXME: REMOVE ME

withdrawals = exec_update["withdrawals"]
self.debug(f"Exec update withdrawals: {withdrawals}")
print(f"Exec update withdrawals: {withdrawals}") # FIXME: REMOVE ME

# Move forward a single block
block = generate_n_blocks(btcrpc, 1)[0] # There's only one
last_block = btcrpc.getblock(block)

# Get all withdraw bridge messages
# VODepositSig(10)
scope = "00"
self.debug(scope)

msgs = seqrpc.strata_getBridgeMsgsByScope(scope)
self.debug(msgs)
print(f"Bridge msgs: {msgs}") # FIXME: REMOVE ME

# Get the output of the tx
# OP_RETURN is the second output
# FIXME: I have no idea how to do this
outputs = last_block["txs"][0].as_dict()["outputs"]
op_return_output = outputs[1]
_, withdraw_tx_receipt, _ = self.withdraw(ctx, el_address, bosd)

# Collect L2 and L1 blocks where the withdrawal has happened.
l2_withdraw_block_num = withdraw_tx_receipt["blockNumber"]
self.info(f"withdrawal block num on L2: {l2_withdraw_block_num}")

last_block_hash = btcrpc.proxy.getblockchaininfo()["bestblockhash"]
last_block = btcrpc.getblock(last_block_hash)
# Check all blocks down from the latest.
# Those blocks will have only coinbase tx for all the empty blocks.
# Block with the withdrawal transfer will have at least two transactions.
while len(last_block["txs"]) <= 1:
last_block = btcrpc.getblock(last_block["prev_block"])
l1_withdraw_block_height = last_block["height"]
self.info(f"withdrawal block height on L1: {l1_withdraw_block_height}")

print(f"last block txs: {last_block['txs'].as_dict()}") # FIXME: REMOVE ME

# Get the output of the tx that is not the conibase tx
outputs = last_block["txs"][1].as_dict()["outputs"]
# OP_RETURN is the first output
op_return_output = outputs[0]
self.debug(f"OP_RETURN output: {op_return_output}")

# Check if it is a nulldata output
op_return_script_type = op_return_output["script_type"]
assert op_return_script_type == "nulldata", "OP_RETURN not found"

# Check the payload
op_return_data = op_return_output["script"]
# The same transformation (remove the <OP_RETURN> <LEN>)
op_return_payload = op_return_data[4:]
reconstructed_bosd = string_to_opreturn_descriptor(op_return_payload)
assert reconstructed_bosd == bosd, "Reconstructed BOSD is not the same as the original"

return True

0 comments on commit 4beb409

Please sign in to comment.