Skip to content

Commit

Permalink
refactor: move WaitForFpPubRandCommitted to utils to dedup (ethereu…
Browse files Browse the repository at this point in the history
  • Loading branch information
bap2pecs committed Jun 25, 2024
1 parent 273963b commit b5b751c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
8 changes: 4 additions & 4 deletions itest/babylon/babylon_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestFinalityProviderLifeCycle(t *testing.T) {
fpIns := fpInsList[0]

// check the public randomness is committed
tm.WaitForFpPubRandCommitted(t, fpIns)
e2eutils.WaitForFpPubRandCommitted(t, fpIns)

// send a BTC delegation
_ = tm.InsertBTCDelegation(t, []*btcec.PublicKey{fpIns.GetBtcPk()}, e2eutils.StakingTime, e2eutils.StakingAmount)
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestDoubleSigning(t *testing.T) {
fpIns := fpInsList[0]

// check the public randomness is committed
tm.WaitForFpPubRandCommitted(t, fpIns)
e2eutils.WaitForFpPubRandCommitted(t, fpIns)

// send a BTC delegation
_ = tm.InsertBTCDelegation(t, []*btcec.PublicKey{fpIns.GetBtcPk()}, e2eutils.StakingTime, e2eutils.StakingAmount)
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestMultipleFinalityProviders(t *testing.T) {
// submit BTC delegations for each finality-provider
for _, fpi := range fpInstances {
// check the public randomness is committed
tm.WaitForFpPubRandCommitted(t, fpi)
e2eutils.WaitForFpPubRandCommitted(t, fpi)
// send a BTC delegation
_ = tm.InsertBTCDelegation(t, []*btcec.PublicKey{fpi.GetBtcPk()}, e2eutils.StakingTime, e2eutils.StakingAmount)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestFastSync(t *testing.T) {
fpIns := fpInsList[0]

// check the public randomness is committed
tm.WaitForFpPubRandCommitted(t, fpIns)
e2eutils.WaitForFpPubRandCommitted(t, fpIns)

// send a BTC delegation
_ = tm.InsertBTCDelegation(t, []*btcec.PublicKey{fpIns.GetBtcPk()}, e2eutils.StakingTime, e2eutils.StakingAmount)
Expand Down
12 changes: 0 additions & 12 deletions itest/babylon/babylon_test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,6 @@ func (tm *TestManager) WaitForFpRegistered(t *testing.T, bbnPk *secp256k1.PubKey
t.Logf("the finality-provider is successfully registered")
}

func (tm *TestManager) WaitForFpPubRandCommitted(t *testing.T, fpIns *service.FinalityProviderInstance) {
require.Eventually(t, func() bool {
lastCommittedHeight, err := fpIns.GetLastCommittedHeight()
if err != nil {
return false
}
return lastCommittedHeight > 0
}, e2eutils.EventuallyWaitTimeOut, e2eutils.EventuallyPollTime)

t.Logf("public randomness is successfully committed")
}

func (tm *TestManager) WaitForNPendingDels(t *testing.T, n int) []*bstypes.BTCDelegationResponse {
var (
dels []*bstypes.BTCDelegationResponse
Expand Down
3 changes: 2 additions & 1 deletion itest/opstackl2/op_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/babylonchain/babylon/testutil/datagen"
e2eutils "github.com/babylonchain/finality-provider/itest"
"github.com/babylonchain/finality-provider/types"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/stretchr/testify/require"
Expand All @@ -22,7 +23,7 @@ func TestOpSubmitFinalitySignature(t *testing.T) {
fpList := ctm.StartFinalityProvider(t, false, 1)
fpInstance := fpList[0]

ctm.WaitForFpPubRandCommitted(t, fpInstance)
e2eutils.WaitForFpPubRandCommitted(t, fpInstance)

// query pub rand
committedPubRandMap, err := ctm.OpL2ConsumerCtrl.QueryLastCommittedPublicRand(fpInstance.GetBtcPk(), 1)
Expand Down
12 changes: 0 additions & 12 deletions itest/opstackl2/op_test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,6 @@ func (ctm *OpL2ConsumerTestManager) StartFinalityProvider(t *testing.T, isBabylo
return resFpList
}

func (ctm *OpL2ConsumerTestManager) WaitForFpPubRandCommitted(t *testing.T, fpIns *service.FinalityProviderInstance) {
require.Eventually(t, func() bool {
lastCommittedHeight, err := fpIns.GetLastCommittedHeight()
if err != nil {
return false
}
return lastCommittedHeight > 0
}, e2eutils.EventuallyWaitTimeOut, e2eutils.EventuallyPollTime)

t.Logf("Public randomness is successfully committed")
}

func storeWasmCode(opcc *opstackl2.OPStackL2ConsumerController, wasmFile string) error {
wasmCode, err := os.ReadFile(wasmFile)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions itest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/babylonchain/babylon/types"
"github.com/babylonchain/finality-provider/finality-provider/config"
"github.com/babylonchain/finality-provider/finality-provider/service"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -79,6 +80,18 @@ func GenerateCovenantCommittee(numCovenants int, t *testing.T) ([]*btcec.Private
return covenantPrivKeys, covenantPubKeys
}

func WaitForFpPubRandCommitted(t *testing.T, fpIns *service.FinalityProviderInstance) {
require.Eventually(t, func() bool {
lastCommittedHeight, err := fpIns.GetLastCommittedHeight()
if err != nil {
return false
}
return lastCommittedHeight > 0
}, EventuallyWaitTimeOut, EventuallyPollTime)

t.Logf("Public randomness is successfully committed")
}

func DefaultFpConfig(keyringDir, homeDir string) *config.Config {
cfg := config.DefaultConfigWithHome(homeDir)

Expand Down

0 comments on commit b5b751c

Please sign in to comment.