Skip to content

Commit

Permalink
refactor: refactored the claim module (#42)
Browse files Browse the repository at this point in the history
* feat: add claim module

* chore: fix the lint issue

* fix: fix the proto issues

1. Change the proto generation with buf
2. Change the `proto-lint` in `Makefile`

* trying to fix proto breaking ci cd

* trying to fix proto breaking ci cd

* trying to fix proto breaking ci cd

* trying to fix proto breaking ci cd

* trying to fix proto breaking ci cd

* trying to fix proto breaking ci cd

* trying to fix proto breaking ci cd

* fix: fix the app testing

* chore: add claim module account on initGenesis time

* chore: address the pr comments

* feat: add claim_records to claim module

1. Add claim records
2. Add claim module params
3. Add claim module keeper functions for airdrop
4. Add grpc_query and cli query for claim module of claim records

* chore: removed `Actions` from proto enum

1. Removed airdrop actions enum
2. Add airdrop actions as a enum in types

* chore: fix the `swagger` api doc route

* chore: try to fix upload test coverage report

* test: added genesis test for claim module

* chore: remove burner, staking permission for claim module

* test: add cli and grpc tests for claim module

* fix: fix the test coverage upload

* feat: add claim module actions and txns

* fix: fix the build issue

* test: fix the test issue

* feat: add antehandler

1. skip the tx fee checking for MsgClaim transactions

* fix: fix the staking hooks for airdrop

* feat: add airdrop for proposal vote

* fix: fix the gov hooks

* fix gomod

* refactor: refactored the claim module

1. add only initial_claim action to get all claim amount

* chore: removed ante handlers

* chore: removed ante handlers test and fee

Co-authored-by: anilCSE <[email protected]>
  • Loading branch information
gsk967 and anilcse authored Jul 6, 2022
1 parent 82c7206 commit 84cc2f9
Show file tree
Hide file tree
Showing 63 changed files with 7,937 additions and 108 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
timeout-minutes: 6
steps:
- uses: actions/checkout@v3
- uses: technote-space/[email protected]
Expand All @@ -20,9 +19,10 @@ jobs:
**/**.go
go.mod
go.sum
- uses: golangci/golangci-lint-action@master
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.28
args: --timeout 10m
github-token: ${{ secrets.github_token }}
version: latest
args: --out-format=tab
skip-go-installation: true
if: env.GIT_DIFF
2 changes: 1 addition & 1 deletion .github/workflows/proto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: check-breakage
run: make proto-check-breaking
run: make proto-check-breaking
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
**/**.go
go.mod
go.sum
- name: run tests and generate coverage
run: make test-cover
- name: run all tests and generate coverage
run: go test -v -mod=readonly -timeout 30m -coverprofile=coverage.txt -tags='norace' -covermode=atomic `go list ./... | grep -v simapp`
if: env.GIT_DIFF
- name: Upload codecov report
uses: codecov/[email protected]
Expand Down
24 changes: 13 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
run:
tests: false
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

linters:
disable-all: true
Expand All @@ -11,30 +11,27 @@ linters:
- depguard
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- maligned
- misspell
- nakedret
- nolintlint
- prealloc
- scopelint
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- unparam
- misspell
# - wsl
- nolintlint
- unused

issues:
exclude-rules:
Expand All @@ -55,9 +52,14 @@ issues:
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
Expand All @@ -68,4 +70,4 @@ linters-settings:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
require-specific: false
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ APP = ./passage
MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/envadiv/Passage3D.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8

export GO111MODULE = on

Expand Down Expand Up @@ -384,9 +384,11 @@ devdoc-update:

containerProtoVer=v0.2
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer)
containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer)
containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer)
containerProtoGen=passage3d-proto-gen-$(containerProtoVer)
containerProtoGenSwagger=passage3d-proto-gen-swagger-$(containerProtoVer)
containerProtoFmt=passage3d-proto-fmt-$(containerProtoVer)
containerProtoLint=passage3d-proto-lint-$(containerProtoVer)
containerProtoBreaking=passage3d-proto-break-$(containerProtoVer)

proto-all: proto-format proto-lint proto-gen

Expand All @@ -412,10 +414,14 @@ proto-format:


proto-lint:
@$(DOCKER_BUF) lint --error-format=json
@echo "Checking Proto-Lint"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoLint}$$"; then docker start -a $(containerProtoLint); else docker run --name $(containerProtoLint) -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8 \
lint --error-format=json ; fi

proto-check-breaking:
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=master
@echo "Checking Proto Breaking "
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoBreaking}$$"; then docker start -a $(containerProtoBreaking); else docker run --name $(containerProtoBreaking) -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8 \
breaking --against $(HTTPS_GIT)#branch=main ; fi


TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.0-rc6/proto/tendermint
Expand Down
7 changes: 5 additions & 2 deletions app/addr_prefixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
)
Expand All @@ -23,6 +22,10 @@ const (
)

func init() {
SetAddressPrefixes()
}

func SetAddressPrefixes() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
Expand All @@ -34,5 +37,5 @@ func init() {
}
return fmt.Errorf("unexpected address length %d", n)
})
config.Seal()
//config.Seal()
}
26 changes: 23 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"os"
"path/filepath"

appparams "github.com/envadiv/Passage3D/app/params"

"github.com/envadiv/Passage3D/x/claim"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand All @@ -25,7 +29,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -92,6 +95,9 @@ import (
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"

claimkeeper "github.com/envadiv/Passage3D/x/claim/keeper"
claimtypes "github.com/envadiv/Passage3D/x/claim/types"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)
Expand Down Expand Up @@ -126,6 +132,9 @@ var (
vesting.AppModuleBasic{},
ibc.AppModuleBasic{},
transfer.AppModuleBasic{}, // i.e ibc-transfer module

// passage3d claim module
claim.AppModuleBasic{},
)

// module account permissions
Expand All @@ -137,6 +146,7 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
claimtypes.ModuleName: {authtypes.Minter},
}
)

Expand Down Expand Up @@ -184,6 +194,8 @@ type PassageApp struct {
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper

ClaimKeeper claimkeeper.Keeper

// the module manager
mm *module.Manager

Expand All @@ -206,7 +218,7 @@ func init() {
// NewPassageApp returns a reference to an initialized PassageApp.
func NewPassageApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
) *PassageApp {

Expand All @@ -224,7 +236,7 @@ func NewPassageApp(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey,
authzkeeper.StoreKey, claimtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
Expand Down Expand Up @@ -285,6 +297,9 @@ func NewPassageApp(
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)

// airdorp module keeper
app.ClaimKeeper = claimkeeper.NewKeeper(appCodec, keys[claimtypes.StoreKey], app.AccountKeeper, app.BankKeeper, &stakingKeeper, app.DistrKeeper, app.GetSubspace(claimtypes.ModuleName))

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -377,6 +392,7 @@ func NewPassageApp(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
claim.NewAppModule(appCodec, app.ClaimKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -401,6 +417,7 @@ func NewPassageApp(
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
claimtypes.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
)
Expand All @@ -420,6 +437,7 @@ func NewPassageApp(
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
claimtypes.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
Expand Down Expand Up @@ -449,6 +467,7 @@ func NewPassageApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
claimtypes.ModuleName,
)

// Uncomment if you want to set a custom migration order here.
Expand Down Expand Up @@ -685,6 +704,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(claimtypes.ModuleName)

return paramsKeeper
}
10 changes: 6 additions & 4 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"
"github.com/envadiv/Passage3D/x/claim"
"os"
"testing"

Expand Down Expand Up @@ -38,7 +39,7 @@ import (
)

func TestSimAppExportAndBlockedAddrs(t *testing.T) {
encCfg := MakeTestEncodingConfig()
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
app := NewPassageApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})

Expand Down Expand Up @@ -76,7 +77,7 @@ func TestGetMaccPerms(t *testing.T) {

func TestRunMigrations(t *testing.T) {
db := dbm.NewMemDB()
encCfg := MakeTestEncodingConfig()
encCfg := MakeEncodingConfig()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})

Expand Down Expand Up @@ -186,6 +187,7 @@ func TestRunMigrations(t *testing.T) {
"capability": capability.AppModule{}.ConsensusVersion(),
"ibc": ibc.AppModule{}.ConsensusVersion(),
"transfer": transfer.AppModule{}.ConsensusVersion(),
"claim": claim.AppModule{}.ConsensusVersion(),
},
)
if tc.expRunErr {
Expand All @@ -201,7 +203,7 @@ func TestRunMigrations(t *testing.T) {

func TestInitGenesisOnMigration(t *testing.T) {
db := dbm.NewMemDB()
encCfg := MakeTestEncodingConfig()
encCfg := MakeEncodingConfig()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
Expand Down Expand Up @@ -244,7 +246,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
}

func TestUpgradeStateOnGenesis(t *testing.T) {
encCfg := MakeTestEncodingConfig()
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
app := NewPassageApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
genesisState := NewDefaultGenesisState(encCfg.Marshaler)
Expand Down
11 changes: 4 additions & 7 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package app

import (
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/std"
"github.com/envadiv/Passage3D/app/params"
)

// MakeTestEncodingConfig creates an EncodingConfig for testing. This function
// should be used only in tests or when creating a new app instance (NewApp*()).
// App user shouldn't create new codecs - use the app.AppCodec instead.
// [DEPRECATED]
func MakeTestEncodingConfig() simappparams.EncodingConfig {
encodingConfig := simappparams.MakeTestEncodingConfig()
// MakeEncodingConfig creates an EncodingConfig for testing.
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
Expand Down
7 changes: 3 additions & 4 deletions app/params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
// NOTE: this field will be renamed to Codec
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
Loading

0 comments on commit 84cc2f9

Please sign in to comment.