Skip to content

Commit

Permalink
Merge pull request #217 from terra-money/main
Browse files Browse the repository at this point in the history
Merge 'main' into 'release/v0.2.x'
  • Loading branch information
javiersuweijie authored Jul 21, 2023
2 parents a1bc98f + 7ed42eb commit 4fbbb51
Show file tree
Hide file tree
Showing 40 changed files with 5,492 additions and 1,737 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: 1.20.0
- uses: actions/checkout@v3
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
version: v1.52.2
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ test-e2e:
test-benchmark:
@VERSION=$(VERSION) go test -v -mod=readonly -tags='ledger test_ledger_mock' github.com/terra-money/alliance/x/alliance/tests/benchmark

.PHONY: test test-unit test-e2e test-benchmark
test-simulate:
@VERSION=$(VERSION) go test -v -run=TestFullAppSimulation ./app -NumBlocks 200 -BlockSize 10 -Commit -Enabled -Period 1

.PHONY: test test-unit test-e2e test-benchmark test-simulate
###############################################################################
### Linting ###
###############################################################################
Expand All @@ -115,7 +118,7 @@ lint: format-tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" -not -path "*pb.gw.go" | xargs gofumpt -d

lint-docker:
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.52.2-alpine golangci-lint run
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.52.2-alpine golangci-lint run --timeout 10m

format: format-tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" -not -path "*pb.gw.go" | xargs gofumpt -w
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ Chains that want to add `x/alliance` must enable the following modules:
- [x/distribution](https://github.com/cosmos/cosmos-sdk/blob/main/x/distribution/README.md)
- [x/gov](https://github.com/cosmos/cosmos-sdk/blob/main/x/gov/README.md)

Compatibility matrix:

| Release | Branch | CosmosSDK |
|---------|----------------|-----------|
| v0.2.0 | release/v0.2.x | 0.47 |
| v0.1.0 | release/v0.1.x | 0.46 |

For an in-depth guide on integrating `x/alliance`, visit the [Alliance Module Integration Guide](https://alliance.terra.money/guides/get-started).

## Development environment
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func New(
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
authtypes.FeeCollectorName,
)

app.BankKeeper.RegisterKeepers(app.AllianceKeeper, app.StakingKeeper)
Expand Down
101 changes: 74 additions & 27 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,86 @@ import (
"os"
"testing"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"

"github.com/stretchr/testify/require"

"github.com/terra-money/alliance/app"
)

// SimAppChainID hardcoded chainID for simulation
const SimAppChainID = "simulation-app"
// Hardcoded chainID for simulation.
const (
simulationAppChainID = "simulation-app"
simulationDirPrefix = "leveldb-app-sim"
simulationDBName = "Simulation"
)

func init() {
simcli.GetSimulatorFlags()
}

type SimApp interface {
app.App
GetBaseApp() *baseapp.BaseApp
AppCodec() codec.Codec
SimulationManager() *module.SimulationManager
ModuleAccountAddrs() map[string]bool
Name() string
LegacyAmino() *codec.LegacyAmino
BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock
EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock
InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain
// Running as a go test:
//
// go test -v -run=TestFullAppSimulation ./app -NumBlocks 200 -BlockSize 10 -Commit -Enabled -Period 1
func TestFullAppSimulation(t *testing.T) {
config := simcli.NewConfigFromFlags()
config.ChainID = simulationAppChainID

if !simcli.FlagEnabledValue {
t.Skip("skipping application simulation")
}

db, dir, logger, _, err := simtestutil.SetupSimulation(
config,
simulationDirPrefix,
simulationDBName,
simcli.FlagVerboseValue,
true, // Don't use this as it is confusing
)
require.NoError(t, err, "simulation setup failed")

defer func() {
require.NoError(t, db.Close())
require.NoError(t, os.RemoveAll(dir))
}()

app := app.New(logger,
db,
nil,
true,
map[int64]bool{},
app.DefaultNodeHome,
simcli.FlagPeriodValue,
app.MakeTestEncodingConfig(),
simtestutil.EmptyAppOptions{},
baseapp.SetChainID(simulationAppChainID),
)

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
t,
os.Stdout,
app.BaseApp,
simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
simtypes.RandomAccounts,
simtestutil.SimulationOperations(app, app.AppCodec(), config),
app.BankKeeper.GetBlockedAddresses(),
config,
app.AppCodec(),
)

// export state and simParams before the simulatino error is checked
err = simtestutil.CheckExportSimulation(app, config, simParams)
require.NoError(t, err)
require.NoError(t, simErr)

if config.Commit {
simtestutil.PrintStats(db)
}
}

// BenchmarkSimulation run the chain simulation
Expand All @@ -61,8 +109,7 @@ func BenchmarkSimulation(b *testing.B) {

encoding := app.MakeTestEncodingConfig()

simApp := app.New(
logger,
app := app.New(logger,
db,
nil,
true,
Expand All @@ -77,17 +124,17 @@ func BenchmarkSimulation(b *testing.B) {
_, simParams, simErr := simulation.SimulateFromSeed(
b,
os.Stdout,
simApp.GetBaseApp(),
simtestutil.AppStateFn(simApp.AppCodec(), simApp.SimulationManager(), simApp.DefaultGenesis()),
simulationtypes.RandomAccounts,
simtestutil.SimulationOperations(simApp, simApp.AppCodec(), config),
simApp.ModuleAccountAddrs(),
app.GetBaseApp(),
simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
simtypes.RandomAccounts,
simtestutil.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
simApp.AppCodec(),
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = simtestutil.CheckExportSimulation(simApp, config, simParams)
err = simtestutil.CheckExportSimulation(app, config, simParams)
require.NoError(b, err)
require.NoError(b, simErr)

Expand Down
5 changes: 5 additions & 0 deletions custom/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewAppModule(cdc codec.Codec, keeper custombankkeeper.Keeper, accountKeeper
return AppModule{
AppModule: bankModule,
keeper: keeper,
subspace: ss,
}
}

Expand All @@ -46,4 +47,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
panic(fmt.Sprintf("failed to migrate x/bank from version 2 to 3: %v", err))
}

if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
panic(fmt.Sprintf("failed to migrate x/bank from version 3 to 4: %v", err))
}
}
Loading

0 comments on commit 4fbbb51

Please sign in to comment.