|
| 1 | +package simulation |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + simappparams "github.com/line/lbm-sdk/simapp/params" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + "github.com/line/lbm-sdk/types/module" |
| 11 | + "github.com/line/lbm-sdk/x/simulation" |
| 12 | + "github.com/line/lbm-sdk/x/wasm/keeper" |
| 13 | + "github.com/line/lbm-sdk/x/wasm/types" |
| 14 | +) |
| 15 | + |
| 16 | +func TestWeightedOperations(t *testing.T) { |
| 17 | + type args struct { |
| 18 | + simstate *module.SimulationState |
| 19 | + ak types.AccountKeeper |
| 20 | + bk simulation.BankKeeper |
| 21 | + wasmKeeper WasmKeeper |
| 22 | + wasmBz []byte |
| 23 | + } |
| 24 | + |
| 25 | + params := args{ |
| 26 | + simstate: &module.SimulationState{}, |
| 27 | + wasmKeeper: makeKeeper(t).WasmKeeper, |
| 28 | + } |
| 29 | + |
| 30 | + tests := []struct { |
| 31 | + name string |
| 32 | + args args |
| 33 | + want simulation.WeightedOperations |
| 34 | + }{ |
| 35 | + { |
| 36 | + name: "execute success", |
| 37 | + args: args{ |
| 38 | + simstate: &module.SimulationState{}, |
| 39 | + }, |
| 40 | + want: simulation.WeightedOperations{ |
| 41 | + simulation.NewWeightedOperation( |
| 42 | + simappparams.DefaultWeightMsgStoreCode, |
| 43 | + SimulateMsgStoreCode(params.ak, params.bk, params.wasmKeeper, params.wasmBz)), |
| 44 | + simulation.NewWeightedOperation( |
| 45 | + simappparams.DefaultWeightMsgInstantiateContract, |
| 46 | + SimulateMsgInstantiateContract(params.ak, params.bk, params.wasmKeeper)), |
| 47 | + }, |
| 48 | + }, |
| 49 | + } |
| 50 | + |
| 51 | + for _, tt := range tests { |
| 52 | + t.Run(tt.name, func(t *testing.T) { |
| 53 | + got := WeightedOperations(tt.args.simstate, tt.args.ak, tt.args.bk, tt.args.wasmKeeper) |
| 54 | + for i := range got { |
| 55 | + require.Equal(t, tt.want[i].Weight(), got[i].Weight(), "WeightedOperations().Weight()") |
| 56 | + |
| 57 | + expected := reflect.TypeOf(tt.want[i].Op()).String() |
| 58 | + actual := reflect.TypeOf(got[i].Op()).String() |
| 59 | + |
| 60 | + require.Equal(t, expected, actual, "return value type should be the same") |
| 61 | + } |
| 62 | + }) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +// Copy from keeper_test.go |
| 67 | +const SupportedFeatures = "iterator,staking,stargate" |
| 68 | + |
| 69 | +// Copy from keeper_test.go |
| 70 | +func makeKeeper(t *testing.T) keeper.TestKeepers { |
| 71 | + _, keepers := keeper.CreateTestInput(t, false, SupportedFeatures, nil, nil) |
| 72 | + return keepers |
| 73 | +} |
0 commit comments