Skip to content

Commit

Permalink
feats: init payment module (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-reorg authored Feb 9, 2023
1 parent db6cdff commit 569f459
Show file tree
Hide file tree
Showing 149 changed files with 26,270 additions and 163 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/buf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Protobuf files lint and backwards compatibility check job
# reference: <https://docs.buf.build/ci-cd/github-actions>
name: protobuf-check

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
protobuf-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: bufbuild/buf-setup-action@v1
- run: buf format --diff --exit-code
54 changes: 54 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: End to End Test

on:
push:
branches:
- master
- develop

pull_request:
branches:
- master
- develop

jobs:
end-to-end-test:
strategy:
matrix:
go-version: [1.18.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
GOPRIVATE: github.com/bnb-chain
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_SECRET }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup GitHub Token
run: git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/
- name: Build
run: |
make build
- name: run local chain
run: bash ./deployment/localup/localup.sh all 1
- name: run cli test
run: bash ./e2e/cli_test.sh
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ release/
.idea/
.vscode/
.DS_Store
spec/
Taskfile.yaml
build/
vendor/
.local
.local
.task
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: build build-linux build-macos build-windows
.PHONY: tools proto test
.PHONY: tools proto-gen proto-format test

VERSION=$(shell git describe --tags)
VERSION=$(shell git describe --tags --always)
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_COMMIT_DATE=$(shell git log -n1 --pretty='format:%cd' --date=format:'%Y%m%d')
REPO=github.com/bnb-chain/greenfield
Expand All @@ -15,15 +15,18 @@ ldflags = -X $(REPO)/version.AppVersion=$(VERSION) \
tools:
curl https://get.ignite.com/cli! | bash

proto:
ignite generate proto-go
proto-gen:
cd proto && buf generate && cp -r github.com/bnb-chain/greenfield/x/* ../x && rm -rf github.com

build:
go build -o build/bin/gnfd -ldflags="$(ldflags)" ./cmd/gnfd/main.go
proto-format:
buf format -w

build:
CGO_CFLAGS="-O -D__BLST_PORTABLE__" CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__" go build -o build/bin/gnfd -ldflags="$(ldflags)" ./cmd/gnfd/main.go

docker-image:
go mod vendor # temporary, should be removed after open source
docker build . -t ${IMAGE_NAME}

test:
go test ./...
go test ./...
27 changes: 14 additions & 13 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,20 @@ func (suite *AnteTestSuite) TestAnteHandler() {
return txBuilder.GetTx()
}, false, false, true,
},
{
"fails- DeliverTx MsgSubmitProposal v1beta",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
gasAmount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
// reusing the gasAmount for deposit
deposit := sdk.NewCoins(coinAmount)
txBuilder := suite.CreateTestEIP712SubmitProposal(from, privKey, "greenfield_9000-1", gas, gasAmount, deposit)
return txBuilder.GetTx()
}, false, false, false,
},
// todo: fix this test after refactoring the gashub module
//{
// "fails- DeliverTx MsgSubmitProposal v1beta",
// func() sdk.Tx {
// from := acc.GetAddress()
// coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
// gasAmount := sdk.NewCoins(coinAmount)
// gas := uint64(200000)
// // reusing the gasAmount for deposit
// deposit := sdk.NewCoins(coinAmount)
// txBuilder := suite.CreateTestEIP712SubmitProposal(from, privKey, "greenfield_9000-1", gas, gasAmount, deposit)
// return txBuilder.GetTx()
// }, false, false, false,
//},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with wrong Chain ID",
func() sdk.Tx {
Expand Down
34 changes: 31 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ import (
spmodulekeeper "github.com/bnb-chain/greenfield/x/sp/keeper"
spmoduletypes "github.com/bnb-chain/greenfield/x/sp/types"
// this line is used by starport scaffolding # stargate/app/moduleImport

paymentmodule "github.com/bnb-chain/greenfield/x/payment"
paymentmodulekeeper "github.com/bnb-chain/greenfield/x/payment/keeper"
paymentmoduletypes "github.com/bnb-chain/greenfield/x/payment/types"
// this line is used by starport scaffolding # stargate/app/moduleImport
)

const (
Name = "greenfield"
ShortName = "gnfd"
EIP155ChainID = "9000"
Epoch = "1"

Expand Down Expand Up @@ -150,6 +156,7 @@ var (
bridgemodule.AppModuleBasic{},
gashub.AppModuleBasic{},
spmodule.AppModuleBasic{},
paymentmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -160,6 +167,8 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
paymentmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
crosschaintypes.ModuleName: {authtypes.Minter},
bridgemoduletypes.ModuleName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
Expand All @@ -178,7 +187,7 @@ func init() {
panic(err)
}

DefaultNodeHome = filepath.Join(userHomeDir, "."+Name)
DefaultNodeHome = filepath.Join(userHomeDir, "."+ShortName)
}

// App extends an ABCI application, but with most of its parameters exported.
Expand Down Expand Up @@ -215,8 +224,9 @@ type App struct {

GreenfieldKeeper greenfieldmodulekeeper.Keeper

BridgeKeeper bridgemodulekeeper.Keeper
SpKeeper spmodulekeeper.Keeper
BridgeKeeper bridgemodulekeeper.Keeper
SpKeeper spmodulekeeper.Keeper
PaymentKeeper paymentmodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down Expand Up @@ -271,6 +281,7 @@ func New(
bridgemoduletypes.StoreKey,
gashubtypes.StoreKey,
spmoduletypes.StoreKey,
paymentmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -447,6 +458,17 @@ func New(
)
spModule := spmodule.NewAppModule(appCodec, app.SpKeeper, app.AccountKeeper, app.BankKeeper)

app.PaymentKeeper = *paymentmodulekeeper.NewKeeper(
appCodec,
keys[paymentmoduletypes.StoreKey],
keys[paymentmoduletypes.MemStoreKey],
app.GetSubspace(paymentmoduletypes.ModuleName),

app.BankKeeper,
app.AccountKeeper,
)
paymentModule := paymentmodule.NewAppModule(appCodec, app.PaymentKeeper, app.AccountKeeper, app.BankKeeper)

// this line is used by starport scaffolding # stargate/app/keeperDefinition

/**** Module Options ****/
Expand Down Expand Up @@ -478,6 +500,7 @@ func New(
bridgeModule,
gashubModule,
spModule,
paymentModule,
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand All @@ -504,6 +527,7 @@ func New(
bridgemoduletypes.ModuleName,
gashubtypes.ModuleName,
spmoduletypes.ModuleName,
paymentmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand All @@ -525,6 +549,7 @@ func New(
bridgemoduletypes.ModuleName,
gashubtypes.ModuleName,
spmoduletypes.ModuleName,
paymentmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand All @@ -551,6 +576,7 @@ func New(
oracletypes.ModuleName,
bridgemoduletypes.ModuleName,
spmoduletypes.ModuleName,
paymentmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down Expand Up @@ -579,6 +605,7 @@ func New(
bridgeModule,
gashubModule,
spModule,
paymentModule,
// this line is used by starport scaffolding # stargate/app/appModule
)
app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -809,6 +836,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(bridgemoduletypes.ModuleName)
paramsKeeper.Subspace(gashubtypes.ModuleName)
paramsKeeper.Subspace(spmoduletypes.ModuleName)
paramsKeeper.Subspace(paymentmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
2 changes: 1 addition & 1 deletion app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
simapp.GetSimulatorFlags()
}

// nolint: unused
// nolint
var defaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
Expand Down
2 changes: 1 addition & 1 deletion cmd/gnfd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
WithViper("")

rootCmd := &cobra.Command{
Use: app.Name + "d",
Use: app.ShortName,
Short: "Stargate CosmosHub App",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
Expand Down
29 changes: 28 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1
accounts:
- name: alice
coins: ["20000token", "200000000stake"]
coins: ["200000000000000token", "200000000stake"]
mnemonic: "marine giant loud party thrive venture winter ill grid kind bus shaft custom bunker cable trend another mosquito banner curtain rib asthma board beach"
- name: bob
coins: ["10000token", "200000000stake"]
Expand All @@ -12,6 +12,33 @@ accounts:
- name: nancy
coins: ["10000token", "200000000stake"]
mnemonic: "chase language anger island giraffe wrap island trumpet fluid story behind victory crush real swear special measure jaguar scatter color canyon forest outdoor prepare"
- name: sp0
coins: ["200000000000000token", "200000000stake"]
mnemonic: "million twice blue eternal travel number section abstract chest affair decade volcano member impose setup floor rail title female spider item nature reunion shoulder"
- name: sp1
coins: ["200000000000000token", "200000000stake"]
mnemonic: "tackle saddle wine net release bread guide reject chat cluster truly soap garden ugly search elegant hurry scrap surge item thunder liquid crop machine"
- name: sp2
coins: ["200000000000000token", "200000000stake"]
mnemonic: "genre cash give exercise dumb glove switch laugh umbrella welcome fix census record sheriff process bicycle zero apple message hunt private myself pig wealth"
- name: sp3
coins: ["200000000000000token", "200000000stake"]
mnemonic: "top ritual shaft camera type embody wedding daring direct census dad dilemma gorilla tree iron forum notable will drum bright student exhibit abuse pass"
- name: sp4
coins: ["200000000000000token", "200000000stake"]
mnemonic: "drip muffin rule hurry orphan wink light draft slush dune wisdom flag convince next this define copy pulp piano document someone found slight random"
- name: sp5
coins: ["200000000000000token", "200000000stake"]
mnemonic: "sudden float cube train okay range soap raw noise gorilla thrive clip baby december tenant help slim tumble version maximum ride buddy place loyal"
- name: sp6
coins: ["200000000000000token", "200000000stake"]
mnemonic: "among hamster prison animal grant resource crime rough affair train pelican swallow fee stove ring silk truck person loan fit play excuse athlete sauce"
- name: user
coins: ["200000000000000token", "200000000stake"]
mnemonic: "faith bomb frequent inflict endless cute glass kick session fence sell firm energy sun march melody claim almost useless burden fish force gorilla immense"
- name: user2
coins: ["200000000000000token", "200000000stake"]
mnemonic: "home piano firm basket label melt shove rhythm opinion question dragon gain sister someone marble program hurdle neither absent gown end woman stadium rare"
validators:
- name: alice
bonded: "100000000stake"
Expand Down
6 changes: 4 additions & 2 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function generate_genesis() {
${bin} add-genesis-account $sp_addrs ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spfund_addrs ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
done

size=$1
declare -a validator_addrs=()
for ((i=0;i<${size};i++));do
Expand Down Expand Up @@ -82,7 +82,7 @@ function generate_genesis() {
validatorAddr=${validator_addrs[$i]}
relayerAddr="$(${bin} keys show relayer${i} -a --keyring-backend test --home ${workspace}/.local/relayer${i})"
relayerBLSKey="$(${bin} keys show relayer_bls${i} --keyring-backend test --home ${workspace}/.local/relayer${i} --output json | jq -r .pubkey_hex)"

# create bond validator tx
${bin} gentx validator${i} ${STAKING_BOND_AMOUNT}${STAKING_BOND_DENOM} $validatorAddr $relayerAddr $relayerBLSKey \
--home ${workspace}/.local/validator${i} \
Expand Down Expand Up @@ -120,6 +120,8 @@ function generate_genesis() {
sed -i -e "s/allow_duplicate_ip = false/allow_duplicate_ip = true/g" ${workspace}/.local/validator${i}/config/config.toml
sed -i -e "s/snapshot-interval = 0/snapshot-interval = ${SNAPSHOT_INTERVAL}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/snapshot-keep-recent = 2/snapshot-keep-recent = ${SNAPSHOT_KEEP_RECENT}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/\"reserve_time\": \"15552000\"/\"reserve_time\": \"600\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/\"forced_settle_time\": \"86400\"/\"forced_settle_time\": \"100\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/172800s/${DEPOSIT_VOTE_PERIOD}/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/\"10000000\"/\"${MIN_DEPOSIT_AMOUNT}\"/g" ${workspace}/.local/validator${i}/config/genesis.json
done
Expand Down
Loading

0 comments on commit 569f459

Please sign in to comment.