Skip to content

Commit

Permalink
fix: unit test sorting of covenant sigs to match expected
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Oct 10, 2024
1 parent 32f2b7a commit 9633554
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ func (bc *BabylonController) reliablySendMsgs(msgs []sdk.Msg) (*provider.Relayer

// SubmitCovenantSigs submits the Covenant signature via a MsgAddCovenantSig to Babylon if the daemon runs in Covenant mode
// it returns tx hash and error
func (bc *BabylonController) SubmitCovenantSigs(covSigs []*types.CovenantSigs) (*types.TxResponse, error) {
func (bc *BabylonController) SubmitCovenantSigs(covSigs []types.CovenantSigs) (*types.TxResponse, error) {
msgs := make([]sdk.Msg, 0, len(covSigs))
for _, covSig := range covSigs {
bip340UnbondingSig := bbntypes.NewBIP340SignatureFromBTCSig(covSig.UnbondingSig)
bip340UnbondingSig := bbntypes.NewBIP340SignatureFromBTCSig(&covSig.UnbondingSig)
msgs = append(msgs, &btcstakingtypes.MsgAddCovenantSigs{
Signer: bc.mustGetTxSigner(),
Pk: bbntypes.NewBIP340PubKeyFromBTCPK(covSig.PublicKey),
Pk: bbntypes.NewBIP340PubKeyFromBTCPK(&covSig.PublicKey),
StakingTxHash: covSig.StakingTxHash.String(),
SlashingTxSigs: covSig.SlashingSigs,
UnbondingTxSig: bip340UnbondingSig,
Expand Down
2 changes: 1 addition & 1 deletion clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ClientController interface {
// SubmitCovenantSigs submits Covenant signatures to the consumer chain, each corresponding to
// a finality provider that the delegation is (re-)staked to
// it returns tx hash and error
SubmitCovenantSigs(covSigMsgs []*types.CovenantSigs) (*types.TxResponse, error)
SubmitCovenantSigs(covSigMsgs []types.CovenantSigs) (*types.TxResponse, error)

// QueryPendingDelegations queries BTC delegations that are in status of pending
QueryPendingDelegations(limit uint64) ([]*types.Delegation, error)
Expand Down
14 changes: 9 additions & 5 deletions covenant/covenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ var net = &chaincfg.SimNetParams
func FuzzAddCovenantSig(f *testing.F) {
testutil.AddRandomSeedsToFuzzer(f, 10)
f.Fuzz(func(t *testing.T, seed int64) {
t.Log("Seed", seed)
r := rand.New(rand.NewSource(seed))

params := testutil.GenRandomParams(r, t)
mockClientController := testutil.PrepareMockedClientController(t, params)

// create a Covenant key pair in the keyring
covenantConfig := covcfg.DefaultConfig()
covenantConfig.BabylonConfig.KeyDirectory = t.TempDir()

covKeyPair, err := keyring.CreateCovenantKey(
covenantConfig.BabylonConfig.KeyDirectory,
covenantConfig.BabylonConfig.ChainID,
Expand All @@ -58,7 +61,7 @@ func FuzzAddCovenantSig(f *testing.F) {
require.NoError(t, err)

numDels := datagen.RandomInt(r, 3) + 1
covSigsSet := make([]*types.CovenantSigs, 0, numDels)
covSigsSet := make([]types.CovenantSigs, 0, numDels)
btcDels := make([]*types.Delegation, 0, numDels)
for i := 0; uint64(i) < numDels; i++ {
// generate BTC delegation
Expand Down Expand Up @@ -176,11 +179,11 @@ func FuzzAddCovenantSig(f *testing.F) {
require.NoError(t, err)
unbondingCovSlashingSigs = append(unbondingCovSlashingSigs, covenantSig.MustMarshal())
}
covSigsSet = append(covSigsSet, &types.CovenantSigs{
PublicKey: covKeyPair.PublicKey,
covSigsSet = append(covSigsSet, types.CovenantSigs{
PublicKey: *covKeyPair.PublicKey,
StakingTxHash: testInfo.StakingTx.TxHash(),
SlashingSigs: covSigs,
UnbondingSig: unbondingCovSig,
UnbondingSig: *unbondingCovSig,
SlashingUnbondingSigs: unbondingCovSlashingSigs,
})
}
Expand All @@ -191,9 +194,10 @@ func FuzzAddCovenantSig(f *testing.F) {
}
btcDels = append(btcDels, invalidDelegation)

sortedCovSigs := covenant.SortCovenantSigs(covSigsSet)
// check the sigs are expected
expectedTxHash := testutil.GenRandomHexStr(r, 32)
mockClientController.EXPECT().SubmitCovenantSigs(covSigsSet).
mockClientController.EXPECT().SubmitCovenantSigs(sortedCovSigs).
Return(&types.TxResponse{TxHash: expectedTxHash}, nil).AnyTimes()
res, err := ce.AddCovenantSignatures(btcDels)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion testutil/mocks/babylon.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions types/sigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
)

type CovenantSigs struct {
PublicKey *btcec.PublicKey
PublicKey btcec.PublicKey
StakingTxHash chainhash.Hash
SlashingSigs [][]byte
UnbondingSig *schnorr.Signature
UnbondingSig schnorr.Signature
SlashingUnbondingSigs [][]byte
}

0 comments on commit 9633554

Please sign in to comment.