Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10/keeper"
|
|
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10/types"
|
|
)
|
|
|
|
func (suite *KeeperTestSuite) TestMigrateWasmStore() {
|
|
testCases := []struct {
|
|
name string
|
|
checksums [][]byte
|
|
}{
|
|
{
|
|
"success: empty checksums",
|
|
[][]byte{},
|
|
},
|
|
{
|
|
"success: multiple checksums",
|
|
[][]byte{[]byte("hash1"), []byte("hash2"), []byte("hash3")},
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
suite.Run(tc.name, func() {
|
|
suite.SetupTest()
|
|
|
|
suite.storeChecksums(tc.checksums)
|
|
|
|
// run the migration
|
|
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper
|
|
m := keeper.NewMigrator(wasmClientKeeper)
|
|
|
|
err := m.MigrateChecksums(suite.chainA.GetContext())
|
|
suite.Require().NoError(err)
|
|
|
|
// check that they were stored in KeySet
|
|
for _, hash := range tc.checksums {
|
|
suite.Require().True(wasmClientKeeper.GetChecksums().Has(suite.chainA.GetContext(), hash))
|
|
}
|
|
|
|
// check that the data under the old key was deleted
|
|
store := suite.chainA.GetContext().KVStore(GetSimApp(suite.chainA).GetKey(types.StoreKey))
|
|
suite.Require().Nil(store.Get([]byte(types.KeyChecksums)))
|
|
})
|
|
}
|
|
}
|
|
|
|
// storeChecksums stores the given checksums under the KeyChecksums key, it runs
|
|
// each time on an empty store so we don't need to read the previous checksums.
|
|
func (suite *KeeperTestSuite) storeChecksums(checksums [][]byte) {
|
|
ctx := suite.chainA.GetContext()
|
|
|
|
store := ctx.KVStore(GetSimApp(suite.chainA).GetKey(types.StoreKey))
|
|
checksum := types.Checksums{Checksums: checksums}
|
|
bz, err := GetSimApp(suite.chainA).AppCodec().Marshal(&checksum)
|
|
suite.Require().NoError(err)
|
|
|
|
store.Set([]byte(types.KeyChecksums), bz)
|
|
}
|