Skip to content

Commit

Permalink
chore: upgrade test and e2e use the same btc base header
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Dec 6, 2024
1 parent be5c335 commit 8fd5b08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
29 changes: 2 additions & 27 deletions app/upgrades/v1/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/babylonlabs-io/babylon/app/upgrades"
"github.com/babylonlabs-io/babylon/test/e2e/util"
"github.com/babylonlabs-io/babylon/testutil/datagen"
"github.com/babylonlabs-io/babylon/types"
"github.com/babylonlabs-io/babylon/testutil/sample"
bbn "github.com/babylonlabs-io/babylon/types"
minttypes "github.com/babylonlabs-io/babylon/x/mint/types"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand All @@ -29,15 +29,13 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/babylonlabs-io/babylon/app"
v1 "github.com/babylonlabs-io/babylon/app/upgrades/v1"
mainnetdata "github.com/babylonlabs-io/babylon/app/upgrades/v1/mainnet"
testnetdata "github.com/babylonlabs-io/babylon/app/upgrades/v1/testnet"
"github.com/babylonlabs-io/babylon/x/btclightclient"
btclightck "github.com/babylonlabs-io/babylon/x/btclightclient/keeper"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
)

Expand Down Expand Up @@ -188,7 +186,7 @@ func (s *UpgradeTestSuite) SetupTest(upgradeDataStr v1.UpgradeDataString) {
// Note: for mainnet upgrade testing a new function needs to be created and
// probably split the upgrade test suite in 2, since the btc config
// will be different for testnet and for mainnet.
baseBtcHeader := SignetBtcHeader195552(s.T())
baseBtcHeader := sample.SignetBtcHeader195552(s.T())

k := s.app.BTCLightClientKeeper
btclightclient.InitGenesis(s.ctx, s.app.BTCLightClientKeeper, btclighttypes.GenesisState{
Expand Down Expand Up @@ -338,26 +336,3 @@ func (s *UpgradeTestSuite) PostUpgrade() {
nonExistentTxHash := chainhash.Hash{}
s.False(s.app.BTCStakingKeeper.IsStakingTransactionAllowed(s.ctx, &nonExistentTxHash))
}

// SignetBtcHeader195552 returns the BTC Header block 195552 from signet bbn-test-4.
func SignetBtcHeader195552(t *testing.T) *btclighttypes.BTCHeaderInfo {
var btcHeader btclighttypes.BTCHeaderInfo
// signet btc header 0
btcHeaderHash, err := types.NewBTCHeaderBytesFromHex("00000020c8710c5662ab0a4680963697765a390cba4814f95f0556fc5fb3b446b2000000fa9b80e52653455e5d4a4648fbe1f62854a07dbec0633a42ef595431de9be36dccb64366934f011ef3d98200")
require.NoError(t, err)

wireHeaders := btclightck.BtcHeadersBytesToBlockHeader([]types.BTCHeaderBytes{btcHeaderHash})
wireHeader := wireHeaders[0]

blockHash := wireHeader.BlockHash()
headerHash := bbn.NewBTCHeaderHashBytesFromChainhash(&blockHash)
work := btclighttypes.CalcWork(&btcHeaderHash)
btcHeader = btclighttypes.BTCHeaderInfo{
Header: &btcHeaderHash,
Height: uint32(195552),
Hash: &headerHash,
Work: &work,
}

return &btcHeader
}
4 changes: 2 additions & 2 deletions test/e2e/software_upgrade_e2e_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
v1 "github.com/babylonlabs-io/babylon/app/upgrades/v1"
"github.com/babylonlabs-io/babylon/app/upgrades/v1/testnet"
"github.com/babylonlabs-io/babylon/testutil/datagen"
"github.com/babylonlabs-io/babylon/testutil/sample"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"

"github.com/babylonlabs-io/babylon/test/e2e/configurer"
Expand All @@ -33,8 +34,7 @@ func (s *SoftwareUpgradeV1TestnetTestSuite) SetupSuite() {
var err error
s.balancesBeforeUpgrade = make(map[string]sdk.Coin)

btcHeaderGenesis, err := app.SignetBtcHeaderGenesis(app.NewTmpBabylonApp().AppCodec())
s.NoError(err)
btcHeaderGenesis := sample.SignetBtcHeader195552(s.T())

tokenDistData, err := v1.LoadTokenDistributionFromData(testnet.TokensDistributionStr)
s.NoError(err)
Expand Down
30 changes: 30 additions & 0 deletions testutil/sample/sample.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package sample

import (
"testing"

"github.com/babylonlabs-io/babylon/types"
bbn "github.com/babylonlabs-io/babylon/types"
btclightck "github.com/babylonlabs-io/babylon/x/btclightclient/keeper"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

// AccAddress returns a sample account address
Expand All @@ -11,3 +18,26 @@ func AccAddress() string {
addr := pk.Address()
return sdk.AccAddress(addr).String()
}

// SignetBtcHeader195552 returns the BTC Header block 195552 from signet bbn-test-4.
func SignetBtcHeader195552(t *testing.T) *btclighttypes.BTCHeaderInfo {
var btcHeader btclighttypes.BTCHeaderInfo
// signet btc header 0
btcHeaderHash, err := types.NewBTCHeaderBytesFromHex("00000020c8710c5662ab0a4680963697765a390cba4814f95f0556fc5fb3b446b2000000fa9b80e52653455e5d4a4648fbe1f62854a07dbec0633a42ef595431de9be36dccb64366934f011ef3d98200")
require.NoError(t, err)

wireHeaders := btclightck.BtcHeadersBytesToBlockHeader([]types.BTCHeaderBytes{btcHeaderHash})
wireHeader := wireHeaders[0]

blockHash := wireHeader.BlockHash()
headerHash := bbn.NewBTCHeaderHashBytesFromChainhash(&blockHash)
work := btclighttypes.CalcWork(&btcHeaderHash)
btcHeader = btclighttypes.BTCHeaderInfo{
Header: &btcHeaderHash,
Height: uint32(195552),
Hash: &headerHash,
Work: &work,
}

return &btcHeader
}

0 comments on commit 8fd5b08

Please sign in to comment.