Skip to content

Commit

Permalink
feat: add init function for gashub module (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 authored Feb 17, 2023
1 parent 2a863e1 commit 170ee16
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 46 deletions.
29 changes: 16 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,6 @@ func New(
app.MountMemoryStores(memKeys)

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

anteHandler, err := ante.NewAnteHandler(
ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
Expand All @@ -637,6 +634,9 @@ func New(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.SetUpgradeChecker(app.UpgradeKeeper.IsUpgraded)

ms := app.CommitMultiStore()
ctx := sdk.NewContext(ms, tmproto.Header{ChainID: app.ChainID(), Height: app.LastBlockHeight()}, true, app.UpgradeKeeper.IsUpgraded, app.Logger())
if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand All @@ -645,27 +645,24 @@ func New(
// Execute the upgraded register, such as the newly added Msg type
// ex.
// app.GovKeeper.Router().RegisterService(...)
ms := app.CommitMultiStore()
ctx := sdk.NewContext(ms, tmproto.Header{ChainID: app.ChainID(), Height: app.LastBlockHeight()}, true, app.UpgradeKeeper.IsUpgraded, app.Logger())
if loadLatest {
err = app.UpgradeKeeper.InitUpgraded(ctx)
if err != nil {
panic(err)
}
err = app.UpgradeKeeper.InitUpgraded(ctx)
if err != nil {
panic(err)
}
}

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

app.initModules()
app.initModules(ctx)

return app
}

func (app *App) initModules() {
func (app *App) initModules(ctx sdk.Context) {
app.initBridge()

app.initCrossChain()

app.initGashub(ctx)
}

func (app *App) initCrossChain() {
Expand All @@ -677,6 +674,12 @@ func (app *App) initBridge() {
bridgemodulekeeper.RegisterCrossApps(app.BridgeKeeper)
}

func (app *App) initGashub(ctx sdk.Context) {
if app.LastBlockHeight() > 0 {
app.GashubKeeper.RegisterGasCalculators(ctx)
}
}

// Name returns the name of the App
func (app *App) Name() string { return app.BaseApp.Name() }

Expand Down
2 changes: 1 addition & 1 deletion app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewDefaultAppConfig() *AppConfig {
// own app.toml to override, or use this default value.
//
// In simapp, we set the min gas prices to 0.
srvCfg.MinGasPrices = "0stake"
srvCfg.MinGasPrices = "1000000000BNB"

return &AppConfig{
Config: *srvCfg,
Expand Down
1 change: 1 addition & 0 deletions cmd/gnfd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
flags.FlagChainID: app.Name + "_" + app.EIP155ChainID + "-" + app.Epoch,
flags.FlagKeyringBackend: "test",
flags.FlagSignMode: flags.SignModeEIP712,
flags.FlagGas: "auto",
})

return rootCmd, encodingConfig
Expand Down
25 changes: 13 additions & 12 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function generate_genesis() {
spfund_addr=("$(${bin} keys show sp${i}_fund -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spseal_addr=("$(${bin} keys show sp${i}_seal -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spapproval_addr=("$(${bin} keys show sp${i}_approval -a --keyring-backend test --home ${workspace}/.local/sp${i})")
${bin} add-genesis-account $sp_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $sp_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spfund_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spseal_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spseal_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spapproval_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
done

Expand Down Expand Up @@ -100,9 +100,10 @@ function generate_genesis() {
--commission-rate=${COMMISSION_RATE} \
--details="validator${i}" \
--website="http://website" \
--node tcp://localhost:$((${VALIDATOR_P2P_PORT_START}+${i})) \
--node tcp://localhost:$((${VALIDATOR_RPC_PORT_START}+${i})) \
--node-id "validator${i}" \
--ip 127.0.0.1
--ip 127.0.0.1 \
--gas ""
cp ${workspace}/.local/validator${i}/config/gentx/gentx-validator${i}.json ${workspace}/.local/gentx/
done

Expand Down Expand Up @@ -186,7 +187,7 @@ function sp_join() {
--from sp${i}_fund \
--home "${workspace}/.local/sp${i}" \
--keyring-backend test \
--node http://localhost:26750 \
--node http://localhost:${VALIDATOR_RPC_PORT_START} \
--yes
done

Expand All @@ -212,7 +213,7 @@ function sp_join() {
--from sp${i} \
--keyring-backend test \
--home ${workspace}/.local/sp${i} \
--node http://localhost:26750 \
--node http://localhost:${VALIDATOR_RPC_PORT_START} \
--broadcast-mode block \
--yes

Expand All @@ -222,7 +223,7 @@ function sp_join() {
--from sp${i} \
--keyring-backend test \
--home ${workspace}/.local/sp${i} \
--node http://localhost:26750 \
--node http://localhost:${VALIDATOR_RPC_PORT_START} \
--broadcast-mode block \
--yes

Expand All @@ -232,7 +233,7 @@ function sp_join() {
--from validator0 \
--keyring-backend test \
--home ${workspace}/.local/validator0 \
--node http://localhost:26750 \
--node http://localhost:${VALIDATOR_RPC_PORT_START} \
--broadcast-mode block \
--yes
sleep 1
Expand All @@ -247,7 +248,7 @@ function sp_check() {
# wait 360s , and then check the sp if ready
n=0
while [ $n -le 360 ]; do
cnt=("$(${bin} query sp storage-providers --node http://localhost:26750 | grep approval_address | wc -l)")
cnt=("$(${bin} query sp storage-providers --node http://localhost:${VALIDATOR_RPC_PORT_START} | grep approval_address | wc -l)")
((n++))
sleep 1
if [ "$cnt" -eq "$sp_size" ]; then
Expand All @@ -273,12 +274,12 @@ fi
case ${CMD} in
init)
echo "===== init ===="
init $SIZE
init $SIZE $SP_SIZE
echo "===== end ===="
;;
generate)
echo "===== generate genesis ===="
generate_genesis $SIZE
generate_genesis $SIZE $SP_SIZE
echo "===== end ===="
;;
start)
Expand Down Expand Up @@ -319,4 +320,4 @@ all)
# TODO: implement create sp in genesis use genesis transaction like validator.
echo "Usage: localup.sh all | init | generate | start | sp_join | sp_check | stop"
;;
esac
esac
13 changes: 7 additions & 6 deletions e2e/core/basesuite.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package core

import (
"github.com/bnb-chain/greenfield/sdk/client"
"github.com/bnb-chain/greenfield/sdk/keys"
"github.com/bnb-chain/greenfield/sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/bnb-chain/greenfield/sdk/client"
"github.com/bnb-chain/greenfield/sdk/keys"
"github.com/bnb-chain/greenfield/sdk/types"
)

type BaseSuite struct {
Expand All @@ -34,7 +35,7 @@ func (s *BaseSuite) SendTxBlock(msg sdk.Msg, from keys.KeyManager) (txRes *sdk.T
Mode: &mode,
GasLimit: 1000000,
Memo: "",
FeeAmount: sdk.Coins{{Denom: s.config.Denom, Amount: sdk.NewInt(1)}},
FeeAmount: sdk.Coins{{Denom: s.config.Denom, Amount: sdk.NewInt(1e9 * 1e6)}},
}
s.Client.SetKeyManager(from)
response, err := s.Client.BroadcastTx([]sdk.Msg{msg}, txOpt)
Expand All @@ -52,15 +53,15 @@ func (s *BaseSuite) GenAndChargeAccounts(n int, balance int64) (accounts []keys.
accounts = append(accounts, km)
outputs = append(outputs, banktypes.Output{
Address: km.GetAddr().String(),
Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance)}},
Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance * 1e18)}},
})
}
if balance == 0 {
return
}
in := banktypes.Input{
Address: s.TestAccount.GetAddr().String(),
Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance * int64(n))}},
Coins: []sdk.Coin{{Denom: denom, Amount: sdk.NewInt(balance * 1e18 * int64(n))}},
}
msg := banktypes.MsgMultiSend{
Inputs: []banktypes.Input{in},
Expand Down
2 changes: 1 addition & 1 deletion e2e/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Config struct {
}

func InitConfig() *Config {
// todo: support qa and testnet config
// TODO: support qa and testnet config
return InitE2eConfig()
}

Expand Down
3 changes: 2 additions & 1 deletion e2e/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"math/rand"

"github.com/bnb-chain/greenfield/sdk/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto"

"github.com/bnb-chain/greenfield/sdk/keys"
)

func GenRandomAddr() sdk.AccAddress {
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"context"
"testing"

"github.com/stretchr/testify/suite"

"github.com/bnb-chain/greenfield/e2e/core"
paymenttypes "github.com/bnb-chain/greenfield/x/payment/types"
"github.com/stretchr/testify/suite"
)

type PaymentTestSuite struct {
Expand All @@ -18,8 +19,7 @@ func (s *PaymentTestSuite) SetupSuite() {
s.BaseSuite.SetupSuite()
}

func (s *PaymentTestSuite) SetupTest() {
}
func (s *PaymentTestSuite) SetupTest() {}

func (s *PaymentTestSuite) TestPaymentAccount() {
user := s.GenAndChargeAccounts(1, 100)[0]
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/tendermint/tendermint v0.34.22
github.com/tendermint/tm-db v0.6.7
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37
google.golang.org/grpc v1.52.3
google.golang.org/grpc v1.51.0
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.3.0
)
Expand All @@ -30,7 +30,7 @@ require golang.org/x/text v0.6.0 // indirect

require (
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.4
github.com/cosmos/gogoproto v1.4.3
github.com/prysmaticlabs/prysm v0.0.0-20220124113610-e26cde5e091b
github.com/rakyll/statik v0.1.7
github.com/spf13/viper v1.13.0
Expand Down Expand Up @@ -228,7 +228,7 @@ require (

replace (
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230214050107-c8beb3e72b61
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230216105555-b94a14479b11
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/bnb-chain/gnfd-tendermint v0.0.1
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230214050107-c8beb3e72b61 h1:L+oI2VYN0GxQDqossulvO0InsZ/cBkPBSzRZg8iOP0Y=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230214050107-c8beb3e72b61/go.mod h1:NlIOmju3uhTOJ2YAzLPidpmh7sAgJ+J9dkUlSysHmjw=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230216105555-b94a14479b11 h1:2BDa9ntopNBk6kQWoGTbX6TzJckyek0K9bk9NcHBIhw=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230216105555-b94a14479b11/go.mod h1:NlIOmju3uhTOJ2YAzLPidpmh7sAgJ+J9dkUlSysHmjw=
github.com/bnb-chain/gnfd-tendermint v0.0.1 h1:KWFuxWv8m6t1vUi3ADyVcEG0qVnEzQt1tjA6dk/b7+Q=
github.com/bnb-chain/gnfd-tendermint v0.0.1/go.mod h1:/v9z9F6cq0+f7EGG92lYSLBcPYQDILoK91X8YM28hWo=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
Expand Down Expand Up @@ -433,8 +433,8 @@ github.com/cosmos/cosmos-sdk/ics23/go v0.8.0/go.mod h1:2a4dBq88TUoqoWAU5eu0lGvpF
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogoproto v1.4.4 h1:nVAsgLlAf5jeN0fV7hRlkZvf768zU+dy4pG+hxc2P34=
github.com/cosmos/gogoproto v1.4.4/go.mod h1:/yl6/nLwsZcZ2JY3OrqjRqvqCG9InUMcXRfRjQiF9DU=
github.com/cosmos/gogoproto v1.4.3 h1:RP3yyVREh9snv/lsOvmsAPQt8f44LgL281X0IOIhhcI=
github.com/cosmos/gogoproto v1.4.3/go.mod h1:0hLIG5TR7IvV1fme1HCFKjfzW9X2x0Mo+RooWXCnOWU=
github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y=
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok=
Expand Down Expand Up @@ -2498,8 +2498,8 @@ google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.52.3 h1:pf7sOysg4LdgBqduXveGKrcEwbStiK2rtfghdzlUYDQ=
google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
google.golang.org/grpc v1.51.0 h1:E1eGv1FTqoLIdnBCZufiSHgKjlqG6fKFf6pPWtMTh8U=
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.0.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down

0 comments on commit 170ee16

Please sign in to comment.