Skip to content

Commit

Permalink
fix: upgrade test to use signet BTC config
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Dec 5, 2024
1 parent dd5c792 commit 815800a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
20 changes: 15 additions & 5 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ type SetupOptions struct {
AppOpts types.AppOptions
}

func setup(t *testing.T, ps *appkeepers.PrivSigner, withGenesis bool, invCheckPeriod uint) (*BabylonApp, GenesisState) {
func setup(t *testing.T, ps *appkeepers.PrivSigner, withGenesis bool, invCheckPeriod uint, btcConf bbn.SupportedBtcNetwork) (*BabylonApp, GenesisState) {
db := dbm.NewMemDB()
nodeHome := t.TempDir()

appOptions := make(simsutils.AppOptionsMap, 0)
appOptions[flags.FlagHome] = nodeHome // ensure unique folder
appOptions[server.FlagInvCheckPeriod] = invCheckPeriod
appOptions["btc-config.network"] = string(bbn.BtcSimnet)
appOptions["btc-config.network"] = string(btcConf)
appOptions[server.FlagPruning] = pruningtypes.PruningOptionDefault
appOptions[server.FlagMempoolMaxTxs] = mempool.DefaultMaxTx
appOptions[flags.FlagChainID] = "chain-test"
Expand Down Expand Up @@ -226,6 +226,16 @@ func genesisStateWithValSet(t *testing.T,
// one validator in validator set during InitGenesis abci call - https://github.com/cosmos/cosmos-sdk/pull/9697
func Setup(t *testing.T, isCheckTx bool) *BabylonApp {
t.Helper()
return SetupWithBitcoinConf(t, isCheckTx, bbn.BtcSimnet)
}

// SetupWithBitcoinConf initializes a new BabylonApp with a specific btc network config.
// A Nop logger is set in BabylonApp. Created Babylon application will have one validator
// with hardoced amount of tokens. This is necessary as from cosmos-sdk 0.46 it is required
// that there is at least one validator in validator set during InitGenesis abci call
// https://github.com/cosmos/cosmos-sdk/pull/9697
func SetupWithBitcoinConf(t *testing.T, isCheckTx bool, btcConf bbn.SupportedBtcNetwork) *BabylonApp {
t.Helper()

ps, err := SetupTestPrivSigner()
require.NoError(t, err)
Expand All @@ -242,7 +252,7 @@ func Setup(t *testing.T, isCheckTx bool) *BabylonApp {
require.NoError(t, err)
genesisValSet := []*checkpointingtypes.GenesisKey{genesisKey}

app := SetupWithGenesisValSet(t, genesisValSet, ps, []authtypes.GenesisAccount{acc}, balance)
app := SetupWithGenesisValSet(t, btcConf, genesisValSet, ps, []authtypes.GenesisAccount{acc}, balance)

return app
}
Expand All @@ -266,9 +276,9 @@ func SetupTestPrivSigner() (*appkeepers.PrivSigner, error) {
// of one consensus engine unit (10^6) in the default token of the babylon app from first genesis
// account. A Nop logger is set in BabylonApp.
// Note that the privSigner should be the 0th item of valSet
func SetupWithGenesisValSet(t *testing.T, valSet []*checkpointingtypes.GenesisKey, privSigner *appkeepers.PrivSigner, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *BabylonApp {
func SetupWithGenesisValSet(t *testing.T, btcConf bbn.SupportedBtcNetwork, valSet []*checkpointingtypes.GenesisKey, privSigner *appkeepers.PrivSigner, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *BabylonApp {
t.Helper()
app, genesisState := setup(t, privSigner, true, 5)
app, genesisState := setup(t, privSigner, true, 5, btcConf)
genesisState = genesisStateWithValSet(t, app, genesisState, valSet, genAccs, balances...)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down
48 changes: 25 additions & 23 deletions app/upgrades/v1/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,25 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.NotNil(respInst.Address)
},
},
// {
// "Test launch software upgrade v1 testnet",
// UpgradeV1DataTestnet,
// s.PreUpgrade,
// s.Upgrade,
// func() {
// s.PostUpgrade()

// // checks that anyone can instantiate a contract
// wasmMsgServer := wasmkeeper.NewMsgServerImpl(&s.app.WasmKeeper)
// resp, err := wasmMsgServer.StoreCode(s.ctx, &wasmtypes.MsgStoreCode{
// Sender: datagen.GenRandomAddress().String(),
// WASMByteCode: wasmContract,
// })
// s.NoError(err)
// s.EqualValues(resp.CodeID, 1)
// s.Equal(stakingWasmChecksum[:], wasmvmtypes.Checksum(resp.Checksum))
// },
// },
{
"Test launch software upgrade v1 testnet",
UpgradeV1DataTestnet,
s.PreUpgrade,
s.Upgrade,
func() {
s.PostUpgrade()

// checks that anyone can instantiate a contract
wasmMsgServer := wasmkeeper.NewMsgServerImpl(&s.app.WasmKeeper)
resp, err := wasmMsgServer.StoreCode(s.ctx, &wasmtypes.MsgStoreCode{
Sender: datagen.GenRandomAddress().String(),
WASMByteCode: wasmContract,
})
s.NoError(err)
s.EqualValues(resp.CodeID, 1)
s.Equal(stakingWasmChecksum[:], wasmvmtypes.Checksum(resp.Checksum))
},
},
}

for _, tc := range testCases {
Expand All @@ -181,10 +181,13 @@ func (s *UpgradeTestSuite) SetupTest(upgradeDataStr v1.UpgradeDataString) {
app.Upgrades = []upgrades.Upgrade{v1.CreateUpgrade(upgradeDataStr)}

// set up app
s.app = app.Setup(s.T(), false)
s.app = app.SetupWithBitcoinConf(s.T(), false, bbn.BtcSignet)
s.ctx = s.app.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "babylon-1", Time: time.Now().UTC()})
s.preModule = upgrade.NewAppModule(s.app.UpgradeKeeper, s.app.AccountKeeper.AddressCodec())

// 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())

k := s.app.BTCLightClientKeeper
Expand Down Expand Up @@ -340,16 +343,15 @@ func (s *UpgradeTestSuite) PostUpgrade() {
func SignetBtcHeader195552(t *testing.T) *btclighttypes.BTCHeaderInfo {
var btcHeader btclighttypes.BTCHeaderInfo
// signet btc header 0
btcHeaderHash, err := types.NewBTCHeaderBytesFromHex(`00000020c8710c5662ab0a4680963697765a390cba4814f95f0556fc5fb3b446b2000000fa9b80e52653455e5d4a4648fbe1f62854a07dbec0633a42ef595431de9be36dccb64366934f011ef3d98200`)
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 := sdkmath.NewUint(2979921237501018)
work := btclighttypes.CalcWork(&btcHeaderHash)
btcHeader = btclighttypes.BTCHeaderInfo{
Header: &btcHeaderHash,
Height: uint32(195552),
Expand Down
5 changes: 3 additions & 2 deletions testutil/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/babylonlabs-io/babylon/app"
appparams "github.com/babylonlabs-io/babylon/app/params"
bbn "github.com/babylonlabs-io/babylon/types"
btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
"github.com/babylonlabs-io/babylon/x/epoching/keeper"
"github.com/babylonlabs-io/babylon/x/epoching/types"
Expand Down Expand Up @@ -70,7 +71,7 @@ func NewHelperWithValSet(t *testing.T, valSet *datagen.GenesisValidators, privSi
GenAccs := []authtypes.GenesisAccount{acc}

// setup the app and ctx
app := app.SetupWithGenesisValSet(t, valSet.GetGenesisKeys(), privSigner, GenAccs, balance)
app := app.SetupWithGenesisValSet(t, bbn.BtcSimnet, valSet.GetGenesisKeys(), privSigner, GenAccs, balance)
ctx := app.BaseApp.NewContext(false).WithBlockHeight(1).WithHeaderInfo(header.Info{Height: 1}) // NOTE: height is 1

// get necessary subsets of the app/keeper
Expand Down Expand Up @@ -109,7 +110,7 @@ func NewHelperWithValSetNoSigner(t *testing.T, valSet *datagen.GenesisValidators
GenAccs := []authtypes.GenesisAccount{acc}

// setup the app and ctx
app := app.SetupWithGenesisValSet(t, valSet.GetGenesisKeys(), privSigner, GenAccs, balance)
app := app.SetupWithGenesisValSet(t, bbn.BtcSimnet, valSet.GetGenesisKeys(), privSigner, GenAccs, balance)
ctx := app.BaseApp.NewContext(false).WithBlockHeight(1).WithHeaderInfo(header.Info{Height: 1}) // NOTE: height is 1

// get necessary subsets of the app/keeper
Expand Down

0 comments on commit 815800a

Please sign in to comment.