Skip to content

Commit

Permalink
chore: no BTC delegation, no power
Browse files Browse the repository at this point in the history
  • Loading branch information
lesterli committed Aug 27, 2024
1 parent cf5b2f2 commit 8e840c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
25 changes: 14 additions & 11 deletions itest/opstackl2/op_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/stretchr/testify/require"
)

// tests the finality signature submission to the op-finality-gadget contract
func TestOpSubmitFinalitySignature(t *testing.T) {
// TestOpFpNoVotingPower tests that the FP has no voting power if it has no BTC delegation
func TestOpFpNoVotingPower(t *testing.T) {
ctm := StartOpL2ConsumerManager(t, 1)
defer ctm.Stop(t)

Expand All @@ -35,19 +35,20 @@ func TestOpSubmitFinalitySignature(t *testing.T) {
testBlocks := ctm.WaitForNBlocksAndReturn(t, committedStartHeight, 1)
testBlock := testBlocks[0]

// wait for the fp sign
ctm.WaitForFpVoteReachHeight(t, fpInstance, testBlock.Height)
queryBlock := &fgtypes.Block{
BlockHeight: testBlock.Height,
BlockHash: hex.EncodeToString(testBlock.Hash),
BlockTimestamp: 12345, // doesn't matter b/c the BTC client is mocked
}

// note: QueryFinalityProviderHasPower is hardcode to return true so FPs can still submit finality sigs even if they
// don't have voting power. But the finality sigs will not be counted at tally time.
// no BTC delegation, so the FP has no voting power
hasPower, err := opcc.QueryFinalityProviderHasPower(fpInstance.GetBtcPk(), queryBlock.BlockHeight)
require.NoError(t, err)
require.Equal(t, false, hasPower)

_, err = ctm.FinalityGadget.QueryIsBlockBabylonFinalized(queryBlock)
require.ErrorIs(t, err, fgtypes.ErrBtcStakingNotActivated)
t.Logf(log.Prefix("Expected no voting power"))
t.Logf(log.Prefix("Expected BTC staking not activated"))
}

// This test has two test cases:
Expand Down Expand Up @@ -136,8 +137,9 @@ func TestFinalityStuckAndRecover(t *testing.T) {
})
fpInstance := fpList[0]

// wait until the BTC staking is activated
l2BlockAfterActivation := ctm.waitForBTCStakingActivation(t)
// BTC delegations are activated after SetupFinalityProviders
l2BlockAfterActivation, err := ctm.getOpCCAtIndex(0).QueryLatestBlockHeight()
require.NoError(t, err)

// wait for the first block to be finalized since BTC staking is activated
e2eutils.WaitForFpPubRandCommittedReachTargetHeight(t, fpInstance, l2BlockAfterActivation)
Expand Down Expand Up @@ -210,8 +212,9 @@ func TestFinalityGadgetServer(t *testing.T) {
e2eutils.WaitForFpPubRandCommitted(t, fpList[i])
}

// wait until the BTC staking is activated
l2BlockAfterActivation := ctm.waitForBTCStakingActivation(t)
// BTC delegations are activated after SetupFinalityProviders
l2BlockAfterActivation, err := ctm.getOpCCAtIndex(0).QueryLatestBlockHeight()
require.NoError(t, err)

// both FP will sign the first block
targetBlockHeight := ctm.WaitForTargetBlockPubRand(t, fpList, l2BlockAfterActivation)
Expand Down
23 changes: 0 additions & 23 deletions itest/opstackl2/op_test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,29 +937,6 @@ func queryFirstOrLastPublicRandCommit(
return resp, nil
}

func (ctm *OpL2ConsumerTestManager) waitForBTCStakingActivation(t *testing.T) uint64 {
var l2BlockAfterActivation uint64
require.Eventually(t, func() bool {
latestBlockHeight, err := ctm.getOpCCAtIndex(0).QueryLatestBlockHeight()
require.NoError(t, err)
latestBlock, err := ctm.getOpCCAtIndex(0).QueryEthBlock(latestBlockHeight)
require.NoError(t, err)
l2BlockAfterActivation = latestBlock.Number.Uint64()

activatedTimestamp, err := ctm.FinalityGadget.QueryBtcStakingActivatedTimestamp()
if err != nil {
t.Logf(log.Prefix("Failed to query BTC staking activated timestamp: %v"), err)
return false
}
t.Logf(log.Prefix("Activated timestamp %d"), activatedTimestamp)

return latestBlock.Time >= activatedTimestamp
}, 30*ctm.getL2BlockTime(), ctm.getL2BlockTime())

t.Logf(log.Prefix("found a L2 block after BTC staking activation: %d"), l2BlockAfterActivation)
return l2BlockAfterActivation
}

func (ctm *OpL2ConsumerTestManager) Stop(t *testing.T) {
t.Log("Stopping test manager")
var err error
Expand Down

0 comments on commit 8e840c3

Please sign in to comment.