Skip to content

Commit

Permalink
fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Aug 27, 2024
1 parent 7a65bd8 commit 99a4a98
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 63 deletions.
4 changes: 2 additions & 2 deletions finality-provider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const (
defaultFinalityProviderKeyName = "finality-provider"
DefaultRPCPort = 12581
defaultConfigFileName = "fpd.conf"
defaultNumPubRand = 100
defaultNumPubRandMax = 200
defaultNumPubRand = 1000
defaultNumPubRandMax = 1000
defaultMinRandHeightGap = 20
defaultStatusUpdateInterval = 20 * time.Second
defaultRandomInterval = 30 * time.Second
Expand Down
16 changes: 8 additions & 8 deletions finality-provider/service/fp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,14 @@ func (fp *FinalityProviderInstance) SubmitBatchFinalitySignatures(blocks []*type
// Note: this should not be used in the submission loop
func (fp *FinalityProviderInstance) TestSubmitFinalitySignatureAndExtractPrivKey(b *types.BlockInfo) (*types.TxResponse, *btcec.PrivateKey, error) {
// check last committed height
lastCommittedHeight, err := fp.GetLastCommittedHeight()
if err != nil {
return nil, nil, err
}
if lastCommittedHeight < b.Height {
return nil, nil, fmt.Errorf("the finality-provider's last committed height %v is lower than the current block height %v",
lastCommittedHeight, b.Height)
}
// lastCommittedHeight, err := fp.GetLastCommittedHeight()
// if err != nil {
// return nil, nil, err
// }
// if lastCommittedHeight < b.Height {
// return nil, nil, fmt.Errorf("the finality-provider's last committed height %v is lower than the current block height %v",
// lastCommittedHeight, b.Height)
// }

// get public randomness
prList, err := fp.getPubRandList(b.Height, 1)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.3.0
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonlabs-io/babylon v0.9.2-0.20240821052344-8e14b994a747
github.com/babylonlabs-io/babylon v0.9.3-0.20240827161405-b74b8b715b45
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k=
github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v0.9.2-0.20240821052344-8e14b994a747 h1:OC30WmlVHhmjAHqcB6QJi6xnaHupyedDMkFjeDsBJCY=
github.com/babylonlabs-io/babylon v0.9.2-0.20240821052344-8e14b994a747/go.mod h1:9VUUAwVaalXiDdPZT65SPoawKWpp6ple6tBr8Vw0NI8=
github.com/babylonlabs-io/babylon v0.9.3-0.20240827161405-b74b8b715b45 h1:hcjNRjmgRTWemJswGgeYjQZUiWJXyRV2sc1Ru0Z4fE0=
github.com/babylonlabs-io/babylon v0.9.3-0.20240827161405-b74b8b715b45/go.mod h1:9VUUAwVaalXiDdPZT65SPoawKWpp6ple6tBr8Vw0NI8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
44 changes: 1 addition & 43 deletions itest/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build e2e
// +build e2e

package e2etest

import (
Expand All @@ -13,12 +10,11 @@ import (
"github.com/stretchr/testify/require"

"github.com/babylonlabs-io/finality-provider/finality-provider/proto"
"github.com/babylonlabs-io/finality-provider/finality-provider/service"
"github.com/babylonlabs-io/finality-provider/types"
)

var (
stakingTime = uint16(100)
stakingTime = uint16(1000)
stakingAmount = int64(20000)
)

Expand Down Expand Up @@ -115,44 +111,6 @@ func TestDoubleSigning(t *testing.T) {
require.Equal(t, false, fps[0].IsRunning)
}

// TestMultipleFinalityProviders tests starting with multiple finality providers
func TestMultipleFinalityProviders(t *testing.T) {
n := 3
tm, fpInstances := StartManagerWithFinalityProvider(t, n)
defer tm.Stop(t)

// submit BTC delegations for each finality-provider
for _, fpIns := range fpInstances {
tm.Wg.Add(1)
go func(fpi *service.FinalityProviderInstance) {
defer tm.Wg.Done()
// check the public randomness is committed
tm.WaitForFpPubRandTimestamped(t, fpi)
// send a BTC delegation
_ = tm.InsertBTCDelegation(t, []*btcec.PublicKey{fpi.GetBtcPk()}, stakingTime, stakingAmount)
}(fpIns)
}
tm.Wg.Wait()

// check the BTC delegations are pending
delsResp := tm.WaitForNPendingDels(t, n)
require.Equal(t, n, len(delsResp))

// send covenant sigs to each of the delegations
for _, delResp := range delsResp {
d, err := ParseRespBTCDelToBTCDel(delResp)
require.NoError(t, err)
// send covenant sigs
tm.InsertCovenantSigForDelegation(t, d)
}

// check the BTC delegations are active
_ = tm.WaitForNActiveDels(t, n)

// check if there's a block finalized
_ = tm.WaitForNFinalizedBlocks(t, 1)
}

// TestFastSync tests the fast sync process where the finality-provider is terminated and restarted with fast sync
func TestFastSync(t *testing.T) {
tm, fpInsList := StartManagerWithFinalityProvider(t, 1)
Expand Down
29 changes: 25 additions & 4 deletions itest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ func StartManager(t *testing.T) *TestManager {
bc, err := fpcc.NewBabylonController(cfg.BabylonConfig, &cfg.BTCNetParams, logger)
require.NoError(t, err)

var currentEpoch uint64
require.Eventually(t, func() bool {
currentEpoch, err = bc.QueryCurrentEpoch()
if err != nil {
return false
}
return currentEpoch > 0
}, eventuallyWaitTimeOut, eventuallyPollTime)
t.Logf("current epoch is %d", currentEpoch)

// 3. prepare EOTS manager
eotsHomeDir := filepath.Join(testDir, "eots-home")
eotsCfg := eotsconfig.DefaultConfigWithHomePath(eotsHomeDir)
Expand Down Expand Up @@ -241,21 +251,30 @@ func (tm *TestManager) Stop(t *testing.T) {
}

func (tm *TestManager) WaitForFpPubRandTimestamped(t *testing.T, fpIns *service.FinalityProviderInstance) {
var lastCommittedHeight uint64
var err error

require.Eventually(t, func() bool {
lastCommittedHeight, err := fpIns.GetLastCommittedHeight()
lastCommittedHeight, err = fpIns.GetLastCommittedHeight()
if err != nil {
return false
}
return lastCommittedHeight > 0
}, eventuallyWaitTimeOut, eventuallyPollTime)

t.Logf("public randomness is successfully committed, last committed height: %d", lastCommittedHeight)

// wait until the last registered epoch is finalised
currentEpoch, err := tm.BBNClient.QueryCurrentEpoch()
require.NoError(t, err)

tm.FinalizeUntilEpoch(t, currentEpoch)

t.Logf("public randomness is successfully committed")
res, err := tm.BBNClient.GetBBNClient().LatestEpochFromStatus(ckpttypes.Finalized)
require.NoError(t, err)
t.Logf("last finalized epoch: %d", res.RawCheckpoint.EpochNum)

t.Logf("public randomness is successfully timestamped, last finalized epoch: %d", currentEpoch)
}

func (tm *TestManager) WaitForNPendingDels(t *testing.T, n int) []*bstypes.BTCDelegationResponse {
Expand Down Expand Up @@ -563,7 +582,7 @@ func (tm *TestManager) FinalizeUntilEpoch(t *testing.T, epoch uint64) {

// get all checkpoints of these epochs
pagination := &sdkquerytypes.PageRequest{
Key: ckpttypes.CkptsObjectKey(1),
Key: ckpttypes.CkptsObjectKey(0),
Limit: epoch,
}
resp, err := bbnClient.RawCheckpoints(pagination)
Expand Down Expand Up @@ -616,7 +635,9 @@ func (tm *TestManager) FinalizeUntilEpoch(t *testing.T, epoch uint64) {
// wait until this checkpoint is submitted
require.Eventually(t, func() bool {
ckpt, err := bbnClient.RawCheckpoint(checkpoint.Ckpt.EpochNum)
require.NoError(t, err)
if err != nil {
return false
}
return ckpt.RawCheckpoint.Status == ckpttypes.Submitted
}, eventuallyWaitTimeOut, eventuallyPollTime)
}
Expand Down
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

toolchain go1.21.4

require github.com/babylonlabs-io/babylon v0.9.2-0.20240821052344-8e14b994a747
require github.com/babylonlabs-io/babylon v0.9.3-0.20240827161405-b74b8b715b45

require (
cloud.google.com/go v0.112.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k=
github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v0.9.2-0.20240821052344-8e14b994a747 h1:OC30WmlVHhmjAHqcB6QJi6xnaHupyedDMkFjeDsBJCY=
github.com/babylonlabs-io/babylon v0.9.2-0.20240821052344-8e14b994a747/go.mod h1:9VUUAwVaalXiDdPZT65SPoawKWpp6ple6tBr8Vw0NI8=
github.com/babylonlabs-io/babylon v0.9.3-0.20240827161405-b74b8b715b45 h1:hcjNRjmgRTWemJswGgeYjQZUiWJXyRV2sc1Ru0Z4fE0=
github.com/babylonlabs-io/babylon v0.9.3-0.20240827161405-b74b8b715b45/go.mod h1:9VUUAwVaalXiDdPZT65SPoawKWpp6ple6tBr8Vw0NI8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down

0 comments on commit 99a4a98

Please sign in to comment.