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

feat(simapp): move simapp binary into its own go.mod #6710

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
871ea13
move simapp to a separate go module
gjermundgaraba Jun 25, 2024
d7589a8
remove unecessary modules from testing/simapp
gjermundgaraba Jun 26, 2024
6221eda
Fix tests
gjermundgaraba Jun 26, 2024
138fff4
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
gjermundgaraba Jun 26, 2024
d308819
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
gjermundgaraba Jun 26, 2024
01e341d
refactor: trim out unnecessary files/code of new simapp go.mod
colin-axner Jul 3, 2024
d6b8bff
refactor: remove unnecessary code in testing simapp package
colin-axner Jul 3, 2024
d293128
remove: upgrade logic and crisis module from testing simapp
colin-axner Jul 3, 2024
b39e7b4
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
colin-axner Jul 3, 2024
8e1ae9f
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
gjermundgaraba Jul 8, 2024
cd4359c
Update simapp go.mod
gjermundgaraba Jul 8, 2024
7c72478
Fix compile issue with new simapp
gjermundgaraba Jul 8, 2024
6221687
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
gjermundgaraba Jul 9, 2024
82bca13
lint
gjermundgaraba Jul 9, 2024
b2df398
go mod tidy e2e
colin-axner Jul 9, 2024
b258687
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
gjermundgaraba Jul 9, 2024
0a4d12e
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
gjermundgaraba Jul 9, 2024
c3bc711
Fix fail after merge
gjermundgaraba Jul 9, 2024
da7ce7c
Merge branch 'main' into gjermund/3968-move-simapp-binary-into-own-go…
colin-axner Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN test -n "${IBC_GO_VERSION}"
# Copy relevant files before go mod download. Replace directives to local paths break if local
# files are not copied before go mod download.
ADD internal internal
ADD simapp simapp
ADD testing testing
ADD modules modules
ADD LICENSE LICENSE
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
BUILDDIR ?= $(CURDIR)/build
SIMAPP = ./testing/simapp
SIMAPP = ./simapp
Copy link
Contributor

Choose a reason for hiding this comment

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

love how few changes are needed here!

MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/cosmos/ibc-go.git
DOCKER := $(shell which docker)
Expand Down Expand Up @@ -116,7 +116,7 @@ build-linux:
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
cd simapp && go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/
Expand Down
2 changes: 0 additions & 2 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/store v1.1.0 // indirect
cosmossdk.io/x/circuit v0.1.1 // indirect
cosmossdk.io/x/evidence v0.1.1 // indirect
cosmossdk.io/x/feegrant v0.1.1 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/transfer/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (suite *AuthzTransferTestSuite) TestAuthz_InvalidTransferAuthorizations() {
// extractTransferAuthorizationFromGrantAuthorization extracts a TransferAuthorization from the given
// GrantAuthorization.
func (suite *AuthzTransferTestSuite) extractTransferAuthorizationFromGrantAuthorization(grantAuth *authz.GrantAuthorization) *transfertypes.TransferAuthorization {
cfg := testsuite.EncodingConfig()
cfg := testsuite.SDKEncodingConfig()
var authorization authz.Authorization
err := cfg.InterfaceRegistry.UnpackAny(grantAuth.Authorization, &authorization)
suite.Require().NoError(err)
Expand Down
11 changes: 2 additions & 9 deletions e2e/testsuite/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
simappparams "github.com/cosmos/ibc-go/v8/testing/simapp/params"
)

// Codec returns the global E2E protobuf codec.
Expand All @@ -44,12 +43,6 @@ func Codec() *codec.ProtoCodec {
return cdc
}

// EncodingConfig returns the global E2E encoding config.
func EncodingConfig() simappparams.EncodingConfig {
_, cfg := codecAndEncodingConfig()
return cfg
}

// SDKEncodingConfig returns the global E2E encoding config.
func SDKEncodingConfig() *testutil.TestEncodingConfig {
_, cfg := codecAndEncodingConfig()
Expand All @@ -61,8 +54,8 @@ func SDKEncodingConfig() *testutil.TestEncodingConfig {
}
}

func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) {
cfg := simappparams.MakeTestEncodingConfig()
func codecAndEncodingConfig() (*codec.ProtoCodec, testutil.TestEncodingConfig) {
cfg := testutil.MakeTestEncodingConfig()

// ibc types
icacontrollertypes.RegisterInterfaces(cfg.InterfaceRegistry)
Expand Down
8 changes: 1 addition & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ require (
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
cosmossdk.io/tools/confix v0.1.1
cosmossdk.io/x/circuit v0.1.1
cosmossdk.io/x/evidence v0.1.1
cosmossdk.io/x/feegrant v0.1.1
Comment on lines -15 to -18
Copy link
Contributor

Choose a reason for hiding this comment

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

wahooo!!! 🎉

cosmossdk.io/x/tx v0.13.3
cosmossdk.io/x/upgrade v0.1.3
github.com/cometbft/cometbft v0.38.9
Expand All @@ -30,7 +26,6 @@ require (
github.com/hashicorp/go-metrics v0.5.3
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094
google.golang.org/grpc v1.65.0
Expand Down Expand Up @@ -75,8 +70,6 @@ require (
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
Expand Down Expand Up @@ -169,6 +162,7 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk=
cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng=
cosmossdk.io/tools/confix v0.1.1 h1:aexyRv9+y15veH3Qw16lxQwo+ki7r2I+g0yNTEFEQM8=
cosmossdk.io/tools/confix v0.1.1/go.mod h1:nQVvP1tHsGXS83PonPVWJtSbddIqyjEw99L4M3rPJyQ=
cosmossdk.io/x/circuit v0.1.1 h1:KPJCnLChWrxD4jLwUiuQaf5mFD/1m7Omyo7oooefBVQ=
cosmossdk.io/x/circuit v0.1.1/go.mod h1:B6f/urRuQH8gjt4eLIXfZJucrbreuYrKh5CSjaOxr+Q=
cosmossdk.io/x/evidence v0.1.1 h1:Ks+BLTa3uftFpElLTDp9L76t2b58htjVbSZ86aoK/E4=
cosmossdk.io/x/evidence v0.1.1/go.mod h1:OoDsWlbtuyqS70LY51aX8FBTvguQqvFrt78qL7UzeNc=
cosmossdk.io/x/feegrant v0.1.1 h1:EKFWOeo/pup0yF0svDisWWKAA9Zags6Zd0P3nRvVvw8=
cosmossdk.io/x/feegrant v0.1.1/go.mod h1:2GjVVxX6G2fta8LWj7pC/ytHjryA6MHAJroBWHFNiEQ=
cosmossdk.io/x/tx v0.13.3 h1:Ha4mNaHmxBc6RMun9aKuqul8yHiL78EKJQ8g23Zf73g=
cosmossdk.io/x/tx v0.13.3/go.mod h1:I8xaHv0rhUdIvIdptKIqzYy27+n2+zBVaxO6fscFhys=
cosmossdk.io/x/upgrade v0.1.3 h1:q4XpXc6zp0dX6x74uBtfN6+J7ikaQev5Bla6Q0ADLK8=
Expand Down Expand Up @@ -370,10 +362,6 @@ github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5n
github.com/cosmos/ledger-cosmos-go v0.13.3/go.mod h1:HENcEP+VtahZFw38HZ3+LS3Iv5XV6svsnkk9vdJtLr8=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creachadair/atomicfile v0.3.1 h1:yQORkHjSYySh/tv5th1dkKcn02NEW5JleB84sjt+W4Q=
github.com/creachadair/atomicfile v0.3.1/go.mod h1:mwfrkRxFKwpNAflYZzytbSwxvbK6fdGRRlp0KEQc0qU=
github.com/creachadair/tomledit v0.0.24 h1:5Xjr25R2esu1rKCbQEmjZYlrhFkDspoAbAKb6QKQDhQ=
github.com/creachadair/tomledit v0.0.24/go.mod h1:9qHbShRWQzSCcn617cMzg4eab1vbLCOjOshAWSzWr8U=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/danieljoos/wincred v1.2.1 h1:dl9cBrupW8+r5250DYkYxocLeZ1Y4vB1kxgtjxw8GQs=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ func (suite *KeeperTestSuite) TestNewModuleQuerySafeAllowList() {
suite.Require().Contains(allowList, "/cosmos.bank.v1beta1.Query/AllBalances")
suite.Require().Contains(allowList, "/cosmos.staking.v1beta1.Query/Validator")
suite.Require().Contains(allowList, "/cosmos.staking.v1beta1.Query/Validators")
suite.Require().Contains(allowList, "/cosmos.circuit.v1.Query/Account")
suite.Require().Contains(allowList, "/cosmos.circuit.v1.Query/DisabledList")
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
suite.Require().Contains(allowList, "/cosmos.auth.v1beta1.Query/Accounts")
suite.Require().Contains(allowList, "/cosmos.auth.v1beta1.Query/ModuleAccountByName")
suite.Require().Contains(allowList, "/ibc.core.client.v1.Query/VerifyMembership")
Expand Down
14 changes: 11 additions & 3 deletions modules/core/02-client/keeper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

abci "github.com/cometbft/cometbft/abci/types"

clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down Expand Up @@ -517,10 +519,16 @@ func (suite *KeeperTestSuite) TestUpdateClientEventEmission() {
suite.Require().NoError(err)

result, err := suite.chainA.SendMsgs(msg)

// check that update client event was emitted
suite.Require().NoError(err)
// first event type is "message", followed by 3 "tx" events in ante
updateEvent := result.Events[4]
suite.Require().Equal(clienttypes.EventTypeUpdateClient, updateEvent.Type)
var event abci.Event
for _, e := range result.Events {
if e.Type == clienttypes.EventTypeUpdateClient {
event = e
}
}
suite.Require().NotNil(event)
}

func (suite *KeeperTestSuite) TestRecoverClient() {
Expand Down
47 changes: 47 additions & 0 deletions simapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# simapp
Copy link
Contributor

Choose a reason for hiding this comment

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

I will go through this document and open a PR if it needs to be updated.


simapp is an application built using the Cosmos SDK for testing and educational purposes.

## Running testnets with `simd`

If you want to spin up a quick testnet with your friends, you can follow these steps.
Unless otherwise noted, every step must be done by everyone who wants to participate
in this testnet.

1. `$ make build`. This will build the `simd` binary and install it in your Cosmos SDK repo,
inside a new `build` directory. The following instructions are run from inside
that directory.
2. If you've run `simd` before, you may need to reset your database before starting a new
testnet: `$ ./simd unsafe-reset-all`
3. `$ ./simd init [moniker]`. This will initialize a new working directory, by default at
`~/.simapp`. You need a provide a "moniker," but it doesn't matter what it is.
4. `$ ./simd keys add [key_name]`. This will create a new key, with a name of your choosing.
Save the output of this command somewhere; you'll need the address generated here later.
5. `$ ./simd add-genesis-account $(simd keys show [key_name] -a) [amount]`, where `key_name`
is the same key name as before; and `amount` is something like `10000000000000000000000000stake`.
6. `$ ./simd gentx [key_name] [amount] --chain-id [chain-id]`. This will create the
genesis transaction for your new chain.
7. Now, one person needs to create the genesis file `genesis.json` using the genesis transactions
from every participant, by gathering all the genesis transactions under `config/gentx` and then
calling `./simd collect-gentxs`. This will create a new `genesis.json` file that includes data
from all the validators (we sometimes call it the "super genesis file" to distinguish it from
single-validator genesis files).
8. Once you've received the super genesis file, overwrite your original `genesis.json` file with
the new super `genesis.json`.
9. Modify your `config/config.toml` (in the simapp working directory) to include the other participants as
persistent peers:

```text
# Comma separated list of nodes to keep persistent connections to
persistent_peers = "[validator address]@[ip address]:[port],[validator address]@[ip address]:[port]"
```

You can find `validator address` by running `./simd tendermint show-node-id`. (It will be hex-encoded.)
By default, `port` is 26656.
10. Now you can start your nodes: `$ ./simd start`.

Now you have a small testnet that you can use to try out changes to the Cosmos SDK or Tendermint!

NOTE: Sometimes creating the network through the `collect-gentxs` will fail, and validators will start
in a funny state (and then panic). If this happens, you can try to create and start the network first
with a single validator and then add additional validators using a `create-validator` transaction.
56 changes: 56 additions & 0 deletions simapp/ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package simapp

import (
"errors"

circuitante "cosmossdk.io/x/circuit/ante"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"

ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
"github.com/cosmos/ibc-go/v8/modules/core/keeper"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
type HandlerOptions struct {
ante.HandlerOptions
CircuitKeeper circuitante.CircuitBreaker
IBCKeeper *keeper.Keeper
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, errors.New("account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, errors.New("bank keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, errors.New("sign mode handler is required for ante builder")
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
}
Loading
Loading