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

feat(x/mint): app wiring #304

Merged
merged 8 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 6 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
Expand Down Expand Up @@ -99,6 +96,9 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/archway-network/archway/wasmbinding"
"github.com/archway-network/archway/x/mint"
mintkeeper "github.com/archway-network/archway/x/mint/keeper"
minttypes "github.com/archway-network/archway/x/mint/types"
"github.com/archway-network/archway/x/rewards"
rewardsKeeper "github.com/archway-network/archway/x/rewards/keeper"
rewardsTypes "github.com/archway-network/archway/x/rewards/types"
Expand Down Expand Up @@ -522,10 +522,7 @@ func NewArchwayApp(
appCodec,
keys[minttypes.StoreKey],
app.getSubspace(minttypes.ModuleName),
&stakingKeeper,
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
)

// The gov proposal types can be individually enabled
Expand Down Expand Up @@ -564,7 +561,7 @@ func NewArchwayApp(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
mint.NewAppModule(appCodec, app.MintKeeper),
slashing.NewAppModule(appCodec, app.slashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -695,7 +692,7 @@ func NewArchwayApp(
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
mint.NewAppModule(appCodec, app.MintKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(appCodec, app.slashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand Down Expand Up @@ -880,7 +877,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable())
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
Expand Down
2 changes: 1 addition & 1 deletion app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"testing"

minttypes "github.com/archway-network/archway/x/mint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -20,7 +21,6 @@ import (
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"time"

minttypes "github.com/archway-network/archway/x/mint/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down
16 changes: 7 additions & 9 deletions e2e/gastracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (

wasmdTypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authTypes "github.com/cosmos/cosmos-sdk/x/auth/types"
abci "github.com/tendermint/tendermint/abci/types"

voterTypes "github.com/archway-network/voter/src/types"

e2eTesting "github.com/archway-network/archway/e2e/testing"
"github.com/archway-network/archway/pkg"
mintTypes "github.com/archway-network/archway/x/mint/types"
rewardsTypes "github.com/archway-network/archway/x/rewards/types"
trackingTypes "github.com/archway-network/archway/x/tracking/types"
)
Expand All @@ -28,17 +30,16 @@ func (s *E2ETestSuite) TestGasTrackingAndRewardsDistribution() {
txFeeRebateRewardsRatio := sdk.NewDecWithPrec(5, 1)
inflationRewardsRatio := sdk.NewDecWithPrec(5, 1)
blockGasLimit := int64(10_000_000)
mintParams := mintTypes.DefaultParams()
mintParams.MinInflation = sdk.OneDec()

// Setup (create new chain here with custom params)
chain := e2eTesting.NewTestChain(s.T(), 1,
e2eTesting.WithTxFeeRebatesRewardsRatio(txFeeRebateRewardsRatio),
e2eTesting.WithBlockGasLimit(blockGasLimit),
// Artificially increase the minted inflation coin to get some rewards for the contract (otherwise contractOp gas / blockGasLimit ratio will be 0)
e2eTesting.WithMintParams(
sdk.NewDecWithPrec(8, 1),
sdk.NewDecWithPrec(8, 1),
1000000,
),
e2eTesting.WithMintParams(mintParams),
e2eTesting.WithInflationDistributionRecipient(authTypes.FeeCollectorName, sdk.OneDec().Sub(inflationRewardsRatio)),
e2eTesting.WithInflationDistributionRecipient(rewardsTypes.ModuleName, inflationRewardsRatio),
// Set default Tx fee for non-manual transaction like Upload / Instantiate
e2eTesting.WithDefaultFeeAmount("10000"),
Expand Down Expand Up @@ -116,10 +117,7 @@ func (s *E2ETestSuite) TestGasTrackingAndRewardsDistribution() {
{
ctx := chain.GetContext()

mintKeeper := chain.GetApp().MintKeeper
mintParams := mintKeeper.GetParams(ctx)

mintedCoin := chain.GetApp().MintKeeper.GetMinter(ctx).BlockProvision(mintParams)
mintedCoin, _ := chain.GetApp().MintKeeper.GetBlockProvisions(ctx)
inflationRewards, _ := pkg.SplitCoins(sdk.NewCoins(mintedCoin), inflationRewardsRatio)
s.Require().Len(inflationRewards, 1)
blockInflationRewardsExpected = inflationRewards[0]
Expand Down
17 changes: 8 additions & 9 deletions e2e/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"time"

wasmdTypes "github.com/CosmWasm/wasmd/x/wasm/types"
mintTypes "github.com/archway-network/archway/x/mint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types"

voterCustomTypes "github.com/archway-network/voter/src/pkg/archway/custom"
voterTypes "github.com/archway-network/voter/src/types"
Expand All @@ -25,6 +25,9 @@ func (s *E2ETestSuite) TestRewardsWithdrawProfitAndFees() {
batchIncStep = 300 // withdraw batch size increment
batchStartSize = 100 // withdraw batch size start value
)
mintParams := mintTypes.DefaultParams()
mintParams.MinInflation = sdk.MustNewDecFromStr("0.1") // 10%
mintParams.MaxInflation = sdk.MustNewDecFromStr("0.1") // 10%

// Create a custom chain with "close to mainnet" params
chain := e2eTesting.NewTestChain(s.T(), 1,
Expand All @@ -41,11 +44,7 @@ func (s *E2ETestSuite) TestRewardsWithdrawProfitAndFees() {
e2eTesting.WithTxFeeRebatesRewardsRatio(sdk.NewDecWithPrec(5, 1)),
e2eTesting.WithInflationDistributionRecipient(rewardsTypes.ModuleName, sdk.NewDecWithPrec(2, 1)),
// Set constant inflation rate
e2eTesting.WithMintParams(
sdk.NewDecWithPrec(10, 2), // 10%
sdk.NewDecWithPrec(10, 2), // 10%
uint64(60*60*8766/1), // 1 seconds block time
),
e2eTesting.WithMintParams(mintParams),
)
trackingKeeper, rewardsKeeper := chain.GetApp().TrackingKeeper, chain.GetApp().RewardsKeeper
chain.NextBlock(0)
Expand Down Expand Up @@ -170,7 +169,7 @@ func (s *E2ETestSuite) TestRewardsWithdrawProfitAndFees() {
}

// Mint rewards coins
s.Require().NoError(chain.GetApp().MintKeeper.MintCoins(ctx, coinsToMint))
s.Require().NoError(chain.GetApp().MintKeeper.MintCoins(ctx, mintTypes.ModuleName, coinsToMint))
s.Require().NoError(chain.GetApp().BankKeeper.SendCoinsFromModuleToModule(ctx, mintTypes.ModuleName, rewardsTypes.ContractRewardCollector, coinsToMint))

// Invariants check (just in case)
Expand Down Expand Up @@ -273,7 +272,7 @@ func (s *E2ETestSuite) TestRewardsParamMaxWithdrawRecordsLimit() {
}

mintCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(rewardsTypes.MaxWithdrawRecordsParamLimit)))
s.Require().NoError(mintKeeper.MintCoins(ctx, mintCoins))
s.Require().NoError(mintKeeper.MintCoins(ctx, mintTypes.ModuleName, mintCoins))
s.Require().NoError(bankKeeper.SendCoinsFromModuleToModule(ctx, mintTypes.ModuleName, rewardsTypes.ContractRewardCollector, mintCoins))
}

Expand Down Expand Up @@ -347,7 +346,7 @@ func (s *E2ETestSuite) TestRewardsRecordsQueryLimit() {
}

mintCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(rewardsTypes.MaxRecordsQueryLimit)))
s.Require().NoError(mintKeeper.MintCoins(ctx, mintCoins))
s.Require().NoError(mintKeeper.MintCoins(ctx, mintTypes.ModuleName, mintCoins))
s.Require().NoError(bankKeeper.SendCoinsFromModuleToModule(ctx, mintTypes.ModuleName, rewardsTypes.ContractRewardCollector, mintCoins))

recordsExpected = records
Expand Down
8 changes: 3 additions & 5 deletions e2e/testing/chain_options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package e2eTesting

import (
mintTypes "github.com/archway-network/archway/x/mint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/archway-network/archway/app"
Expand Down Expand Up @@ -107,14 +107,12 @@ func WithTxFeeRebatesRewardsRatio(ratio sdk.Dec) TestChainGenesisOption {
}

// WithMintParams sets x/mint inflation calculation parameters.
func WithMintParams(inflationMin, inflationMax sdk.Dec, blocksPerYear uint64) TestChainGenesisOption {
func WithMintParams(mintParams mintTypes.Params) TestChainGenesisOption {
return func(cdc codec.Codec, genesis app.GenesisState) {
var mintGenesis mintTypes.GenesisState
cdc.MustUnmarshalJSON(genesis[mintTypes.ModuleName], &mintGenesis)

mintGenesis.Params.InflationMin = inflationMin
mintGenesis.Params.InflationMax = inflationMax
mintGenesis.Params.BlocksPerYear = blocksPerYear
mintGenesis.Params = mintParams

genesis[mintTypes.ModuleName] = cdc.MustMarshalJSON(&mintGenesis)
}
Expand Down
13 changes: 6 additions & 7 deletions e2e/txfees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
voterTypes "github.com/archway-network/voter/src/types"

e2eTesting "github.com/archway-network/archway/e2e/testing"
mintTypes "github.com/archway-network/archway/x/mint/types"
rewardsTypes "github.com/archway-network/archway/x/rewards/types"
)

Expand All @@ -34,6 +35,9 @@ func (s *E2ETestSuite) TestTxFees() {
}
return fmt.Sprintf("%8s", e2eTesting.HumanizeDecCoins(0, coin))
}
mintParams := mintTypes.DefaultParams()
mintParams.MinInflation = sdk.MustNewDecFromStr("0.1") // 10% (Archway mainnet param)
mintParams.MaxInflation = sdk.MustNewDecFromStr("0.1") // 10% (Archway mainnet param)

// Create a custom chain with fixed inflation (10%) and 10M block gas limit
chain := e2eTesting.NewTestChain(s.T(), 1,
Expand All @@ -50,11 +54,7 @@ func (s *E2ETestSuite) TestTxFees() {
e2eTesting.WithTxFeeRebatesRewardsRatio(sdk.NewDecWithPrec(5, 1)), // 50 % (Archway mainnet param)
e2eTesting.WithInflationDistributionRecipient(rewardsTypes.ModuleName, sdk.NewDecWithPrec(2, 1)), // 20 % (Archway mainnet param)
// Set constant inflation rate
e2eTesting.WithMintParams(
sdk.NewDecWithPrec(10, 2), // 10% (Archway mainnet param)
sdk.NewDecWithPrec(10, 2), // 10% (Archway mainnet param)
uint64(60*60*8766/1), //1 seconds block time (Archway mainnet param)
),
e2eTesting.WithMintParams(mintParams),
)

// Check total supply
Expand Down Expand Up @@ -99,8 +99,7 @@ func (s *E2ETestSuite) TestTxFees() {
{
ctx := chain.GetContext()

mintParams := chain.GetApp().MintKeeper.GetParams(ctx)
mintedCoin := chain.GetApp().MintKeeper.GetMinter(ctx).BlockProvision(mintParams)
mintedCoin, _ := chain.GetApp().MintKeeper.GetBlockProvisions(ctx)
s.T().Logf("x/mint minted amount per block: %s", coinsToStr(mintedCoin))
}

Expand Down
4 changes: 2 additions & 2 deletions wasmbinding/rewards/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"time"

"github.com/CosmWasm/wasmvm/types"
mintTypes "github.com/archway-network/archway/x/mint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -241,7 +241,7 @@ func TestRewardsWASMBindings(t *testing.T) {
keeper.GetState().RewardsRecord(ctx).CreateRewardsRecord(contractAddr, record1RewardsExpected, ctx.BlockHeight(), ctx.BlockTime())
keeper.GetState().RewardsRecord(ctx).CreateRewardsRecord(contractAddr, record2RewardsExpected, ctx.BlockHeight(), ctx.BlockTime())
keeper.GetState().RewardsRecord(ctx).CreateRewardsRecord(contractAddr, record3RewardsExpected, ctx.BlockHeight(), ctx.BlockTime())
require.NoError(t, chain.GetApp().MintKeeper.MintCoins(ctx, recordsRewards))
require.NoError(t, chain.GetApp().MintKeeper.MintCoins(ctx, mintTypes.ModuleName, recordsRewards))
require.NoError(t, chain.GetApp().BankKeeper.SendCoinsFromModuleToModule(ctx, mintTypes.ModuleName, rewardsTypes.ContractRewardCollector, recordsRewards))

// Query available rewards
Expand Down
8 changes: 5 additions & 3 deletions x/mint/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
k.SetParams(ctx, genState.GetParams())
lbi := genState.GetLastBlockInfo()
if (lbi == types.LastBlockInfo{}) {
time := ctx.BlockTime()
if (lbi.Inflation == sdk.Dec{}) {
lbi = types.LastBlockInfo{
Inflation: genState.Params.MinInflation,
Time: &time,
}
}
if lbi.Time == nil {
time := ctx.BlockTime()
lbi.Time = &time
}
if err := k.SetLastBlockInfo(ctx, lbi); err != nil {
panic(err)
}
Expand Down
90 changes: 89 additions & 1 deletion x/mint/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,91 @@
package mint_test

// todo: add tests after app wiring: #289
import (
"testing"
"time"

e2eTesting "github.com/archway-network/archway/e2e/testing"
"github.com/archway-network/archway/x/mint"
"github.com/archway-network/archway/x/mint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"
)

// TestGenesisImportExport check genesis import/export.
func (s *KeeperTestSuite) TestGenesisImportExport() {
currentTime := time.Now()
ctx, k := s.chain.GetContext().WithBlockTime(currentTime), s.chain.GetApp().MintKeeper
inflation := sdk.MustNewDecFromStr("0.3")

s.Run("Panic: invalid inflation info. should panic", func() {
initParams := types.DefaultParams()
genesisState := types.GenesisState{
Params: initParams,
LastBlockInfo: types.LastBlockInfo{
Inflation: sdk.MustNewDecFromStr("8"),
Time: &currentTime,
},
}
s.Panics(func() { mint.InitGenesis(ctx, k, genesisState) })
})

s.Run("OK: check state matches init input. LastBlockInfo missing", func() {
initParams := types.DefaultParams()
initParams.MinInflation = sdk.MustNewDecFromStr("1")
genesisState := types.GenesisState{
Params: initParams,
}

mint.InitGenesis(ctx, k, genesisState)

params := k.GetParams(ctx)
lbi, found := k.GetLastBlockInfo(ctx)
s.Require().EqualValues(initParams, params)
s.Require().True(found)
s.Require().EqualValues(params.MinInflation, lbi.Inflation)
s.Require().EqualValues(currentTime.UTC(), lbi.Time.UTC())
})

s.Run("OK: check state matches init input", func() {
initParams := types.DefaultParams()
initParams.InflationChange = sdk.MustNewDecFromStr("0.123")
genesisState := types.GenesisState{
Params: initParams,
LastBlockInfo: types.LastBlockInfo{
Inflation: inflation,
Time: &currentTime,
},
}

mint.InitGenesis(ctx, k, genesisState)

params := k.GetParams(ctx)
lbi, found := k.GetLastBlockInfo(ctx)
s.Require().EqualValues(initParams, params)
s.Require().True(found)
s.Require().EqualValues(inflation, lbi.Inflation)
s.Require().EqualValues(currentTime.UTC(), lbi.Time.UTC())
})

s.Run("OK: check export matches what we init", func() {
k.SetParams(ctx, types.DefaultParams())
genesisState := mint.ExportGenesis(ctx, k)
s.Require().NotNil(genesisState)
s.Require().EqualValues(types.DefaultParams(), genesisState.Params)
s.Require().EqualValues(inflation, genesisState.LastBlockInfo.Inflation)
s.Require().EqualValues(currentTime.UTC(), genesisState.LastBlockInfo.Time.UTC())
})
}

type KeeperTestSuite struct {
suite.Suite
chain *e2eTesting.TestChain
}

func (s *KeeperTestSuite) SetupTest() {
s.chain = e2eTesting.NewTestChain(s.T(), 1)
}

func TestMintKeeper(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
Loading