Skip to content

Commit

Permalink
func-tests: move common function to utilities and add more asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
voidash committed Dec 22, 2024
1 parent e856435 commit f0ed257
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
14 changes: 2 additions & 12 deletions functional-tests/fn_btcio_inscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import testenv
from constants import SEQ_PUBLISH_BATCH_INTERVAL_SECS
from utils import generate_n_blocks, wait_until
from utils import generate_n_blocks, submit_da_blob, wait_until


@flexitest.register
Expand Down Expand Up @@ -33,21 +33,11 @@ def main(self, ctx: flexitest.RunContext):

# Submit blob
blobdata = "2c4253d512da5bb4223f10e8e6017ede69cc63d6e6126916f4b68a1830b7f805"
_ = seqrpc.strataadmin_submitDABlob(blobdata)

# Allow some time for sequencer to publish blob
time.sleep(SEQ_PUBLISH_BATCH_INTERVAL_SECS)

l1_status = seqrpc.strata_l1status()
txid = l1_status["last_published_txid"]

tx = submit_da_blob(btcrpc, seqrpc, blobdata)
# Calculate scriptbpubkey for sequencer address
addrdata = btcrpc.proxy.validateaddress(seqaddr)
scriptpubkey = addrdata["scriptPubKey"]

# Check if txn is present in mempool/blockchain and is spent to sequencer address
tx = btcrpc.gettransaction(txid)

# NOTE: could have just compared address
# but bitcoinlib is somehow giving bc1* addr even though network is regtest
assert (
Expand Down
40 changes: 13 additions & 27 deletions functional-tests/fn_btcio_resubmit_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from bitcoinlib.services.bitcoind import BitcoindClient

from constants import SEQ_PUBLISH_BATCH_INTERVAL_SECS
from utils import generate_n_blocks, wait_until, wait_until_with_value
import testenv
from utils import generate_n_blocks, submit_da_blob, wait_until, wait_until_with_value, get_envelope_pushdata


@flexitest.register
class ResubmitCheckpointTest(flexitest.Test):
class ResubmitCheckpointTest(testenv.StrataTester):
def __init__(self, ctx: flexitest.InitContext):
ctx.set_env("basic")

Expand Down Expand Up @@ -43,43 +44,28 @@ def main(self, ctx: flexitest.RunContext):
try:
envelope_data = get_envelope_pushdata(tx.witness_data().hex())
except ValueError:
print("NOt a envelope transaction")
print("Not an envelope transaction")
continue

# submit envelope data
_ = seqrpc.strataadmin_submitDABlob(envelope_data)

# Allow some time for sequencer to get the blob
time.sleep(SEQ_PUBLISH_BATCH_INTERVAL_SECS)

l1_status = seqrpc.strata_l1status()
txid = l1_status["last_published_txid"]

tx = submit_da_blob(btcrpc, seqrpc, envelope_data)
# Calculate scriptbpubkey for sequencer address
addrdata = btcrpc.proxy.validateaddress(seqaddr)
scriptpubkey = addrdata["scriptPubKey"]

# Check if txn is present in mempool/blockchain and is spent to sequencer address
tx = btcrpc.gettransaction(txid)

# NOTE: could have just compared address
# but bitcoinlib is somehow giving bc1* addr even though network is regtest
assert (
tx.outputs[0].lock_script.hex() == scriptpubkey
), "Output should be locked to sequencer's scriptpubkey"

return True
# ensure that client is still up and running
wait_until(lambda: seqrpc.strata_protocolVersion() is not None,
error_with="sequencer rpc is not working")

# check if chain tip is being increased
cur_chain_tip = seqrpc.strata_clientStatus()['chain_tip_slot']
wait_until(lambda: seqrpc.strata_clientStatus()['chain_tip_slot'] > cur_chain_tip,
"chain tip slot hasn't changed since resubmit of checkpoint blob")

def get_envelope_pushdata(inp: str):
op_if = "63"
op_endif = "68"
op_pushbytes_33 = "21"
op_false = "00"
start_position = inp.index(f"{op_false}{op_if}")
end_position = inp.index(f"{op_endif}{op_pushbytes_33}", start_position)
op_if_block = inp[start_position + 3 : end_position]
op_pushdata = "4d"
pushdata_position = op_if_block.index(f"{op_pushdata}")
# we don't want PUSHDATA + num bytes b401
return op_if_block[pushdata_position + 2 + 4 :]
return True
28 changes: 28 additions & 0 deletions functional-tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any, Callable, Optional, TypeVar

from bitcoinlib.services.bitcoind import BitcoindClient
from seqrpc import JsonrpcClient
from strata_utils import convert_to_xonly_pk, musig_aggregate_pks

from constants import *
Expand Down Expand Up @@ -464,3 +465,30 @@ def setup_test_logger(datadir_root: str, test_name: str) -> logging.Logger:
logger.addHandler(stream_handler)

return logger

def get_envelope_pushdata(inp: str):
op_if = "63"
op_endif = "68"
op_pushbytes_33 = "21"
op_false = "00"
start_position = inp.index(f"{op_false}{op_if}")
end_position = inp.index(f"{op_endif}{op_pushbytes_33}", start_position)
op_if_block = inp[start_position + 3 : end_position]
op_pushdata = "4d"
pushdata_position = op_if_block.index(f"{op_pushdata}")
# we don't want PUSHDATA + num bytes b401
return op_if_block[pushdata_position + 2 + 4 :]

def submit_da_blob(btcrpc: BitcoindClient , seqrpc: JsonrpcClient, blobdata: str):
_ = seqrpc.strataadmin_submitDABlob(blobdata)

# Allow some time for sequencer to publish blob
time.sleep(SEQ_PUBLISH_BATCH_INTERVAL_SECS)

l1_status = seqrpc.strata_l1status()
txid = l1_status["last_published_txid"]

tx = btcrpc.gettransaction(txid)
return tx


0 comments on commit f0ed257

Please sign in to comment.