diff --git a/Makefile b/Makefile index 4e3942d2..b8f27b41 100644 --- a/Makefile +++ b/Makefile @@ -125,16 +125,6 @@ test-e2e-op-ci: clean-e2e install-babylond "xargs go test -race -mod=readonly -timeout=25m -v $(PACKAGES_E2E_OP) -count=1 --tags=e2e_op --run" \ --split-by=name --timings-type=name -DEVNET_REPO_URL := https://github.com/babylonlabs-io/op-e2e-devnet -TARGET_DIR := ./itest/opstackl2/devnet-data - -.PHONY: op-e2e-devnet -op-e2e-devnet: - @rm -rf $(TARGET_DIR) - @mkdir -p $(TARGET_DIR) - @git clone $(DEVNET_REPO_URL) $(TARGET_DIR) - @echo "Devnet data downloaded to $(TARGET_DIR)" - ############################################################################### ### Protobuf ### ############################################################################### diff --git a/finality-provider/service/app.go b/finality-provider/service/app.go index 3dd2b7a4..df8b5204 100644 --- a/finality-provider/service/app.go +++ b/finality-provider/service/app.go @@ -332,6 +332,24 @@ func (app *FinalityProviderApp) Start() error { return startErr } +// StartWithoutSyncFpStatus starts only the finality-provider daemon without any finality-provider instances +// and without syncing the finality-provider status loop for testing purpose +// b/c this loop detects FP status and then automatically starts the FP instance when it is ACTIVE +// Note: this is only for testing purposes +func (app *FinalityProviderApp) StartWithoutSyncFpStatus() error { + var startErr error + app.startOnce.Do(func() { + app.logger.Info("Starting FinalityProviderApp") + + app.wg.Add(3) + go app.eventLoop() + go app.registrationLoop() + go app.metricsUpdateLoop() + }) + + return startErr +} + func (app *FinalityProviderApp) Stop() error { var stopErr error app.stopOnce.Do(func() { diff --git a/itest/opstackl2/README.md b/itest/opstackl2/README.md index c18acb22..4d9089ab 100644 --- a/itest/opstackl2/README.md +++ b/itest/opstackl2/README.md @@ -1,19 +1,11 @@ # OP-stack itest -To run the e2e tests, first you need to set up the devnet data: +Run the following command to start the e2e tests: ```bash -$ make op-e2e-devnet -``` - -Then run the following command to start the e2e tests: - -```bash -$ make test-e2e-op - # Run all tests -$ make test-e2e-op +make test-e2e-op # Filter specific test -$ make test-e2e-op-filter FILTER=TestFinalityGadget +make test-e2e-op-filter FILTER=TestPubRandCommitment ``` diff --git a/itest/opstackl2/op_e2e_test.go b/itest/opstackl2/op_e2e_test.go index 4e3be08a..4c07cd9b 100644 --- a/itest/opstackl2/op_e2e_test.go +++ b/itest/opstackl2/op_e2e_test.go @@ -5,10 +5,14 @@ package e2etest_op import ( "testing" + + "github.com/stretchr/testify/require" ) -// This test case will be removed by the final PR -func TestOpTestManagerSetup(t *testing.T) { +// TestPubRandCommitment tests the consumer controller's functions: +// - CommitPubRandList +// - QueryLastPublicRandCommit +func TestPubRandCommitment(t *testing.T) { ctm := StartOpL2ConsumerManager(t) defer ctm.Stop(t) @@ -16,5 +20,25 @@ func TestOpTestManagerSetup(t *testing.T) { fps := ctm.setupBabylonAndConsumerFp(t) // send a BTC delegation and wait for activation - ctm.delegateBTCAndWaitForActivation(t, fps[0], fps[1]) + consumerFpPk := fps[1] + ctm.delegateBTCAndWaitForActivation(t, fps[0], consumerFpPk) + + // get the consumer FP instance + consumerFpInstance := ctm.getConsumerFpInstance(t, consumerFpPk) + + // commit pub rand with start height 1 + // this will call consumer controller's CommitPubRandList function + _, err := consumerFpInstance.CommitPubRand(1) + require.NoError(t, err) + + // query the last pub rand + pubRand, err := ctm.OpConsumerController.QueryLastPublicRandCommit(consumerFpPk.MustToBTCPK()) + require.NoError(t, err) + require.NotNil(t, pubRand) + + // check the end height of the pub rand + // endHeight = startHeight + numberPubRand - 1 + // startHeight is 1 in this case, so EndHeight should equal NumPubRand + consumerCfg := ctm.ConsumerFpApp.GetConfig() + require.Equal(t, uint64(consumerCfg.NumPubRand), pubRand.EndHeight()) } diff --git a/itest/opstackl2/op_test_manager.go b/itest/opstackl2/op_test_manager.go index 42f0f4ac..13b9d8cf 100644 --- a/itest/opstackl2/op_test_manager.go +++ b/itest/opstackl2/op_test_manager.go @@ -17,6 +17,7 @@ import ( bbncc "github.com/babylonlabs-io/finality-provider/clientcontroller/babylon" opcc "github.com/babylonlabs-io/finality-provider/clientcontroller/opstackl2" cwclient "github.com/babylonlabs-io/finality-provider/cosmwasmclient/client" + "github.com/babylonlabs-io/finality-provider/eotsmanager/client" eotsconfig "github.com/babylonlabs-io/finality-provider/eotsmanager/config" fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config" "github.com/babylonlabs-io/finality-provider/finality-provider/service" @@ -50,6 +51,7 @@ type OpL2ConsumerTestManager struct { EOTSServerHandler *e2eutils.EOTSServerHandler BabylonFpApp *service.FinalityProviderApp ConsumerFpApp *service.FinalityProviderApp + ConsumerEOTSClient *client.EOTSManagerGRpcClient } // Config is the config of the OP finality gadget cw contract @@ -139,6 +141,7 @@ func StartOpL2ConsumerManager(t *testing.T) *OpL2ConsumerTestManager { EOTSServerHandler: eotsHandler, BabylonFpApp: babylonFpApp, ConsumerFpApp: consumerFpApp, + ConsumerEOTSClient: EOTSClients[1], } return ctm @@ -335,6 +338,22 @@ func (ctm *OpL2ConsumerTestManager) setupBabylonAndConsumerFp(t *testing.T) []*b return []*bbntypes.BIP340PubKey{babylonFpPk, consumerFpPk} } +func (ctm *OpL2ConsumerTestManager) getConsumerFpInstance( + t *testing.T, + consumerFpPk *bbntypes.BIP340PubKey, +) *service.FinalityProviderInstance { + fpCfg := ctm.ConsumerFpApp.GetConfig() + fpStore := ctm.ConsumerFpApp.GetFinalityProviderStore() + pubRandStore := ctm.ConsumerFpApp.GetPubRandProofStore() + bc := ctm.BabylonFpApp.GetBabylonController() + logger := ctm.ConsumerFpApp.Logger() + fpInstance, err := service.TestNewUnregisteredFinalityProviderInstance( + consumerFpPk, fpCfg, fpStore, pubRandStore, bc, ctm.OpConsumerController, ctm.ConsumerEOTSClient, + metrics.NewFpMetrics(), "", make(chan<- *service.CriticalError), logger) + require.NoError(t, err) + return fpInstance +} + func (ctm *OpL2ConsumerTestManager) delegateBTCAndWaitForActivation(t *testing.T, babylonFpPk *bbntypes.BIP340PubKey, consumerFpPk *bbntypes.BIP340PubKey) { // send a BTC delegation ctm.InsertBTCDelegation(t, []*btcec.PublicKey{babylonFpPk.MustToBTCPK(), consumerFpPk.MustToBTCPK()}, @@ -355,9 +374,13 @@ func (ctm *OpL2ConsumerTestManager) delegateBTCAndWaitForActivation(t *testing.T func (ctm *OpL2ConsumerTestManager) Stop(t *testing.T) { t.Log("Stopping test manager") var err error + err = ctm.BabylonFpApp.Stop() + require.NoError(t, err) + err = ctm.ConsumerFpApp.Stop() + require.NoError(t, err) err = ctm.BabylonHandler.Stop() require.NoError(t, err) - + ctm.EOTSServerHandler.Stop() err = os.RemoveAll(ctm.BaseDir) require.NoError(t, err) } diff --git a/itest/test-manager/base_test_manager.go b/itest/test-manager/base_test_manager.go index 8b04aa22..a85d6234 100644 --- a/itest/test-manager/base_test_manager.go +++ b/itest/test-manager/base_test_manager.go @@ -603,7 +603,7 @@ func CreateAndStartFpApp( fpApp, err := service.NewFinalityProviderApp(cfg, bc, cc, eotsCli, fpdb, logger) require.NoError(t, err) - err = fpApp.Start() + err = fpApp.StartWithoutSyncFpStatus() require.NoError(t, err) return fpApp