Skip to content

Commit

Permalink
imp: added feature
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed May 20, 2024
1 parent 7127eb7 commit 469a0f0
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 10 deletions.
11 changes: 10 additions & 1 deletion pkg/interchaintest/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/srdtrk/go-codegen/templates/interchaintestv8/chainconfig"
"github.com/srdtrk/go-codegen/templates/interchaintestv8/e2esuite"
"github.com/srdtrk/go-codegen/templates/interchaintestv8/github"
"github.com/srdtrk/go-codegen/templates/interchaintestv8/testvalues"
"github.com/srdtrk/go-codegen/templates/interchaintestv8/types"
)

Expand Down Expand Up @@ -53,7 +54,8 @@ func getInitGenerators(moduleName string, chainNum uint8, outDir string, githubA

// chain config generator
cg, err := chainconfig.NewGenerator(&chainconfig.Options{
ChainNum: chainNum,
ModulePath: moduleName,
ChainNum: chainNum,
})
if err != nil {
return nil, err
Expand All @@ -67,6 +69,13 @@ func getInitGenerators(moduleName string, chainNum uint8, outDir string, githubA
}
generators = append(generators, tg)

// testvalues generator
tvg, err := testvalues.NewGenerator(&testvalues.Options{})
if err != nil {
return nil, err
}
generators = append(generators, tvg)

return generators, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"bytes"
"encoding/json"
"fmt"
"time"

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"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/strangelove-ventures/interchaintest/v8/ibc"

"<%= ModulePath %>/testvalues"
)

func defaultModifyGenesis() func(ibc.ChainConfig, []byte) ([]byte, error) {
Expand Down Expand Up @@ -63,10 +64,8 @@ func modifyGovV1AppState(chainConfig ibc.ChainConfig, govAppState []byte) ([]byt
}

govGenesisState.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin(chainConfig.Denom, govv1.DefaultMinDepositTokens))
maxDep := time.Second * 10
govGenesisState.Params.MaxDepositPeriod = &maxDep
vp := time.Second * 30
govGenesisState.Params.VotingPeriod = &vp
govGenesisState.Params.MaxDepositPeriod = &testvalues.MaxDepositPeriod
govGenesisState.Params.VotingPeriod = &testvalues.VotingPeriod

// govGenBz := MustProtoMarshalJSON(govGenesisState)

Expand Down
10 changes: 9 additions & 1 deletion templates/interchaintestv8/chainconfig/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import (
"errors"

"github.com/gobuffalo/plush/v4"
"golang.org/x/mod/module"
)

type Options struct {
ChainNum uint8
ModulePath string
ChainNum uint8
}

// Validate that options are usable.
func (opts *Options) Validate() error {
err := module.CheckPath(opts.ModulePath)
if err != nil {
return err
}

if opts.ChainNum == 0 {
return errors.New("ChainNum must be greater than 0")
}
Expand All @@ -20,6 +27,7 @@ func (opts *Options) Validate() error {

func (opts *Options) plushContext() *plush.Context {
ctx := plush.NewContext()
ctx.Set("ModulePath", opts.ModulePath)
ctx.Set("ChainNum", int(opts.ChainNum))
ctx.Set("between", betweenHelper)
return ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

sdkmath "cosmossdk.io/math"
<%= if (ChainNum > 1) { %>
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"

interchaintest "github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
Expand All @@ -22,6 +24,7 @@ import (
"github.com/strangelove-ventures/interchaintest/v8/ibc"
<% } %>
"<%= ModulePath %>/chainconfig"
"<%= ModulePath %>/testvalues"
)

// TestSuite is a suite of tests that require two chains and a relayer
Expand Down Expand Up @@ -104,7 +107,7 @@ func (s *TestSuite) SetupSuite(ctx context.Context) {
<%= for (n) in between(0, ChainNum) { %> s.Require().NoError(populateQueryReqToPath(ctx, s.Chain<%= numToLetter(n) %>))
<% } %>
// Fund a user accounts
userFunds := sdkmath.NewInt(10_000_000_000)
userFunds := sdkmath.NewInt(testvalues.StartingTokenAmount)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds<%= for (n) in between(0, ChainNum) { return ", s.Chain" + numToLetter(n) } %>)
<%= for (n) in between(0, ChainNum) { %> s.User<%= numToLetter(n) %> = users[<%= n %>]
<% } %><%= if (ChainNum > 1) { %>
Expand Down Expand Up @@ -132,15 +135,15 @@ func (s *TestSuite) SetupSuite(ctx context.Context) {
// localhost is always a connection since ibc-go v7.1+
s.Require().Equal(2, len(connections))
wasmdConnection := connections[0]
s.Require().NotEqual("connection-localhost", wasmdConnection.ID)
s.Require().NotEqual(ibcexported.LocalhostConnectionID, wasmdConnection.ID)

// Query for the newly created connection in simd
connections, err = s.Relayer.GetConnections(ctx, s.ExecRep, s.ChainB.Config().ChainID)
s.Require().NoError(err)
// localhost is always a connection since ibc-go v7.1+
s.Require().Equal(2, len(connections))
simdConnection := connections[0]
s.Require().NotEqual("connection-localhost", simdConnection.ID)
s.Require().NotEqual(ibcexported.LocalhostConnectionID, simdConnection.ID)

// Start the relayer and set the cleanup function.
err = s.Relayer.StartRelayer(ctx, s.ExecRep, s.PathName)
Expand Down
37 changes: 37 additions & 0 deletions templates/interchaintestv8/testvalues/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package testvalues

import (
"embed"
"fmt"
"io/fs"

"github.com/gobuffalo/genny/v2"

"github.com/srdtrk/go-codegen/pkg/xgenny"
)

//go:embed files/* files/**/*
var files embed.FS

func NewGenerator(opts *Options) (*genny.Generator, error) {
if err := opts.Validate(); err != nil {
return nil, fmt.Errorf("invalid options: %w", err)
}

// Remove "files/" prefix
subfs, err := fs.Sub(files, "files")
if err != nil {
return nil, fmt.Errorf("generator sub: %w", err)
}

g := genny.New()

err = g.SelectiveFS(subfs, nil, nil, nil, nil)
if err != nil {
return nil, fmt.Errorf("generator selective fs: %w", err)
}

g.Transformer(xgenny.Transformer(opts.plushContext()))

return g, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testvalues

import "time"

const (
// StartingTokenAmount is the amount of tokens to give to each user at the start of the test.
StartingTokenAmount int64 = 10_000_000_000
)

var (
// Maximum period to deposit on a proposal.
// This value overrides the default value in the gov module using the `modifyGovV1AppState` function.
MaxDepositPeriod = time.Second * 10
// Duration of the voting period.
// This value overrides the default value in the gov module using the `modifyGovV1AppState` function.
VotingPeriod = time.Second * 30
)
15 changes: 15 additions & 0 deletions templates/interchaintestv8/testvalues/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testvalues

import "github.com/gobuffalo/plush/v4"

type Options struct{}

// Validate that options are usable.
func (opts *Options) Validate() error {

Check warning on line 8 in templates/interchaintestv8/testvalues/options.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-receiver: method receiver 'opts' is not referenced in method's body, consider removing or renaming it as _ (revive)
return nil
}

func (opts *Options) plushContext() *plush.Context {

Check warning on line 12 in templates/interchaintestv8/testvalues/options.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-receiver: method receiver 'opts' is not referenced in method's body, consider removing or renaming it as _ (revive)
ctx := plush.NewContext()
return ctx
}

0 comments on commit 469a0f0

Please sign in to comment.