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

Konradstaniec/fix delegation translation (#71) #72

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Bug fixes

* [#71](https://github.com/babylonlabs-io/covenant-emulator/pull/71) Fix delegation
response to delegation conversion

## v0.11.0

### Improvements
Expand Down
1 change: 1 addition & 0 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func DelegationRespToDelegation(del *btcstakingtypes.BTCDelegationResponse) (*ty
CovenantSigs: covenantSigs,
UnbondingTime: uint16(del.UnbondingTime),
BtcUndelegation: undelegation,
ParamsVersion: del.ParamsVersion,
}, nil
}

Expand Down
61 changes: 61 additions & 0 deletions clientcontroller/babylon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package clientcontroller_test

import (
"math/rand"
"testing"

"github.com/babylonlabs-io/babylon/testutil/datagen"
bbntypes "github.com/babylonlabs-io/babylon/types"
"github.com/babylonlabs-io/babylon/x/btcstaking/types"
"github.com/babylonlabs-io/covenant-emulator/clientcontroller"
"github.com/babylonlabs-io/covenant-emulator/testutil"
"github.com/stretchr/testify/require"
)

func FuzzDelegationRespToDelegation(f *testing.F) {
testutil.AddRandomSeedsToFuzzer(f, 10)
f.Fuzz(func(t *testing.T, seed int64) {
r := rand.New(rand.NewSource(seed))

delPub, err := datagen.GenRandomBIP340PubKey(r)
require.NoError(t, err)

fpPub, err := datagen.GenRandomBIP340PubKey(r)
require.NoError(t, err)

randSat := datagen.RandomInRange(r, 10000, 10000000)
randVersion := datagen.RandomInRange(r, 1, 10)
stakingTx := datagen.GenRandomHexStr(r, 100)
slashingTx := datagen.GenRandomHexStr(r, 100)
stakingTime := datagen.RandomInRange(r, 100, 1000000)
startHeight := datagen.RandomInRange(r, 100, 1000000)
endHeight := datagen.RandomInRange(r, 100, 1000000)
stakingOutputIdx := datagen.RandomInRange(r, 100, 1000000)

response := types.BTCDelegationResponse{
BtcPk: delPub,
FpBtcPkList: []bbntypes.BIP340PubKey{*fpPub},
TotalSat: uint64(randSat),
ParamsVersion: uint32(randVersion),
StakingTxHex: stakingTx,
SlashingTxHex: slashingTx,
StakingTime: uint32(stakingTime),
StartHeight: uint32(startHeight),
EndHeight: uint32(endHeight),
StakingOutputIdx: uint32(stakingOutputIdx),
}

del, err := clientcontroller.DelegationRespToDelegation(&response)
require.NoError(t, err)
require.NotNil(t, del)
require.Equal(t, response.ParamsVersion, del.ParamsVersion)
require.Equal(t, response.StakingTime, del.StakingTime)
require.Equal(t, response.StartHeight, del.StartHeight)
require.Equal(t, response.EndHeight, del.EndHeight)
require.Equal(t, response.StakingOutputIdx, del.StakingOutputIdx)
require.Equal(t, response.StakingTxHex, del.StakingTxHex)
require.Equal(t, response.SlashingTxHex, del.SlashingTxHex)
require.Equal(t, response.BtcPk, bbntypes.NewBIP340PubKeyFromBTCPK(del.BtcPk))
require.Equal(t, response.FpBtcPkList, bbntypes.NewBIP340PKsFromBTCPKs(del.FpBtcPks))
})
}
2 changes: 2 additions & 0 deletions covenant/covenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func FuzzAddCovenantSig(f *testing.F) {
startHeight := uint32(datagen.RandomInt(r, 1000) + 100)
stakingOutputIdx, err := bbntypes.GetOutputIdxInBTCTx(testInfo.StakingTx, testInfo.StakingInfo.StakingOutput)
require.NoError(t, err)
randParamsVersion := datagen.RandomInRange(r, 1, 10)
btcDel := &types.Delegation{
BtcPk: delPK,
FpBtcPks: fpPks,
Expand All @@ -102,6 +103,7 @@ func FuzzAddCovenantSig(f *testing.F) {
StakingTxHex: hex.EncodeToString(stakingTxBytes),
StakingOutputIdx: stakingOutputIdx,
SlashingTxHex: testInfo.SlashingTx.ToHexStr(),
ParamsVersion: uint32(randParamsVersion),
}
btcDels = append(btcDels, btcDel)
// generate covenant staking sigs
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
cosmossdk.io/math v1.4.0
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonlabs-io/babylon v1.0.0-rc.1
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.2.0
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.3.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v1.0.0-rc.1 h1:esV0UJ1TmXfVkfKWOee/2ny+GMiqZXNni8f2H4ASD38=
github.com/babylonlabs-io/babylon v1.0.0-rc.1/go.mod h1:B8ma8IjGUEKhmoRfwv60Qa7DtUXssCgtmD89huQ4+5I=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.2.0 h1:bIosLYR/HUDN4gtUMqbPZjDKapcTHVJHFs0o9AGJt+U=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.2.0/go.mod h1:9lAyEcdpfS21bMLMEa8WjTyLVfwHJABRh5TmoxC9LKU=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.3.0 h1:WS0Hcb8VZHTJJ470NyFKrqOZfEpN7DG4x7RYLe8nXs4=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.3.0/go.mod h1:Ri87bBAOtpKeNz7BtQcHs4poob+OBX/ALgZJxOINq2g=
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
Loading