Skip to content

Commit

Permalink
Merge branch 'main' into foundation_pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech authored Oct 18, 2022
2 parents 46b2cd7 + 5ed82db commit 163c337
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/modules) [\#722](https://github.com/line/lbm-sdk/pull/722) Check error for `RegisterQueryHandlerClient` in all modules `RegisterGRPCGatewayRoutes`
* (x/bank) [\#716](https://github.com/line/lbm-sdk/pull/716) remove useless DenomMetadata key function
* (x/foundation) [\#704](https://github.com/line/lbm-sdk/pull/704) update x/foundation params
* (x/wasm) [\#695](https://github.com/line/lbm-sdk/pull/695) fix to prevent external filesystem dependency of simulation

### Bug Fixes
* (x/wasm) [\#453](https://github.com/line/lbm-sdk/pull/453) modify wasm grpc query api path
Expand All @@ -103,7 +104,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (global) [\#694](https://github.com/line/lbm-sdk/pull/694) replace deprecated functions since go 1.16 or 1.17
* (x/bankplus) [\#705](https://github.com/line/lbm-sdk/pull/705) add missing blockedAddr checking in bankplus
* (x/foundation) [\#712](https://github.com/line/lbm-sdk/pull/712) fix x/foundation EndBlocker
* (baseapp) [\#724](https://github.com/line/lbm-sdk/pull/724) add checking pubkey type from validator params
* (x/staking) [\#726](https://github.com/line/lbm-sdk/pull/726) check allowedList size in StakeAuthorization.Accept()
* (x/staking) [\#728](https://github.com/line/lbm-sdk/pull/728) fix typo in unbondingToUnbonded() panic
* (x/foundation) [\#730](https://github.com/line/lbm-sdk/pull/730) prune stale x/foundation proposals at voting period end

### Breaking Changes
Expand Down
10 changes: 10 additions & 0 deletions baseapp/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

abci "github.com/line/ostracon/abci/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"
octypes "github.com/line/ostracon/types"

sdk "github.com/line/lbm-sdk/types"
)
Expand Down Expand Up @@ -82,5 +83,14 @@ func ValidateValidatorParams(i interface{}) error {
return errors.New("validator allowed pubkey types must not be empty")
}

for _, pubKeyType := range v.PubKeyTypes {
switch pubKeyType {
case octypes.ABCIPubKeyTypeBls12WithEd25519, octypes.ABCIPubKeyTypeEd25519, octypes.ABCIPubKeyTypeSecp256k1, octypes.ABCIPubKeyTypeBls12:
continue
default:
return fmt.Errorf("not-allowed pubkey type: %s", pubKeyType)
}
}

return nil
}
1 change: 1 addition & 0 deletions baseapp/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestValidateValidatorParams(t *testing.T) {
{ocproto.ValidatorParams{}, true},
{ocproto.ValidatorParams{PubKeyTypes: []string{}}, true},
{ocproto.ValidatorParams{PubKeyTypes: []string{"secp256k1"}}, false},
{ocproto.ValidatorParams{PubKeyTypes: []string{"invalidPubKeyType"}}, true},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (k Keeper) unbondedToBonded(ctx sdk.Context, validator types.Validator) (ty
// UnbondingToUnbonded switches a validator from unbonding state to unbonded state
func (k Keeper) UnbondingToUnbonded(ctx sdk.Context, validator types.Validator) types.Validator {
if !validator.IsUnbonding() {
panic(fmt.Sprintf("bad state transition unbondingToBonded, validator: %v\n", validator))
panic(fmt.Sprintf("bad state transition unbondingToUnbonded, validator: %v\n", validator))
}

return k.completeUnbondingValidator(ctx, validator)
Expand Down
30 changes: 30 additions & 0 deletions x/staking/keeper/val_state_change_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package keeper_test

import (
"github.com/line/lbm-sdk/x/staking/keeper"
"github.com/line/lbm-sdk/x/staking/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func TestUnbondingToUnbondedPanic(t *testing.T) {
app, ctx, _, _, validators := initValidators(t, 100, 2, []int64{0, 100})

for i, validator := range validators {
validators[i] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, false)
}

assert.Equal(t, validators[0].Status, types.Unbonded)
assert.Equal(t, validators[1].Status, types.Bonded)

// unbond validator which is in unbonded status
require.Panics(t, func() {
app.StakingKeeper.UnbondingToUnbonded(ctx, validators[0])
})

// unbond validator which is in bonded status
require.Panics(t, func() {
app.StakingKeeper.UnbondingToUnbonded(ctx, validators[1])
})
}
12 changes: 12 additions & 0 deletions x/wasm/keeper/testdata/reflect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package testdata

import (
_ "embed"
)

//go:embed reflect.wasm
var reflectContract []byte

func ReflectContractWasm() []byte {
return reflectContract
}
14 changes: 2 additions & 12 deletions x/wasm/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package simulation

import (
"math/rand"
"os"

"github.com/line/lbm-sdk/baseapp"
simappparams "github.com/line/lbm-sdk/simapp/params"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/types/module"
simtypes "github.com/line/lbm-sdk/types/simulation"
"github.com/line/lbm-sdk/x/simulation"
"github.com/line/lbm-sdk/x/wasm/keeper/testdata"
"github.com/line/lbm-sdk/x/wasm/types"
)

Expand Down Expand Up @@ -37,7 +37,6 @@ func WeightedOperations(
var (
weightMsgStoreCode int
weightMsgInstantiateContract int
wasmContractPath string
)

simstate.AppParams.GetOrGenerate(simstate.Cdc, OpWeightMsgStoreCode, &weightMsgStoreCode, nil,
Expand All @@ -51,17 +50,8 @@ func WeightedOperations(
weightMsgInstantiateContract = simappparams.DefaultWeightMsgInstantiateContract
},
)
simstate.AppParams.GetOrGenerate(simstate.Cdc, OpReflectContractPath, &wasmContractPath, nil,
func(_ *rand.Rand) {
// simulations are run from the `app` folder
wasmContractPath = "../x/wasm/keeper/testdata/reflect.wasm"
},
)

wasmBz, err := os.ReadFile(wasmContractPath)
if err != nil {
panic(err)
}
wasmBz := testdata.ReflectContractWasm()

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
Expand Down
73 changes: 73 additions & 0 deletions x/wasm/simulation/operations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package simulation

import (
"reflect"
"testing"

simappparams "github.com/line/lbm-sdk/simapp/params"
"github.com/stretchr/testify/require"

"github.com/line/lbm-sdk/types/module"
"github.com/line/lbm-sdk/x/simulation"
"github.com/line/lbm-sdk/x/wasm/keeper"
"github.com/line/lbm-sdk/x/wasm/types"
)

func TestWeightedOperations(t *testing.T) {
type args struct {
simstate *module.SimulationState
ak types.AccountKeeper
bk simulation.BankKeeper
wasmKeeper WasmKeeper
wasmBz []byte
}

params := args{
simstate: &module.SimulationState{},
wasmKeeper: makeKeeper(t).WasmKeeper,
}

tests := []struct {
name string
args args
want simulation.WeightedOperations
}{
{
name: "execute success",
args: args{
simstate: &module.SimulationState{},
},
want: simulation.WeightedOperations{
simulation.NewWeightedOperation(
simappparams.DefaultWeightMsgStoreCode,
SimulateMsgStoreCode(params.ak, params.bk, params.wasmKeeper, params.wasmBz)),
simulation.NewWeightedOperation(
simappparams.DefaultWeightMsgInstantiateContract,
SimulateMsgInstantiateContract(params.ak, params.bk, params.wasmKeeper)),
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := WeightedOperations(tt.args.simstate, tt.args.ak, tt.args.bk, tt.args.wasmKeeper)
for i := range got {
require.Equal(t, tt.want[i].Weight(), got[i].Weight(), "WeightedOperations().Weight()")

expected := reflect.TypeOf(tt.want[i].Op()).String()
actual := reflect.TypeOf(got[i].Op()).String()

require.Equal(t, expected, actual, "return value type should be the same")
}
})
}
}

// Copy from keeper_test.go
const SupportedFeatures = "iterator,staking,stargate"

// Copy from keeper_test.go
func makeKeeper(t *testing.T) keeper.TestKeepers {
_, keepers := keeper.CreateTestInput(t, false, SupportedFeatures, nil, nil)
return keepers
}

0 comments on commit 163c337

Please sign in to comment.