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

Update the disabled alliance #1

Open
wants to merge 101 commits into
base: disable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
3742bab
Merge pull request #181 from terra-money/fix/query/special/chars
emidev98 May 4, 2023
ff70e05
fix: simulation redelegate to same validator
emidev98 May 4, 2023
663e3c7
Merge pull request #184 from terra-money/fix/simulation
emidev98 May 5, 2023
5beb406
Merge pull request #187 from terra-money/fix/simulation
emidev98 May 5, 2023
7d0e92d
fix: wording
emidev98 May 5, 2023
7b3b0fb
chore: compatibility matrix
emidev98 May 5, 2023
7181ba4
Merge branch 'main' into fix/wording
emidev98 May 5, 2023
8f42ab3
Merge pull request #190 from terra-money/fix/wording
emidev98 May 5, 2023
d0926fb
bumps for cosmos eco libs
faddat May 7, 2023
655c168
Merge remote-tracking branch 'origin/main' into bump-ecosystem-libs
faddat May 7, 2023
849c7b0
Merge pull request #191 from faddat/bump-ecosystem-libs
javiersuweijie May 11, 2023
518c8a6
chore(deps): bump github.com/spf13/cast from 1.5.0 to 1.5.1
dependabot[bot] May 16, 2023
8a68cbb
feat: buf registry
emidev98 May 16, 2023
4c326b2
Merge pull request #196 from terra-money/feat/buf
javiersuweijie May 19, 2023
0df1b7a
feat: benchmark from 1000 blocks to 200
emidev98 May 22, 2023
455f247
feat: simulation
emidev98 May 22, 2023
f94fefb
Merge pull request #198 from terra-money/feat/benchmark
javiersuweijie May 23, 2023
42a0d81
chore(deps): bump cosmossdk.io/math from 1.0.0 to 1.0.1
dependabot[bot] May 23, 2023
9f8bf58
chore(deps): bump github.com/stretchr/testify from 1.8.2 to 1.8.3
dependabot[bot] May 23, 2023
b8454bb
update: deps for cosmos 47
javiersuweijie May 23, 2023
6fc4453
Merge pull request #199 from terra-money/update/deps-for-47
javiersuweijie May 23, 2023
ecd7f3a
Merge pull request #195 from terra-money/dependabot/go_modules/cosmos…
javiersuweijie May 23, 2023
53b927a
Merge pull request #194 from terra-money/dependabot/go_modules/github…
javiersuweijie May 23, 2023
adea6ab
Merge pull request #197 from terra-money/dependabot/go_modules/github…
javiersuweijie May 23, 2023
bcc3391
chore(deps): bump github.com/cosmos/ibc-go/v7 from 7.0.0 to 7.0.1
dependabot[bot] May 26, 2023
15bdc30
feat: rosetta v1
emidev98 May 29, 2023
87dbce1
Merge pull request #201 from terra-money/dependabot/go_modules/github…
emidev98 May 29, 2023
ac28065
chore(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4
dependabot[bot] May 31, 2023
1bb70c9
Merge pull request #203 from terra-money/dependabot/go_modules/github…
emidev98 Jun 1, 2023
9bb3863
chore(deps): bump github.com/spf13/viper from 1.15.0 to 1.16.0
dependabot[bot] Jun 1, 2023
9a28ea0
Merge pull request #204 from terra-money/dependabot/go_modules/github…
emidev98 Jun 1, 2023
6d5aed1
wip: query unbonding
emidev98 Jun 1, 2023
faa7702
feat: query unbonding completion time
emidev98 Jun 2, 2023
763b03b
feat: query unbondings
emidev98 Jun 2, 2023
df78424
fix: query linting
emidev98 Jun 5, 2023
63f15fc
feat: query redelegations
emidev98 Jun 5, 2023
30eaad0
fix: dependencies conflict
emidev98 Jun 8, 2023
a0e6360
fix: bank migration v3 to v4
emidev98 Jun 8, 2023
dcd829e
fix: lint version
emidev98 Jun 8, 2023
9a534b7
Merge pull request #210 from terra-money/fix/lint
emidev98 Jun 8, 2023
ea471c0
Merge branch 'main' of https://github.com/terra-money/alliance into f…
emidev98 Jun 8, 2023
d10b084
Merge branch 'main' of https://github.com/terra-money/alliance into f…
emidev98 Jun 8, 2023
f8561b9
Merge branch 'main' of https://github.com/terra-money/alliance into f…
emidev98 Jun 8, 2023
cffe1b1
Merge branch 'main' of https://github.com/terra-money/alliance into f…
emidev98 Jun 8, 2023
44535b1
Merge pull request #209 from terra-money/fix/migration
emidev98 Jun 8, 2023
66353ed
fix: bank module subspace migration
emidev98 Jun 8, 2023
26bc514
Merge pull request #211 from terra-money/fix/subspace/migration
javiersuweijie Jun 8, 2023
4843189
use real v0.47.3
faddat Jun 9, 2023
506375f
Merge pull request #202 from terra-money/feat/rosetta/v1
emidev98 Jun 12, 2023
2b0acfc
chore(deps): bump github.com/cosmos/ibc-go/v7 from 7.0.1 to 7.1.0
dependabot[bot] Jun 12, 2023
64e1390
Merge pull request #215 from terra-money/dependabot/go_modules/github…
javiersuweijie Jun 12, 2023
a752e55
Merge branch 'main' of https://github.com/terra-money/alliance into HEAD
emidev98 Jun 12, 2023
1ea07c6
Merge branch 'main' of https://github.com/terra-money/alliance into f…
emidev98 Jun 12, 2023
feaffd8
feat: paginated redelegations
emidev98 Jun 12, 2023
8a1984b
Merge pull request #216 from terra-money/feat/sdk/ibc
emidev98 Jun 12, 2023
c069185
Merge branch 'main' of https://github.com/terra-money/alliance into f…
emidev98 Jun 12, 2023
24b831c
Merge pull request #208 from terra-money/feat/query/redelegations
emidev98 Jun 12, 2023
f199f6f
feat: update proto
emidev98 Jun 12, 2023
d08cd0c
Merge pull request #206 from terra-money/feat/query/unbonding
emidev98 Jun 12, 2023
f2832ad
chore(deps): bump github.com/cosmos/cosmos-sdk from 0.47.2 to 0.47.3
dependabot[bot] Jun 13, 2023
27de5a5
feat: add support for user-provided fee collector module account
madrezaz Jun 27, 2023
512439b
Merge pull request #218 from terra-money/dependabot/go_modules/github…
emidev98 Jun 28, 2023
870de40
chore(deps): bump github.com/cometbft/cometbft from 0.37.1 to 0.37.2
dependabot[bot] Jun 28, 2023
16f8f5b
Merge pull request #226 from prism-finance/feat-fee-collector-account
emidev98 Jun 29, 2023
25cca86
feat: emit event on asset take rate deduction
madrezaz Jun 28, 2023
16b6591
Merge pull request #219 from terra-money/dependabot/go_modules/github…
emidev98 Jul 11, 2023
7ed42eb
Merge pull request #228 from prism-finance/feat-deduct-asset-event
emidev98 Jul 12, 2023
1cdf4e3
fix: remove validator info after hook
javiersuweijie Jul 21, 2023
4fbbb51
Merge pull request #217 from terra-money/main
javiersuweijie Jul 21, 2023
68edf39
feat: publish new version of buf
emidev98 Aug 18, 2023
1d34f63
Merge pull request #236 from terra-money/feat/buf
emidev98 Aug 21, 2023
73058d5
Merge branch 'release/v0.2.x' of https://github.com/terra-money/allia…
emidev98 Sep 4, 2023
346a3dd
feat: migrate params to alliance store
javiersuweijie Sep 7, 2023
608ab07
feat: add new gov-only msg for updating params
javiersuweijie Sep 7, 2023
1a3bb43
Update x/alliance/types/msg.go
javiersuweijie Sep 7, 2023
17139c9
chore: pushed latest to buf registry
javiersuweijie Sep 7, 2023
d2cd78d
Merge branch 'upgrade/v0.3.0' of github.com:terra-money/alliance into…
javiersuweijie Sep 7, 2023
46382cd
fix: merge errors
javiersuweijie Sep 7, 2023
cc98486
feat: migrate gov proposal away from legacy
javiersuweijie Sep 7, 2023
193de62
chore: gofumpt
emidev98 Sep 7, 2023
7a483b7
feat: added authority validation
javiersuweijie Sep 8, 2023
6d0d747
Merge branch 'upgrade/v0.3.0' of github.com:terra-money/alliance into…
javiersuweijie Sep 8, 2023
c530e8f
update: buf registry
javiersuweijie Sep 8, 2023
2ff54b7
fix: authority for gov msgs
emidev98 Sep 8, 2023
d67aaaa
Merge pull request #245 from terra-money/upgrade/v0.3.0
javiersuweijie Sep 8, 2023
0be00a9
Merge pull request #250 from terra-money/fix/delete-validator-0.2.x
javiersuweijie Sep 8, 2023
1b675c8
fix: upgrade v0.3.0
emidev98 Sep 14, 2023
1d2086d
Merge pull request #256 from terra-money/fix/upgrade/v0.3.0
emidev98 Sep 14, 2023
cfdb968
Update README.md
evanorti Sep 29, 2023
d5f162c
fix: app genesis creation
emidev98 Oct 11, 2023
807ce1e
fix: linting
emidev98 Oct 16, 2023
6d302c2
Merge pull request #265 from terra-money/fix/v0.3.x/app
emidev98 Oct 16, 2023
5c1938d
Merge pull request #262 from terra-money/evanorti-patch-1
emidev98 Oct 23, 2023
9bf0147
fix: updated links
javiersuweijie Jul 25, 2023
8230d62
Add codecommit.yml
Aug 24, 2023
09b3635
Add codecommit.yml
Aug 25, 2023
6d5f18a
Add codecommit.yml
Aug 29, 2023
779e0cd
feat: allow updating of weight range
javiersuweijie Nov 9, 2023
5b8534e
fix: test
javiersuweijie Nov 10, 2023
8439e9f
Merge pull request #277 from terra-money/feat/update-weight-ranges
emidev98 Nov 13, 2023
28e475d
Merge remote-tracking branch 'origin/release/v0.3.x' into HEAD
faddat Dec 27, 2023
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
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
11 changes: 9 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 All @@ -131,6 +134,10 @@ proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(PROTO_BUILDER_IMAGE) sh ./scripts/protocgen.sh

buf-push:
@echo "Pushing protobuf files to buf registry"
cd proto && buf push

###############################################################################
### Local Testnet (docker) ###
###############################################################################
Expand Down
54 changes: 30 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
<h1 align="center"> 🤝 Alliance</h1>

<p align="center">
<a href="https://alliance.terra.money/">Technical Documentation</a>
<a href="https://docs.alliance.terra.money/">Technical Documentation</a>
·
<a href="https://alliance.terra.money/guides/get-started">Integration Guide</a>
<a href="https://docs.alliance.terra.money/guides/get-started">Integration Guide</a>
·
<a href="https://alliance.terra.money/alliance-audit.pdf">Code Audit</a>

<a href="https://github.com/terra-money/alliance/blob/main/audit/alliance-audit-v1.0.pdf">Code Audit</a>
</p>

<br/>
Expand All @@ -20,35 +19,35 @@ Alliance is an open-source Cosmos SDK module that leverages interchain staking t

### Here’s how it works:

- Two chains [integrate the Alliance module](https://alliance.terra.money/guides/get-started) and decide through governance which assets can be staked on their chain. These are known as [Alliance assets](https://alliance.terra.money/alliance#what-are-alliance-assets).
- Each Alliance asset is assigned a [Take Rate](https://alliance.terra.money/alliance#the-take-rate) (the percentage of staked Alliance assets the chain redistributes to native chain stakers) and a [Reward Weight](https://alliance.terra.money/alliance#rewards) (the percentage of native staking rewards the chain distributes to Alliance asset stakers).
- Users of each chain can then [bridge their assets via IBC](https://alliance.terra.money/alliance#what-are-alliance-assets) to the other chain and stake them to earn the Reward Weight.
- Two chains [integrate the Alliance module](https://docs.alliance.terra.money/guides/get-started) and decide through governance which assets can be staked on their chain. These are known as [Alliance assets](https://docs.alliance.terra.money/alliance#what-are-alliance-assets).
- Each Alliance asset is assigned a [Take Rate](https://docs.alliance.terra.money/alliance#the-take-rate) (the percentage of staked Alliance assets the chain redistributes to native chain stakers) and a [Reward Weight](https://docs.alliance.terra.money/alliance#rewards) (the percentage of native staking rewards the chain distributes to Alliance asset stakers).
- Users of each chain can then [bridge their assets via IBC](https://docs.alliance.terra.money/alliance#what-are-alliance-assets) to the other chain and stake them to earn the Reward Weight.

## Tech Specs

[The Alliance Docs](https://alliance.terra.money/) contain detailed information about Alliance. Familiarize yourself with the following concepts before integrating the Alliance module.
[The Alliance Docs](https://docs.alliance.terra.money/) contain detailed information about Alliance. Familiarize yourself with the following concepts before integrating the Alliance module.

- About Alliance
- [Overview](https://alliance.terra.money/overview)
- [How Alliance works](https://alliance.terra.money/alliance)
- [Alliance staking](https://alliance.terra.money/concepts/staking)
- [Reward distribution](https://alliance.terra.money/concepts/rewards)
- [Validator shares](https://alliance.terra.money/concepts/delegation)
- [Overview](https://docs.alliance.terra.money/overview)
- [How Alliance works](https://docs.alliance.terra.money/alliance)
- [Alliance staking](https://docs.alliance.terra.money/concepts/staking)
- [Reward distribution](https://docs.alliance.terra.money/concepts/rewards)
- [Validator shares](https://docs.alliance.terra.money/concepts/delegation)
- Guides
- [Integrate the Alliance module](https://alliance.terra.money/guides/get-started)
- [Create, update, or delete an Alliance](https://alliance.terra.money/guides/create)
- [Interact with an Alliance](https://alliance.terra.money/guides/how-to)
- [Integrate the Alliance module](https://docs.alliance.terra.money/guides/get-started)
- [Create, update, or delete an Alliance](https://docs.alliance.terra.money/guides/create)
- [Interact with an Alliance](https://docs.alliance.terra.money/guides/how-to)
- Technical specifications:
- [Module parameters](https://alliance.terra.money/tech/parameters) and [Alliance asset properties](https://alliance.terra.money/tech/asset)
- [Txs and queries](https://alliance.terra.money/tech/tx-queries)
- [Data structures](https://alliance.terra.money/tech/data)
- [State transitions](https://alliance.terra.money/tech/transitions)
- [Invariants](https://alliance.terra.money/tech/invariants)
- [Benchmarks](https://alliance.terra.money/tech/benchmarks)
- [Module parameters](https://docs.alliance.terra.money/tech/parameters) and [Alliance asset properties](https://alliance.terra.money/tech/asset)
- [Txs and queries](https://docs.alliance.terra.money/tech/tx-queries)
- [Data structures](https://docs.alliance.terra.money/tech/data)
- [State transitions](https://docs.alliance.terra.money/tech/transitions)
- [Invariants](https://docs.alliance.terra.money/tech/invariants)
- [Benchmarks](https://docs.alliance.terra.money/tech/benchmarks)

## Integrate the `x/alliance` module

The Alliance module can be [added to any compatible Cosmos chain](https://alliance.terra.money/guides/get-started) and does not require any changes to consensus or major changes to common core modules. This module wraps around a chain’s native staking module, allowing whitelisted assets to be staked and earn rewards. Alliance assets can be staked with the Alliance module, and the chain's native staking module is used for native stakers.
The Alliance module can be [added to any compatible Cosmos chain](https://docs.alliance.terra.money/guides/get-started) and does not require any changes to consensus or major changes to common core modules. This module wraps around a chain’s native staking module, allowing whitelisted assets to be staked and earn rewards. Alliance assets can be staked with the Alliance module, and the chain's native staking module is used for native stakers.

Chains that want to add `x/alliance` must enable the following modules:

Expand All @@ -59,7 +58,14 @@ 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)

For an in-depth guide on integrating `x/alliance`, visit the [Alliance Module Integration Guide](https://alliance.terra.money/guides/get-started).
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://docs.alliance.terra.money/guides/get-started).

## Development environment

Expand Down
27 changes: 15 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ var (
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
authzmodule.AppModuleBasic{},
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
Expand Down Expand Up @@ -436,11 +436,12 @@ func New(
app.AllianceKeeper = alliancemodulekeeper.NewKeeper(
appCodec,
keys[alliancemoduletypes.StoreKey],
app.GetSubspace(alliancemoduletypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.BankKeeper.RegisterKeepers(app.AllianceKeeper, app.StakingKeeper)
Expand Down Expand Up @@ -573,7 +574,7 @@ func New(
params.NewAppModule(app.ParamsKeeper),
transferModule,
icaModule,
alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancemoduletypes.ModuleName)),
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand Down Expand Up @@ -880,21 +881,23 @@ func GetMaccPerms() map[string][]string {
}

// initParamsKeeper init params keeper and its subspaces
//
//nolint:staticcheck // ParamsKeyTable is deprecated but used here for migration
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable())
paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable())
paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable())
paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable())
paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable())
paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable())
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(alliancemoduletypes.ModuleName)
paramsKeeper.Subspace(alliancemoduletypes.ModuleName).WithKeyTable(alliancemoduletypes.ParamKeyTable())
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
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
Binary file added audit/alliance-audit-v1.0.pdf
Binary file not shown.
Loading
Loading