From c58dda203414fcd746652ae2f56f8f71f2a38827 Mon Sep 17 00:00:00 2001 From: Lorenz Herzberger Date: Tue, 5 Sep 2023 11:03:42 +0200 Subject: [PATCH] add denoms to config Signed-off-by: Lorenz Herzberger --- config/config.go | 9 +++++++++ tests/e2e/dao/suite.go | 13 ++++++++++--- x/dao/keeper/keeper.go | 9 +++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index da7e666..c30b4fe 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,9 @@ const DefaultConfigTemplate = ` osc-service-port = {{ .PlmntConfig.OSCServicePort }} watchmen-endpoint = "{{ .PlmntConfig.WatchmenEndpoint }}" watchmen-port = {{ .PlmntConfig.WatchmenPort }} +token-denom = {{ .PlmntConfig.TokenDenom }} +stake-denom = {{ .PlmntConfig.StakeDenom }} +fee-denom = {{ .PlmntConfig.FeeDenom }} ` // Config defines Planetmint's top level configuration @@ -21,6 +24,9 @@ type Config struct { OSCServicePort int `mapstructure:"osc-service-port" json:"osc-service-port"` WatchmenEndpoint string `mapstructure:"watchmen-endpoint" json:"watchmen-endpoint"` WatchmenPort int `mapstructure:"watchmen-port" json:"watchmen-port"` + TokenDenom string `mapstructure:"token-denom" json:"token-denom"` + StakeDenom string `mapstructure:"stake-denom" json:"stake-denom"` + FeeDenom string `mapstructure:"fee-denom" json:"fee-denom"` } // cosmos-sdk wide global singleton @@ -35,6 +41,9 @@ func DefaultConfig() *Config { OSCServicePort: 8766, WatchmenEndpoint: "lab.r3c.network", WatchmenPort: 7401, + TokenDenom: "plmnt", + StakeDenom: "plmntstake", + FeeDenom: "plmnt", } } diff --git a/tests/e2e/dao/suite.go b/tests/e2e/dao/suite.go index 00d9165..c69d2e1 100644 --- a/tests/e2e/dao/suite.go +++ b/tests/e2e/dao/suite.go @@ -2,6 +2,7 @@ package dao import ( "fmt" + "planetmint-go/config" "planetmint-go/testutil/network" "planetmint-go/testutil/sample" @@ -37,6 +38,10 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { // SetupSuite initializes dao E2ETestSuite func (s *E2ETestSuite) SetupSuite() { + conf := config.GetConfig() + conf.FeeDenom = "node0token" + conf.SetPlanetmintConfig(conf) + s.T().Log("setting up e2e test suite") // set accounts for alice and bob in genesis state @@ -60,11 +65,13 @@ func (s *E2ETestSuite) SetupSuite() { s.cfg.Codec.MustUnmarshalJSON(s.cfg.GenesisState[banktypes.ModuleName], &bankGenState) bbalances := sdk.NewCoins( - sdk.NewCoin("rddl", math.NewInt(10000)), + sdk.NewCoin(conf.TokenDenom, math.NewInt(10000)), + sdk.NewCoin(conf.StakeDenom, math.NewInt(10000)), ) abalances := sdk.NewCoins( - sdk.NewCoin("rddl", math.NewInt(5000)), + sdk.NewCoin(conf.TokenDenom, math.NewInt(10000)), + sdk.NewCoin(conf.StakeDenom, math.NewInt(5000)), ) accountBalances := []banktypes.Balance{ @@ -74,7 +81,7 @@ func (s *E2ETestSuite) SetupSuite() { bankGenState.Balances = append(bankGenState.Balances, accountBalances...) s.cfg.GenesisState[banktypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(&bankGenState) - s.cfg.MinGasPrices = fmt.Sprintf("0.000006%s", "node0token") + s.cfg.MinGasPrices = fmt.Sprintf("0.000006%s", conf.FeeDenom) s.network = network.New(s.T(), s.cfg) } diff --git a/x/dao/keeper/keeper.go b/x/dao/keeper/keeper.go index 77ad9d4..442a1fa 100644 --- a/x/dao/keeper/keeper.go +++ b/x/dao/keeper/keeper.go @@ -12,6 +12,7 @@ import ( disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "planetmint-go/config" "planetmint-go/x/dao/types" ) @@ -58,13 +59,14 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { func (k Keeper) DistributeCollectedFees(ctx sdk.Context) { ctx = sdk.UnwrapSDKContext(ctx) + conf := config.GetConfig() balances := make(map[string]math.Int) totalStake := math.ZeroInt() k.accountKeeper.IterateAccounts(ctx, func(acc authtypes.AccountI) bool { addr := acc.GetAddress() balance := k.bankKeeper.SpendableCoins(ctx, addr) - found, stake := balance.Find("rddl") + found, stake := balance.Find(conf.StakeDenom) if found { totalStake = totalStake.Add(stake.Amount) balances[addr.String()] = stake.Amount @@ -74,8 +76,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) { distAddr := k.accountKeeper.GetModuleAddress(disttypes.ModuleName) distSpendableCoins := k.bankKeeper.SpendableCoins(ctx, distAddr) - // found, coinToDistribute := distSpendableCoins.Find("stake") - found, coinToDistribute := distSpendableCoins.Find("node0token") + found, coinToDistribute := distSpendableCoins.Find(conf.FeeDenom) if found { decTotalAmountToDistribute := sdk.NewDecFromInt(coinToDistribute.Amount) @@ -86,7 +87,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) { claim := decTotalAmountToDistribute.Mul(share) if claim.GTE(sdk.OneDec()) { intClaim := claim.TruncateInt() - coinClaim := sdk.NewCoin("node0token", intClaim) + coinClaim := sdk.NewCoin(conf.FeeDenom, intClaim) accAddress, err := sdk.AccAddressFromBech32(addr) if err != nil { panic(err)