Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix to prevent external filesystem dependency of simulations #695

Merged
merged 10 commits into from
Oct 18, 2022
62 changes: 62 additions & 0 deletions x/wasm/keeper/testdata/reflect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package testdata

import (
_ "embed"

"github.com/line/lbm-sdk/types"
typwasmvmtypes "github.com/line/wasmvm/types"
)

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

func ReflectContractWasm() []byte {
return reflectContract
}

// ReflectHandleMsg is used to encode handle messages
type ReflectHandleMsg struct {
Reflect *ReflectPayload `json:"reflect_msg,omitempty"`
ReflectSubMsg *ReflectSubPayload `json:"reflect_sub_msg,omitempty"`
ChangeOwner *OwnerPayload `json:"change_owner,omitempty"`
}

type OwnerPayload struct {
Owner types.Address `json:"owner"`
}

type ReflectPayload struct {
Msgs []typwasmvmtypes.CosmosMsg `json:"msgs"`
}

type ReflectSubPayload struct {
Msgs []typwasmvmtypes.SubMsg `json:"msgs"`
}

// ReflectQueryMsg is used to encode query messages
type ReflectQueryMsg struct {
Owner *struct{} `json:"owner,omitempty"`
Capitalized *Text `json:"capitalized,omitempty"`
Chain *ChainQuery `json:"chain,omitempty"`
SubMsgResult *SubCall `json:"sub_msg_result,omitempty"`
}

type ChainQuery struct {
Request *typwasmvmtypes.QueryRequest `json:"request,omitempty"`
}

type Text struct {
Text string `json:"text"`
}

type SubCall struct {
ID uint64 `json:"id"`
}

type OwnerResponse struct {
Owner string `json:"owner,omitempty"`
}

type ChainResponse struct {
Data []byte `json:"data,omitempty"`
}
18 changes: 12 additions & 6 deletions x/wasm/simulation/operations.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package simulation

import (
"io/ioutil"
"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 @@ -53,14 +54,19 @@ func WeightedOperations(
)
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"
wasmContractPath = ""
},
)

wasmBz, err := ioutil.ReadFile(wasmContractPath)
if err != nil {
panic(err)
var wasmBz []byte
if wasmContractPath == "" {
wasmBz = testdata.ReflectContractWasm()
} else {
var err error
wasmBz, err = os.ReadFile(wasmContractPath)
if err != nil {
panic(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding the unittest of this lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code, so I deleted it.

}
}

return simulation.WeightedOperations{
Expand Down