Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: op e2e finality gadget daemon itest #26

Merged
merged 11 commits into from
Aug 12, 2024
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
test_e2e_op:
machine:
image: ubuntu-2204:2024.01.1
parallelism: 3
parallelism: 4
resource_class: large
steps:
- go/install:
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TOOLS_DIR := tools

BABYLON_PKG := github.com/babylonlabs-io/babylon/cmd/babylond
WASMD_PKG := github.com/CosmWasm/wasmd/cmd/wasmd
BCD_PKG := github.com/babylonchain/babylon-sdk/demo/cmd/bcd
BCD_PKG := github.com/babylonlabs-io/babylon-sdk/demo/cmd/bcd

GO_BIN := ${GOPATH}/bin
BTCD_BIN := $(GO_BIN)/btcd
Expand Down Expand Up @@ -112,8 +112,9 @@ test-e2e-bcd: clean-e2e install-babylond install-bcd
test-e2e-wasmd: clean-e2e install-babylond install-wasmd
@go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e_wasmd

FILTER ?= .
test-e2e-op: clean-e2e install-babylond
@go test -race -mod=readonly -timeout=25m -v $(PACKAGES_E2E_OP) -count=1 --tags=e2e_op
@go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E_OP) -count=1 --tags=e2e_op --run ^$(FILTER)$

test-e2e-op-ci: clean-e2e install-babylond
go test -list . ./itest/opstackl2 --tags=e2e_op | grep Test \
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonchain/babylon-sdk/demo v0.0.0-20240705194516-4e2c5650cde8
github.com/babylonlabs-io/babylon v0.9.0
github.com/babylonlabs-io/babylon-finality-gadget v0.0.0-20240801002122-6d6bca47ec56
github.com/babylonlabs-io/finality-gadget v0.1.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.5
Expand Down Expand Up @@ -381,7 +381,7 @@ require (
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.etcd.io/bbolt v1.3.10 // indirect
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/v2 v2.305.10 // indirect
Expand Down Expand Up @@ -440,8 +440,9 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/babylonlabs-io/babylon => github.com/babylonlabs-io/babylon-private v0.9.0-rc.3.0.20240801001431-74a24c962ce2
github.com/babylonlabs-io/finality-gadget => github.com/babylonlabs-io/finality-gadget v0.0.0-20240805210950-4ff43c720b6a
github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20231018212520-f6cde3fc2fa4
github.com/ethereum-optimism/optimism => github.com/babylonlabs-io/optimism v1.8.1-0.20240731214220-e7d71bf38866
github.com/ethereum-optimism/optimism => github.com/babylonlabs-io/optimism v1.8.1-0.20240804005223-75f4cdcfed28
github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101315.1-rc.5
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ github.com/babylonchain/babylon-sdk/demo v0.0.0-20240705194516-4e2c5650cde8 h1:V
github.com/babylonchain/babylon-sdk/demo v0.0.0-20240705194516-4e2c5650cde8/go.mod h1:X4QovCWMwqMjoTriu18w4gfqX1sYqOWRnZwXGYD8bnE=
github.com/babylonchain/babylon-sdk/x v0.0.0-20240705194516-4e2c5650cde8 h1:W8jr9BHOLD9RJviI6TmnWPwZpMSjliQNIbNuflBx6vo=
github.com/babylonchain/babylon-sdk/x v0.0.0-20240705194516-4e2c5650cde8/go.mod h1:Ojrlnwh9z7fvmTUzYH4Tk+8hWSctCrZYWiC5+t4X32I=
github.com/babylonlabs-io/babylon-finality-gadget v0.0.0-20240801002122-6d6bca47ec56 h1:xZ+x4nfezT99jbBYDfqxQx+KBmqICbJtu8WLrjS1sVY=
github.com/babylonlabs-io/babylon-finality-gadget v0.0.0-20240801002122-6d6bca47ec56/go.mod h1:IZUMNT4MCzKPzsniq5EeNITWy/HeNX5k8hPoJNjFSqQ=
github.com/babylonlabs-io/babylon-private v0.9.0-rc.3.0.20240801001431-74a24c962ce2 h1:sFsAJkrYe1eIkKzWTn4sj7G6QrPQ3IK33/UlOVgeA5M=
github.com/babylonlabs-io/babylon-private v0.9.0-rc.3.0.20240801001431-74a24c962ce2/go.mod h1:pyFZgF85gUhfiCJKbYjnxo5+9prDkti48tW4FDEu9js=
github.com/babylonlabs-io/optimism v1.8.1-0.20240731214220-e7d71bf38866 h1:FjrkthFS4JRGCckPh/uTdznhqwQOzjD8JJ0blcrS1VY=
github.com/babylonlabs-io/optimism v1.8.1-0.20240731214220-e7d71bf38866/go.mod h1:MAppo9HosEUwyUCNnvJxJb3GQr5iP72HYb0Xv5YY4JE=
github.com/babylonlabs-io/finality-gadget v0.0.0-20240805210950-4ff43c720b6a h1:wMQ0sCWzwjXMXkww3kr5N0MgjizmulVGKvNcvyTEGhg=
github.com/babylonlabs-io/finality-gadget v0.0.0-20240805210950-4ff43c720b6a/go.mod h1:+BICJA7mUJpfYOSYds1G5w6nLO0gKVe9XwdmpIUiXmk=
github.com/babylonlabs-io/optimism v1.8.1-0.20240804005223-75f4cdcfed28 h1:1xw+4A+IAvHff0f02UsXR1h0bg04Xn726ZvEAwrc/7Y=
github.com/babylonlabs-io/optimism v1.8.1-0.20240804005223-75f4cdcfed28/go.mod h1:cVDnobSCpjb8XIfy8/8tlnm1gkO9lV2xfCezG/7YacY=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down Expand Up @@ -1675,8 +1675,8 @@ github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfU
github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA=
go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.etcd.io/etcd/api/v3 v3.5.10 h1:szRajuUUbLyppkhs9K6BRtjY37l66XQQmw7oZRANE4k=
go.etcd.io/etcd/api/v3 v3.5.10/go.mod h1:TidfmT4Uycad3NM/o25fG3J07odo4GBB9hoxaodFCtI=
Expand Down
14 changes: 7 additions & 7 deletions itest/eotsmanager_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ type EOTSServerHandler struct {
}

func NewEOTSServerHandlerMultiFP(
t *testing.T, configs []*config.Config, eotsHomeDirs []string, logger *zap.Logger,
t *testing.T, configs []*config.Config, eotsHomeDirs []string, logger *zap.Logger, shutdownInterceptor *signal.Interceptor,
) *EOTSServerHandler {
shutdownInterceptor, err := signal.Intercept()
require.NoError(t, err)

eotsServers := make([]*service.Server, 0, len(configs))
for i, cfg := range configs {
dbBackend, err := cfg.DatabaseConfig.GetDbBackend()
Expand All @@ -32,21 +29,24 @@ func NewEOTSServerHandlerMultiFP(
eotsManager, err := eotsmanager.NewLocalEOTSManager(eotsHomeDirs[i], cfg.KeyringBackend, dbBackend, logger)
require.NoError(t, err)

eotsServer := service.NewEOTSManagerServer(cfg, logger, eotsManager, dbBackend, shutdownInterceptor)
eotsServer := service.NewEOTSManagerServer(cfg, logger, eotsManager, dbBackend, *shutdownInterceptor)
eotsServers = append(eotsServers, eotsServer)
}

return &EOTSServerHandler{
t: t,
eotsServers: eotsServers,
interceptor: &shutdownInterceptor,
interceptor: shutdownInterceptor,
}
}

func NewEOTSServerHandler(t *testing.T, cfg *config.Config, eotsHomeDir string) *EOTSServerHandler {
// TODO: no-op logger makes it hard to debug. replace w real logger.
// create shutdown interceptor
shutdownInterceptor, err := signal.Intercept()
require.NoError(t, err)
// this need refactor of NewEOTSServerHandler
return NewEOTSServerHandlerMultiFP(t, []*config.Config{cfg}, []string{eotsHomeDir}, zap.NewNop())
return NewEOTSServerHandlerMultiFP(t, []*config.Config{cfg}, []string{eotsHomeDir}, zap.NewNop(), &shutdownInterceptor)
}

func (eh *EOTSServerHandler) Start() {
Expand Down
5 changes: 4 additions & 1 deletion itest/opstackl2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ Then run the following command to start the e2e tests:

```bash
$ make test-e2e-op
```

# Filter specific test
$ make test-e2e-op Filter=TestFinalityGadget
```
65 changes: 59 additions & 6 deletions itest/opstackl2/op_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
package e2etest_op

import (
"context"
"encoding/hex"
"testing"
"time"

sdkclient "github.com/babylonlabs-io/babylon-finality-gadget/sdk/client"
"github.com/babylonlabs-io/babylon-finality-gadget/sdk/cwclient"
sdkclient "github.com/babylonlabs-io/finality-gadget/sdk/client"
"github.com/babylonlabs-io/finality-gadget/sdk/cwclient"
e2eutils "github.com/babylonlabs-io/finality-provider/itest"
"github.com/babylonlabs-io/finality-provider/testutil/log"
"github.com/stretchr/testify/require"
)

// tests the finality signature submission to the op-finality-gadget contract
func TestOpSubmitFinalitySignature(t *testing.T) {
ctm := StartOpL2ConsumerManager(t, 1)
ctm := StartOpL2ConsumerManager(t, 1, false)
defer ctm.Stop(t)

consumerFpPkList := ctm.RegisterConsumerFinalityProvider(t, 1)
Expand Down Expand Up @@ -46,15 +47,15 @@ func TestOpSubmitFinalitySignature(t *testing.T) {
// 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.
_, err = ctm.SdkClient.QueryIsBlockBabylonFinalized(queryParams)
require.ErrorIs(t, err, sdkclient.ErrNoFpHasVotingPower)
require.ErrorIs(t, err, sdkclient.ErrBtcStakingNotActivated)
t.Logf(log.Prefix("Expected no voting power"))
}

// This test has two test cases:
// 1. block has both two FP signs, so it would be finalized
// 2. block has only one FP with smaller power (1/4) signs, so it would not be considered as finalized
func TestOpMultipleFinalityProviders(t *testing.T) {
ctm := StartOpL2ConsumerManager(t, 2)
ctm := StartOpL2ConsumerManager(t, 2, false)
defer ctm.Stop(t)

// register, get BTC delegations, and start FPs
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestOpMultipleFinalityProviders(t *testing.T) {
}

func TestFinalityStuckAndRecover(t *testing.T) {
ctm := StartOpL2ConsumerManager(t, 1)
ctm := StartOpL2ConsumerManager(t, 1, false)
defer ctm.Stop(t)

// register, get BTC delegations, and start FPs
Expand Down Expand Up @@ -185,3 +186,55 @@ func TestFinalityStuckAndRecover(t *testing.T) {
"OP chain fianlity is recovered, the latest finalized block height %d",
), nextFinalizedHeight)
}

func TestFinalityGadget(t *testing.T) {
// start the consumer manager
ctm := StartOpL2ConsumerManager(t, 2, true)
defer ctm.Stop(t)

// register, get BTC delegations, and start FPs
n := 2
fpList := ctm.SetupFinalityProviders(t, n, []stakingParam{
// for the first FP, we give it more power b/c it will be used later
{e2eutils.StakingTime, 3 * e2eutils.StakingAmount},
{e2eutils.StakingTime, e2eutils.StakingAmount},
})

// check both FPs have committed their first public randomness
// TODO: we might use go routine to do this in parallel
for i := 0; i < n; i++ {
e2eutils.WaitForFpPubRandCommitted(t, fpList[i])
}

// wait until the BTC staking is activated
l2BlockAfterActivation := ctm.waitForBTCStakingActivation(t)

// both FP will sign the first block
targetBlockHeight := ctm.WaitForTargetBlockPubRand(t, fpList, l2BlockAfterActivation)
ctm.WaitForFpVoteReachHeight(t, fpList[0], targetBlockHeight)
ctm.WaitForFpVoteReachHeight(t, fpList[1], targetBlockHeight)
t.Logf(log.Prefix("Both FP instances signed the first block"))

// both FP will sign the second block
ctm.WaitForFpVoteReachHeight(t, fpList[0], targetBlockHeight+1)
ctm.WaitForFpVoteReachHeight(t, fpList[1], targetBlockHeight+1)
t.Logf(log.Prefix("Both FP instances signed the second block"))

// run the finality gadget
ctx, cancel := context.WithCancel(context.Background())
go func() {
t.Logf(log.Prefix("Starting finality gadget"))
err := ctm.FinalityGadget.ProcessBlocks(ctx)
require.NoError(t, err)
}()

// check latest block
require.Eventually(t, func() bool {
block, err := ctm.FinalityGadgetClient.GetLatestBlock()
require.NoError(t, err)
return block.BlockHeight > targetBlockHeight+6
bap2pecs marked this conversation as resolved.
Show resolved Hide resolved
}, 40*time.Second, 5*time.Second, "Failed to process blocks")

// stop the finality gadget
cancel()
}
Loading