Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Nov 28, 2024
1 parent 9ffb088 commit 5f48134
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
9 changes: 6 additions & 3 deletions finality-provider/cmd/fpd/daemon/daemon_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ func CommandCreateFP() *cobra.Command {
Use: "create-finality-provider",
Aliases: []string{"cfp"},
Short: "Create a finality provider object and save it in database.",
Long: fmt.Sprintf(`
Create a new finality provider object and store it in the finality provider database.
It needs to have an operating EOTS manager available and running.`),
Long: "Create a new finality provider object and store it in the finality provider database. " +
"It needs to have an operating EOTS manager available and running.",
Example: fmt.Sprintf(`fpd create-finality-provider --daemon-address %s ...`, defaultFpdDaemonAddress),
Args: cobra.NoArgs,
RunE: fpcmd.RunEWithClientCtx(runCommandCreateFP),
Expand Down Expand Up @@ -181,6 +180,10 @@ func runCommandCreateFP(ctx client.Context, cmd *cobra.Command, _ []string) erro
return fmt.Errorf("failed to read flag %s: %w", fpEotsPkFlag, err)
}

if eotsPkHex == "" {
return fmt.Errorf("eots-pk cannot be empty")
}

info, err := client.CreateFinalityProvider(
context.Background(),
keyName,
Expand Down
3 changes: 3 additions & 0 deletions finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ func (app *FinalityProviderApp) handleCreateFinalityProviderRequest(req *createF
}

// 2. create proof-of-possession
if req.eotsPk == nil {
return nil, fmt.Errorf("eots pk cannot be nil")
}
pop, err := app.CreatePop(fpAddr, req.eotsPk, req.passPhrase)
if err != nil {
return nil, fmt.Errorf("failed to create proof-of-possession of the finality-provider: %w", err)
Expand Down
36 changes: 21 additions & 15 deletions finality-provider/service/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,16 @@ func FuzzRegisterFinalityProvider(f *testing.F) {
}()

var eotsPk *bbntypes.BIP340PubKey
eotsPk = nil
generateEotsKeyBefore := r.Int31n(10) > 5
if generateEotsKeyBefore {
// sometimes uses the previously generated EOTS pk
eotsKeyName := testutil.GenRandomHexStr(r, 4)
eotsPkBz, err := em.CreateKey(eotsKeyName, passphrase, hdPath)
require.NoError(t, err)
eotsPk, err = bbntypes.NewBIP340PubKey(eotsPkBz)
require.NoError(t, err)
}
eotsKeyName := testutil.GenRandomHexStr(r, 4)
require.NoError(t, err)
eotsPkBz, err := em.CreateKey(eotsKeyName, passphrase, hdPath)
require.NoError(t, err)
eotsPk, err = bbntypes.NewBIP340PubKey(eotsPkBz)
require.NoError(t, err)

// create a finality-provider object and save it to db
fp := testutil.GenStoredFinalityProvider(r, t, app, passphrase, hdPath, eotsPk)
if generateEotsKeyBefore {
require.Equal(t, eotsPk, bbntypes.NewBIP340PubKeyFromBTCPK(fp.BtcPk))
}
require.Equal(t, eotsPk, bbntypes.NewBIP340PubKeyFromBTCPK(fp.BtcPk))

btcSig := new(bbntypes.BIP340Signature)
err = btcSig.Unmarshal(fp.Pop.BtcSig)
Expand Down Expand Up @@ -199,7 +193,13 @@ func FuzzSyncFinalityProviderStatus(f *testing.F) {
err = app.Start()
require.NoError(t, err)

fp := testutil.GenStoredFinalityProvider(r, t, app, "", hdPath, nil)
eotsKeyName := testutil.GenRandomHexStr(r, 4)
require.NoError(t, err)
eotsPkBz, err := em.CreateKey(eotsKeyName, passphrase, hdPath)
require.NoError(t, err)
eotsPk, err := bbntypes.NewBIP340PubKey(eotsPkBz)
require.NoError(t, err)
fp := testutil.GenStoredFinalityProvider(r, t, app, "", hdPath, eotsPk)

require.Eventually(t, func() bool {
fpPk := fp.GetBIP340BTCPK()
Expand Down Expand Up @@ -277,7 +277,13 @@ func FuzzUnjailFinalityProvider(f *testing.F) {
}()
require.NoError(t, err)

fp := testutil.GenStoredFinalityProvider(r, t, app, "", hdPath, nil)
eotsKeyName := testutil.GenRandomHexStr(r, 4)
require.NoError(t, err)
eotsPkBz, err := em.CreateKey(eotsKeyName, passphrase, hdPath)
require.NoError(t, err)
eotsPk, err := bbntypes.NewBIP340PubKey(eotsPkBz)
require.NoError(t, err)
fp := testutil.GenStoredFinalityProvider(r, t, app, "", hdPath, eotsPk)
err = app.GetFinalityProviderStore().SetFpStatus(fp.BtcPk, proto.FinalityProviderStatus_JAILED)
require.NoError(t, err)

Expand Down
9 changes: 8 additions & 1 deletion finality-provider/service/fp_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"testing"

bbntypes "github.com/babylonlabs-io/babylon/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand Down Expand Up @@ -122,7 +123,13 @@ func startFinalityProviderAppWithRegisteredFp(t *testing.T, r *rand.Rand, cc cli
require.NoError(t, err)

// create registered finality-provider
fp := testutil.GenStoredFinalityProvider(r, t, app, passphrase, hdPath, nil)
eotsKeyName := testutil.GenRandomHexStr(r, 4)
require.NoError(t, err)
eotsPkBz, err := em.CreateKey(eotsKeyName, passphrase, hdPath)
require.NoError(t, err)
eotsPk, err := bbntypes.NewBIP340PubKey(eotsPkBz)
require.NoError(t, err)
fp := testutil.GenStoredFinalityProvider(r, t, app, passphrase, hdPath, eotsPk)
pubRandProofStore := app.GetPubRandProofStore()
fpStore := app.GetFinalityProviderStore()
err = fpStore.SetFpStatus(fp.BtcPk, proto.FinalityProviderStatus_REGISTERED)
Expand Down
8 changes: 7 additions & 1 deletion itest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ func StartManagerWithFinalityProvider(t *testing.T) (*TestManager, *service.Fina
_, _, err = tm.manager.BabylondTxBankSend(t, fpBbnKeyInfo.AccAddress.String(), "1000000ubbn", "node0")
require.NoError(t, err)

res, err := app.CreateFinalityProvider(testFpName, testChainID, passphrase, hdPath, nil, desc, &commission)
eotsKeyName := "eots-key"
require.NoError(t, err)
eotsPkBz, err := tm.EOTSClient.CreateKey(eotsKeyName, passphrase, hdPath)
require.NoError(t, err)
eotsPk, err := bbntypes.NewBIP340PubKey(eotsPkBz)
require.NoError(t, err)
res, err := app.CreateFinalityProvider(testFpName, testChainID, passphrase, hdPath, eotsPk, desc, &commission)
require.NoError(t, err)
fpPk, err := bbntypes.NewBIP340PubKeyFromHex(res.FpInfo.BtcPkHex)
require.NoError(t, err)
Expand Down

0 comments on commit 5f48134

Please sign in to comment.