Skip to content

Commit db4ec13

Browse files
mergify[bot]chattonsrdtrk
authored
Dockerfile added and go.mod local pin removed (backport #4406) (#4477)
* Support e2e tests for callback module SimApp (#4406) (cherry picked from commit 9a22ede) * deps: removed local ibc-go pin * ci: updated Docker file to remove copy lines * ci: removed this workflow, it is only needed in main * docs(callbacks/testing): fixed broken link in README --------- Co-authored-by: Cian Hatton <cian@interchain.io> Co-authored-by: srdtrk <srdtrk@hotmail.com>
1 parent 3201ab9 commit db4ec13

File tree

6 files changed

+366
-5
lines changed

6 files changed

+366
-5
lines changed

modules/apps/callbacks/Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM golang:1.21-alpine3.18 as builder
2+
3+
RUN set -eux; apk add --no-cache git libusb-dev linux-headers gcc musl-dev make;
4+
5+
ENV GOPATH=""
6+
ENV GOMODULE="on"
7+
8+
# Copy relevant files before go mod download. Replace directives to local paths break if local
9+
# files are not copied before go mod download.
10+
ADD internal internal
11+
ADD testing testing
12+
ADD modules modules
13+
ADD LICENSE LICENSE
14+
15+
WORKDIR modules/apps/callbacks
16+
17+
RUN go mod download
18+
19+
RUN GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false go build -mod=readonly -tags "netgo ledger" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=sim -X github.com/cosmos/cosmos-sdk/version.AppName=simd -X github.com/cosmos/cosmos-sdk/version.Version= -X github.com/cosmos/cosmos-sdk/version.Commit= -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo ledger," -w -s' -trimpath -o /go/build/ ./...
20+
21+
FROM alpine:3.18
22+
23+
COPY --from=builder /go/build/simd /bin/simd
24+
25+
ENTRYPOINT ["simd"]

modules/apps/callbacks/go.mod

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module github.com/cosmos/ibc-go/modules/apps/callbacks
22

33
go 1.20
44

5-
replace github.com/cosmos/ibc-go/v7 => ../../../
6-
75
replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
86

97
require (
@@ -14,8 +12,10 @@ require (
1412
github.com/cometbft/cometbft-db v0.8.0
1513
github.com/cosmos/cosmos-sdk v0.47.4
1614
github.com/cosmos/gogoproto v1.4.10
17-
github.com/cosmos/ibc-go/v7 v7.3.0-rc0
15+
github.com/cosmos/ibc-go/v7 v7.3.0-rc1
1816
github.com/spf13/cast v1.5.1
17+
github.com/spf13/cobra v1.7.0
18+
github.com/spf13/viper v1.16.0
1919
github.com/stretchr/testify v1.8.4
2020
)
2121

@@ -137,10 +137,8 @@ require (
137137
github.com/rs/zerolog v1.29.1 // indirect
138138
github.com/sasha-s/go-deadlock v0.3.1 // indirect
139139
github.com/spf13/afero v1.9.5 // indirect
140-
github.com/spf13/cobra v1.7.0 // indirect
141140
github.com/spf13/jwalterweatherman v1.1.0 // indirect
142141
github.com/spf13/pflag v1.0.5 // indirect
143-
github.com/spf13/viper v1.16.0 // indirect
144142
github.com/subosito/gotenv v1.4.2 // indirect
145143
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
146144
github.com/tendermint/go-amino v0.16.0 // indirect

modules/apps/callbacks/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK
332332
github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek=
333333
github.com/cosmos/iavl v0.20.0 h1:fTVznVlepH0KK8NyKq8w+U7c2L6jofa27aFX6YGlm38=
334334
github.com/cosmos/iavl v0.20.0/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
335+
github.com/cosmos/ibc-go/v7 v7.3.0-rc1 h1:nFVDlXrxHepknIgLgkn/IqyfqpKfANNw8pwd7jNYWzg=
336+
github.com/cosmos/ibc-go/v7 v7.3.0-rc1/go.mod h1:mUmaHFXpXrEdcxfdXyau+utZf14pGKVUiXwYftRZZfQ=
335337
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
336338
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
337339
github.com/cosmos/ledger-cosmos-go v0.12.1 h1:sMBxza5p/rNK/06nBSNmsI/WDqI0pVJFVNihy1Y984w=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Callbacks Testing SimApp
2+
3+
This testing directory is a duplicate of the ibc-go testing directory.
4+
It is only here as a way of creating a separate SimApp binary to avoid introducing a dependency on the callbacks
5+
module from within ibc-go.
6+
7+
The simapp can be built with the workflow found [here](https://github.com/cosmos/ibc-go/blob/main/.github/workflows/build-callbacks-simd-image-from-tag.yml).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"io"
6+
"os"
7+
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/viper"
10+
11+
"github.com/cosmos/cosmos-sdk/client"
12+
"github.com/cosmos/cosmos-sdk/client/config"
13+
"github.com/cosmos/cosmos-sdk/client/debug"
14+
"github.com/cosmos/cosmos-sdk/client/flags"
15+
"github.com/cosmos/cosmos-sdk/client/keys"
16+
"github.com/cosmos/cosmos-sdk/client/pruning"
17+
"github.com/cosmos/cosmos-sdk/client/rpc"
18+
"github.com/cosmos/cosmos-sdk/client/snapshot"
19+
"github.com/cosmos/cosmos-sdk/server"
20+
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
21+
servertypes "github.com/cosmos/cosmos-sdk/server/types"
22+
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
23+
sdk "github.com/cosmos/cosmos-sdk/types"
24+
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
25+
"github.com/cosmos/cosmos-sdk/x/auth/types"
26+
"github.com/cosmos/cosmos-sdk/x/crisis"
27+
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
28+
29+
dbm "github.com/cometbft/cometbft-db"
30+
cmtcfg "github.com/cometbft/cometbft/config"
31+
"github.com/cometbft/cometbft/libs/log"
32+
33+
"github.com/cosmos/ibc-go/modules/apps/callbacks/testing/simapp"
34+
"github.com/cosmos/ibc-go/modules/apps/callbacks/testing/simapp/params"
35+
)
36+
37+
// NewRootCmd creates a new root command for simd. It is called once in the
38+
// main function.
39+
func NewRootCmd() *cobra.Command {
40+
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
41+
tempApp := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome))
42+
encodingConfig := params.EncodingConfig{
43+
InterfaceRegistry: tempApp.InterfaceRegistry(),
44+
Codec: tempApp.AppCodec(),
45+
TxConfig: tempApp.TxConfig(),
46+
Amino: tempApp.LegacyAmino(),
47+
}
48+
49+
initClientCtx := client.Context{}.
50+
WithCodec(encodingConfig.Codec).
51+
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
52+
WithTxConfig(encodingConfig.TxConfig).
53+
WithLegacyAmino(encodingConfig.Amino).
54+
WithInput(os.Stdin).
55+
WithAccountRetriever(types.AccountRetriever{}).
56+
WithHomeDir(simapp.DefaultNodeHome).
57+
WithViper("") // In simapp, we don't use any prefix for env variables.
58+
59+
rootCmd := &cobra.Command{
60+
Use: "simd",
61+
Short: "simulation app",
62+
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
63+
// set the default command outputs
64+
cmd.SetOut(cmd.OutOrStdout())
65+
cmd.SetErr(cmd.ErrOrStderr())
66+
67+
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
68+
if err != nil {
69+
return err
70+
}
71+
72+
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
73+
if err != nil {
74+
return err
75+
}
76+
77+
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
78+
return err
79+
}
80+
81+
customAppTemplate, customAppConfig := initAppConfig()
82+
customTMConfig := initTendermintConfig()
83+
84+
return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
85+
},
86+
}
87+
88+
initRootCmd(rootCmd, encodingConfig)
89+
90+
return rootCmd
91+
}
92+
93+
// initTendermintConfig helps to override default Tendermint Config values.
94+
// return cmtcfg.DefaultConfig if no custom configuration is required for the application.
95+
func initTendermintConfig() *cmtcfg.Config {
96+
cfg := cmtcfg.DefaultConfig()
97+
98+
// these values put a higher strain on node memory
99+
// cfg.P2P.MaxNumInboundPeers = 100
100+
// cfg.P2P.MaxNumOutboundPeers = 40
101+
102+
return cfg
103+
}
104+
105+
// initAppConfig helps to override default appConfig template and configs.
106+
// return "", nil if no custom configuration is required for the application.
107+
func initAppConfig() (string, interface{}) {
108+
// The following code snippet is just for reference.
109+
110+
// WASMConfig defines configuration for the wasm module.
111+
type WASMConfig struct {
112+
// This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
113+
QueryGasLimit uint64 `mapstructure:"query_gas_limit"`
114+
115+
// Address defines the gRPC-web server to listen on
116+
LruSize uint64 `mapstructure:"lru_size"`
117+
}
118+
119+
type CustomAppConfig struct {
120+
serverconfig.Config
121+
122+
WASM WASMConfig `mapstructure:"wasm"`
123+
}
124+
125+
// Optionally allow the chain developer to overwrite the SDK's default
126+
// server config.
127+
srvCfg := serverconfig.DefaultConfig()
128+
// The SDK's default minimum gas price is set to "" (empty value) inside
129+
// app.toml. If left empty by validators, the node will halt on startup.
130+
// However, the chain developer can set a default app.toml value for their
131+
// validators here.
132+
//
133+
// In summary:
134+
// - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their
135+
// own app.toml config,
136+
// - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their
137+
// own app.toml to override, or use this default value.
138+
//
139+
// In simapp, we set the min gas prices to 0.
140+
srvCfg.MinGasPrices = "0stake"
141+
// srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default
142+
143+
customAppConfig := CustomAppConfig{
144+
Config: *srvCfg,
145+
WASM: WASMConfig{
146+
LruSize: 1,
147+
QueryGasLimit: 300000,
148+
},
149+
}
150+
151+
customAppTemplate := serverconfig.DefaultConfigTemplate + `
152+
[wasm]
153+
# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
154+
query_gas_limit = 300000
155+
# This is the number of wasm vm instances we keep cached in memory for speed-up
156+
# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally
157+
lru_size = 0`
158+
159+
return customAppTemplate, customAppConfig
160+
}
161+
162+
func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
163+
cfg := sdk.GetConfig()
164+
cfg.Seal()
165+
166+
rootCmd.AddCommand(
167+
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome),
168+
debug.Cmd(),
169+
config.Cmd(),
170+
pruning.PruningCmd(newApp),
171+
snapshot.Cmd(newApp),
172+
)
173+
174+
server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, appExport, addModuleInitFlags)
175+
176+
// add keybase, auxiliary RPC, query, genesis, and tx child commands
177+
rootCmd.AddCommand(
178+
rpc.StatusCommand(),
179+
genesisCommand(encodingConfig),
180+
queryCommand(),
181+
txCommand(),
182+
keys.Commands(simapp.DefaultNodeHome),
183+
)
184+
}
185+
186+
func addModuleInitFlags(startCmd *cobra.Command) {
187+
crisis.AddModuleInitFlags(startCmd)
188+
}
189+
190+
// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter
191+
func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command {
192+
cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, simapp.ModuleBasics, simapp.DefaultNodeHome)
193+
194+
for _, subCmd := range cmds {
195+
cmd.AddCommand(subCmd)
196+
}
197+
return cmd
198+
}
199+
200+
func queryCommand() *cobra.Command {
201+
cmd := &cobra.Command{
202+
Use: "query",
203+
Aliases: []string{"q"},
204+
Short: "Querying subcommands",
205+
DisableFlagParsing: false,
206+
SuggestionsMinimumDistance: 2,
207+
RunE: client.ValidateCmd,
208+
}
209+
210+
cmd.AddCommand(
211+
authcmd.GetAccountCmd(),
212+
rpc.ValidatorCommand(),
213+
rpc.BlockCommand(),
214+
authcmd.QueryTxsByEventsCmd(),
215+
authcmd.QueryTxCmd(),
216+
)
217+
218+
simapp.ModuleBasics.AddQueryCommands(cmd)
219+
220+
return cmd
221+
}
222+
223+
func txCommand() *cobra.Command {
224+
cmd := &cobra.Command{
225+
Use: "tx",
226+
Short: "Transactions subcommands",
227+
DisableFlagParsing: false,
228+
SuggestionsMinimumDistance: 2,
229+
RunE: client.ValidateCmd,
230+
}
231+
232+
cmd.AddCommand(
233+
authcmd.GetSignCommand(),
234+
authcmd.GetSignBatchCommand(),
235+
authcmd.GetMultiSignCommand(),
236+
authcmd.GetMultiSignBatchCmd(),
237+
authcmd.GetValidateSignaturesCommand(),
238+
authcmd.GetBroadcastCommand(),
239+
authcmd.GetEncodeCommand(),
240+
authcmd.GetDecodeCommand(),
241+
authcmd.GetAuxToFeeCommand(),
242+
)
243+
244+
simapp.ModuleBasics.AddTxCommands(cmd)
245+
246+
return cmd
247+
}
248+
249+
// newApp creates the application
250+
func newApp(
251+
logger log.Logger,
252+
db dbm.DB,
253+
traceStore io.Writer,
254+
appOpts servertypes.AppOptions,
255+
) servertypes.Application {
256+
baseappOptions := server.DefaultBaseappOptions(appOpts)
257+
258+
return simapp.NewSimApp(
259+
logger, db, traceStore, true,
260+
appOpts,
261+
baseappOptions...,
262+
)
263+
}
264+
265+
// appExport creates a new simapp (optionally at a given height) and exports state.
266+
func appExport(
267+
logger log.Logger,
268+
db dbm.DB,
269+
traceStore io.Writer,
270+
height int64,
271+
forZeroHeight bool,
272+
jailAllowedAddrs []string,
273+
appOpts servertypes.AppOptions,
274+
modulesToExport []string,
275+
) (servertypes.ExportedApp, error) {
276+
var simApp *simapp.SimApp
277+
278+
// this check is necessary as we use the flag in x/upgrade.
279+
// we can exit more gracefully by checking the flag here.
280+
homePath, ok := appOpts.Get(flags.FlagHome).(string)
281+
if !ok || homePath == "" {
282+
return servertypes.ExportedApp{}, errors.New("application home not set")
283+
}
284+
285+
viperAppOpts, ok := appOpts.(*viper.Viper)
286+
if !ok {
287+
return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper")
288+
}
289+
290+
// overwrite the FlagInvCheckPeriod
291+
viperAppOpts.Set(server.FlagInvCheckPeriod, 1)
292+
appOpts = viperAppOpts
293+
294+
if height != -1 {
295+
simApp = simapp.NewSimApp(logger, db, traceStore, false, appOpts)
296+
297+
if err := simApp.LoadHeight(height); err != nil {
298+
return servertypes.ExportedApp{}, err
299+
}
300+
} else {
301+
simApp = simapp.NewSimApp(logger, db, traceStore, true, appOpts)
302+
}
303+
304+
return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
305+
}

0 commit comments

Comments
 (0)