Skip to content

Commit

Permalink
feat: add genesis modification function to e2e (#2112)
Browse files Browse the repository at this point in the history
## Description

Configures genesis properly for passing gov proposals. See #2071 for passing tests

closes: #2077 

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing)
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [ ] Re-reviewed `Files changed` in the Github PR explorer
- [ ] Review `Codecov Report` in the comment section below once CI passes
  • Loading branch information
colin-axner authored Aug 25, 2022
1 parent 8911d8d commit b6dd724
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
59 changes: 59 additions & 0 deletions e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package testconfig

import (
"encoding/json"
"fmt"
"os"

"github.com/cosmos/cosmos-sdk/codec"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/strangelove-ventures/ibctest/ibc"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/ibc-go/e2e/testvalues"
)

const (
Expand Down Expand Up @@ -150,3 +161,51 @@ func newDefaultSimappConfig(cc ChainConfig, name, chainID, denom string) ibc.Cha
NoHostMount: false,
}
}

// defaultModifyGenesis will only modify governance params to ensure the voting period and minimum deposit
// are functional for e2e testing purposes.
func defaultModifyGenesis(denom string) func([]byte) ([]byte, error) {
return func(genbz []byte) ([]byte, error) {
genDoc, err := tmtypes.GenesisDocFromJSON(genbz)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err)
}

var appState genutiltypes.AppMap
if err := json.Unmarshal(genDoc.AppState, &appState); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis bytes into app state: %w", err)
}

cfg := simappparams.MakeTestEncodingConfig()
govv1beta1.RegisterInterfaces(cfg.InterfaceRegistry)
cdc := codec.NewProtoCodec(cfg.InterfaceRegistry)

govGenesisState := &govv1beta1.GenesisState{}
if err := cdc.UnmarshalJSON(appState[govtypes.ModuleName], govGenesisState); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis bytes into gov genesis state: %w", err)
}

// set correct minimum deposit using configured denom
govGenesisState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(denom, govv1beta1.DefaultMinDepositTokens))
govGenesisState.VotingParams.VotingPeriod = testvalues.VotingPeriod

govGenBz, err := cdc.MarshalJSON(govGenesisState)
if err != nil {
return nil, fmt.Errorf("failed to marshal gov genesis state: %w", err)
}

appState[govtypes.ModuleName] = govGenBz

genDoc.AppState, err = json.Marshal(appState)
if err != nil {
return nil, err
}

bz, err := tmjson.MarshalIndent(genDoc, "", " ")
if err != nil {
return nil, err
}

return bz, nil
}
}
9 changes: 6 additions & 3 deletions e2e/testvalues/values.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package testvalues

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/ibctest/ibc"

feetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
)

const (
StartingTokenAmount int64 = 100_000_000
IBCTransferAmount int64 = 10_000
InvalidAddress string = "<invalid-address>"
StartingTokenAmount int64 = 100_000_000
IBCTransferAmount int64 = 10_000
InvalidAddress string = "<invalid-address>"
VotingPeriod time.Duration = time.Second * 30
)

// ImmediatelyTimeout returns an ibc.IBCTimeout which will cause an IBC transfer to timeout immediately.
Expand Down

0 comments on commit b6dd724

Please sign in to comment.