forked from CosmWasm/wasmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore_test.go
101 lines (92 loc) · 2.89 KB
/
store_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package v2_test
import (
"testing"
"github.com/cometbft/cometbft/libs/rand"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/CosmWasm/wasmd/x/wasm"
v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
func TestMigrate(t *testing.T) {
cfg := moduletestutil.MakeTestEncodingConfig(wasm.AppModuleBasic{})
cdc := cfg.Codec
var (
wasmStoreKey = storetypes.NewKVStoreKey(types.StoreKey)
paramsStoreKey = storetypes.NewKVStoreKey(paramstypes.StoreKey)
paramsTStoreKey = storetypes.NewTransientStoreKey(paramstypes.TStoreKey)
myAddress = sdk.AccAddress(rand.Bytes(address.Len))
)
specs := map[string]struct {
src v2.Params
}{
"one address": {
src: v2.Params{
CodeUploadAccess: v2.AccessConfig{
Permission: v2.AccessTypeOnlyAddress,
Address: myAddress.String(),
},
InstantiateDefaultPermission: v2.AccessTypeNobody,
},
},
"multiple addresses": {
src: v2.Params{
CodeUploadAccess: v2.AccessConfig{
Permission: v2.AccessTypeAnyOfAddresses,
Addresses: []string{myAddress.String(), sdk.AccAddress(rand.Bytes(address.Len)).String()},
},
InstantiateDefaultPermission: v2.AccessTypeEverybody,
},
},
"everybody": {
src: v2.Params{
CodeUploadAccess: v2.AccessConfig{
Permission: v2.AccessTypeEverybody,
},
InstantiateDefaultPermission: v2.AccessTypeEverybody,
},
},
"nobody": {
src: v2.Params{
CodeUploadAccess: v2.AccessConfig{
Permission: v2.AccessTypeNobody,
},
InstantiateDefaultPermission: v2.AccessTypeNobody,
},
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
paramsKeeper := paramskeeper.NewKeeper(cdc, cfg.Amino, paramsStoreKey, paramsTStoreKey)
ctx := testutil.DefaultContextWithKeys(
map[string]*storetypes.KVStoreKey{
paramstypes.StoreKey: paramsStoreKey,
types.StoreKey: wasmStoreKey,
},
map[string]*storetypes.TransientStoreKey{
paramstypes.TStoreKey: paramsTStoreKey,
},
nil,
)
// register legacy parameters
params := spec.src
subspace := paramsKeeper.Subspace(types.ModuleName)
subspace.WithKeyTable(v2.ParamKeyTable())
subspace.SetParamSet(ctx, ¶ms)
// when
require.NoError(t, v2.MigrateStore(ctx, runtime.NewKVStoreService(wasmStoreKey), subspace, cdc))
var res v2.Params
bz := ctx.KVStore(wasmStoreKey).Get(types.ParamsKey)
require.NoError(t, cdc.Unmarshal(bz, &res))
assert.Equal(t, params, res)
})
}
}