From 8e840c378d7cbf80b073cb654581600977fcb00a Mon Sep 17 00:00:00 2001 From: lesterli Date: Tue, 27 Aug 2024 18:31:43 +0800 Subject: [PATCH] chore: no BTC delegation, no power --- itest/opstackl2/op_e2e_test.go | 25 ++++++++++++++----------- itest/opstackl2/op_test_manager.go | 23 ----------------------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/itest/opstackl2/op_e2e_test.go b/itest/opstackl2/op_e2e_test.go index 741eba79..e421d5ab 100644 --- a/itest/opstackl2/op_e2e_test.go +++ b/itest/opstackl2/op_e2e_test.go @@ -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) @@ -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: @@ -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) @@ -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) diff --git a/itest/opstackl2/op_test_manager.go b/itest/opstackl2/op_test_manager.go index 54100037..746bcc75 100644 --- a/itest/opstackl2/op_test_manager.go +++ b/itest/opstackl2/op_test_manager.go @@ -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