Skip to content

Commit

Permalink
refactor(devgas): For #1866
Browse files Browse the repository at this point in the history
  • Loading branch information
expertdicer committed Feb 6, 2025
1 parent 1d543b3 commit cd1df04
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 132 deletions.
22 changes: 11 additions & 11 deletions x/devgas/v1/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package ante
import (
"encoding/json"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasm "github.com/CosmWasm/wasmd/x/wasm/types"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"

devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
)

var _ sdk.AnteDecorator = (*DevGasPayoutDecorator)(nil)
Expand Down Expand Up @@ -77,11 +77,11 @@ func (a DevGasPayoutDecorator) devGasPayout(

bz, err := json.Marshal(feesPaidOutput)
if err != nil {
return devgastypes.ErrFeeSharePayment.Wrapf("failed to marshal feesPaidOutput: %s", err.Error())
return devgas.ErrFeeSharePayment.Wrapf("failed to marshal feesPaidOutput: %s", err.Error())

Check warning on line 80 in x/devgas/v1/ante/ante.go

View check run for this annotation

Codecov / codecov/patch

x/devgas/v1/ante/ante.go#L80

Added line #L80 was not covered by tests
}

return ctx.EventManager().EmitTypedEvent(
&devgastypes.EventPayoutDevGas{Payouts: string(bz)},
&devgas.EventPayoutDevGas{Payouts: string(bz)},
)
}

Expand All @@ -92,7 +92,7 @@ type FeeSharePayoutEventOutput struct {

// settleFeePayments sends the funds to the contract developers
func (a DevGasPayoutDecorator) settleFeePayments(
ctx sdk.Context, toPay []sdk.AccAddress, params devgastypes.ModuleParams, totalFees sdk.Coins,
ctx sdk.Context, toPay []sdk.AccAddress, params devgas.ModuleParams, totalFees sdk.Coins,
) ([]FeeSharePayoutEventOutput, error) {
allowedFees := getAllowedFees(params, totalFees)

Expand All @@ -104,14 +104,14 @@ func (a DevGasPayoutDecorator) settleFeePayments(

// pay fees evenly between all withdraw addresses
for i, withdrawAddr := range toPay {
err := a.bankKeeper.SendCoinsFromModuleToAccount(ctx, authtypes.FeeCollectorName, withdrawAddr, splitFees)
err := a.bankKeeper.SendCoinsFromModuleToAccount(ctx, auth.FeeCollectorName, withdrawAddr, splitFees)
feesPaidOutput[i] = FeeSharePayoutEventOutput{
WithdrawAddress: withdrawAddr,
FeesPaid: splitFees,
}

if err != nil {
return nil, devgastypes.ErrFeeSharePayment.Wrapf("failed to pay allowedFees to contract developer: %s", err.Error())
return nil, devgas.ErrFeeSharePayment.Wrapf("failed to pay allowedFees to contract developer: %s", err.Error())
}
}
}
Expand All @@ -121,7 +121,7 @@ func (a DevGasPayoutDecorator) settleFeePayments(

// getAllowedFees gets the allowed fees to be paid based on the module
// parameters of x/devgas
func getAllowedFees(params devgastypes.ModuleParams, totalFees sdk.Coins) sdk.Coins {
func getAllowedFees(params devgas.ModuleParams, totalFees sdk.Coins) sdk.Coins {
// Get only allowed governance fees to be paid (helps for taxes)
var allowedFees sdk.Coins
if len(params.AllowedDenoms) == 0 {
Expand All @@ -145,9 +145,9 @@ func getAllowedFees(params devgastypes.ModuleParams, totalFees sdk.Coins) sdk.Co
func (a DevGasPayoutDecorator) getWithdrawAddressesFromMsgs(ctx sdk.Context, msgs []sdk.Msg) ([]sdk.AccAddress, error) {
toPay := make([]sdk.AccAddress, 0)
for _, msg := range msgs {
if _, ok := msg.(*wasmtypes.MsgExecuteContract); ok {
if _, ok := msg.(*wasm.MsgExecuteContract); ok {
contractAddr, err := sdk.AccAddressFromBech32(
msg.(*wasmtypes.MsgExecuteContract).Contract,
msg.(*wasm.MsgExecuteContract).Contract,
)
if err != nil {
return nil, err
Expand Down
26 changes: 13 additions & 13 deletions x/devgas/v1/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"testing"

"cosmossdk.io/math"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasm "github.com/CosmWasm/wasmd/x/wasm/types"
sdkclienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/NibiruChain/nibiru/v2/app"
"github.com/NibiruChain/nibiru/v2/x/common/testutil"
"github.com/NibiruChain/nibiru/v2/x/common/testutil/testapp"
devgasante "github.com/NibiruChain/nibiru/v2/x/devgas/v1/ante"
devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
)

type AnteTestSuite struct {
Expand Down Expand Up @@ -136,7 +136,7 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
contracts := addrs[:5]
withdrawAddrs := addrs[5:10]
deployerAddr := addrs[10]
wasmExecMsgs := []*wasmtypes.MsgExecuteContract{
wasmExecMsgs := []*wasm.MsgExecuteContract{
{Contract: contracts[0].String()},
{Contract: contracts[1].String()},
{Contract: contracts[2].String()},
Expand All @@ -145,8 +145,8 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
}
devGasForWithdrawer := func(
contractIdx int, withdrawerIdx int,
) devgastypes.FeeShare {
return devgastypes.FeeShare{
) devgas.FeeShare {
return devgas.FeeShare{
ContractAddress: contracts[contractIdx].String(),
DeployerAddress: deployerAddr.String(),
WithdrawerAddress: withdrawAddrs[withdrawerIdx].String(),
Expand All @@ -155,14 +155,14 @@ func (suite *AnteTestSuite) TestDevGasPayout() {

testCases := []struct {
name string
devGasState []devgastypes.FeeShare
devGasState []devgas.FeeShare
wantWithdrawerRoyalties sdk.Coins
wantErr bool
setup func() (*app.NibiruApp, sdk.Context)
}{
{
name: "1 contract, 1 exec, 1 withdrawer",
devGasState: []devgastypes.FeeShare{
devGasState: []devgas.FeeShare{
devGasForWithdrawer(0, 0),
},
// The expected royalty is gas / num_withdrawers / 2. Thus, We
Expand All @@ -173,14 +173,14 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
setup: func() (*app.NibiruApp, sdk.Context) {
bapp, ctx := testapp.NewNibiruTestAppAndContext()
err := testapp.FundModuleAccount(
bapp.BankKeeper, ctx, authtypes.FeeCollectorName, txGasCoins)
bapp.BankKeeper, ctx, auth.FeeCollectorName, txGasCoins)
suite.NoError(err)
return bapp, ctx
},
},
{
name: "1 contract, 4 exec, 2 withdrawer",
devGasState: []devgastypes.FeeShare{
devGasState: []devgas.FeeShare{
devGasForWithdrawer(0, 0),
devGasForWithdrawer(1, 0),
devGasForWithdrawer(2, 1),
Expand All @@ -194,14 +194,14 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
setup: func() (*app.NibiruApp, sdk.Context) {
bapp, ctx := testapp.NewNibiruTestAppAndContext()
err := testapp.FundModuleAccount(
bapp.BankKeeper, ctx, authtypes.FeeCollectorName, txGasCoins)
bapp.BankKeeper, ctx, auth.FeeCollectorName, txGasCoins)
suite.NoError(err)
return bapp, ctx
},
},
{
name: "err: empty fee collector module account",
devGasState: []devgastypes.FeeShare{
devGasState: []devgas.FeeShare{
devGasForWithdrawer(0, 0),
},
// The expected royalty is gas / num_withdrawers / 2. Thus, We
Expand All @@ -216,7 +216,7 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
},
{
name: "happy: no registered dev gas contracts",
devGasState: []devgastypes.FeeShare{},
devGasState: []devgas.FeeShare{},
// The expected royalty is gas / num_withdrawers / 2. Thus, We
// divide gas by (num_withdrawers * 2). The 2 comes from 50% split.
// wantWithdrawerRoyalties: num_withdrawers * 2 = 2
Expand Down
6 changes: 3 additions & 3 deletions x/devgas/v1/ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package ante
import (
sdk "github.com/cosmos/cosmos-sdk/types"

devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
)

type BankKeeper interface {
Expand All @@ -20,6 +20,6 @@ type BankKeeper interface {
}

type IDevGasKeeper interface {
GetParams(ctx sdk.Context) devgastypes.ModuleParams
GetFeeShare(ctx sdk.Context, contract sdk.Address) (devgastypes.FeeShare, bool)
GetParams(ctx sdk.Context) devgas.ModuleParams
GetFeeShare(ctx sdk.Context, contract sdk.Address) (devgas.FeeShare, bool)
}
4 changes: 2 additions & 2 deletions x/devgas/v1/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
params "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
ParamSet = paramtypes.ParamSet
ParamSet = params.ParamSet

// Subspace defines an interface that implements the legacy x/params
// Subspace type.
Expand Down
38 changes: 19 additions & 19 deletions x/devgas/v1/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/NibiruChain/nibiru/v2/app"
"github.com/NibiruChain/nibiru/v2/x/common/testutil"
"github.com/NibiruChain/nibiru/v2/x/common/testutil/testapp"
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1"
devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
devgasv1 "github.com/NibiruChain/nibiru/v2/x/devgas/v1"
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
)

type GenesisTestSuite struct {
Expand All @@ -22,7 +22,7 @@ type GenesisTestSuite struct {
app *app.NibiruApp
ctx sdk.Context

genesis devgastypes.GenesisState
genesis devgas.GenesisState
}

func TestGenesisTestSuite(t *testing.T) {
Expand All @@ -35,14 +35,14 @@ func (s *GenesisTestSuite) SetupTest() {
s.app = app
s.ctx = ctx

s.genesis = *devgastypes.DefaultGenesisState()
s.genesis = *devgas.DefaultGenesisState()
}

func (s *GenesisTestSuite) TestGenesis() {
randomAddr := testutil.AccAddress().String()
testCases := []struct {
name string
genesis devgastypes.GenesisState
genesis devgas.GenesisState
expPanic bool
}{
{
Expand All @@ -52,19 +52,19 @@ func (s *GenesisTestSuite) TestGenesis() {
},
{
name: "custom genesis - feeshare disabled",
genesis: devgastypes.GenesisState{
Params: devgastypes.ModuleParams{
genesis: devgas.GenesisState{
Params: devgas.ModuleParams{
EnableFeeShare: false,
DeveloperShares: devgastypes.DefaultDeveloperShares,
DeveloperShares: devgas.DefaultDeveloperShares,
AllowedDenoms: []string{"unibi"},
},
},
expPanic: false,
},
{
name: "custom genesis - feeshare enabled, 0% developer shares",
genesis: devgastypes.GenesisState{
Params: devgastypes.ModuleParams{
genesis: devgas.GenesisState{
Params: devgas.ModuleParams{
EnableFeeShare: true,
DeveloperShares: math.LegacyNewDecWithPrec(0, 2),
AllowedDenoms: []string{"unibi"},
Expand All @@ -74,8 +74,8 @@ func (s *GenesisTestSuite) TestGenesis() {
},
{
name: "custom genesis - feeshare enabled, 100% developer shares",
genesis: devgastypes.GenesisState{
Params: devgastypes.ModuleParams{
genesis: devgas.GenesisState{
Params: devgas.ModuleParams{
EnableFeeShare: true,
DeveloperShares: math.LegacyNewDecWithPrec(100, 2),
AllowedDenoms: []string{"unibi"},
Expand All @@ -85,13 +85,13 @@ func (s *GenesisTestSuite) TestGenesis() {
},
{
name: "custom genesis - feeshare enabled, all denoms allowed",
genesis: devgastypes.GenesisState{
Params: devgastypes.ModuleParams{
genesis: devgas.GenesisState{
Params: devgas.ModuleParams{
EnableFeeShare: true,
DeveloperShares: math.LegacyNewDecWithPrec(10, 2),
AllowedDenoms: []string{},
},
FeeShare: []devgastypes.FeeShare{
FeeShare: []devgas.FeeShare{
{
ContractAddress: randomAddr,
DeployerAddress: randomAddr,
Expand All @@ -103,7 +103,7 @@ func (s *GenesisTestSuite) TestGenesis() {
},
{
name: "empty genesis",
genesis: devgastypes.GenesisState{},
genesis: devgas.GenesisState{},
expPanic: true,
},
}
Expand All @@ -114,17 +114,17 @@ func (s *GenesisTestSuite) TestGenesis() {

if tc.expPanic {
s.Require().Panics(func() {
devgas.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
devgasv1.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
})
} else {
s.Require().NotPanics(func() {
devgas.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
devgasv1.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
})

params := s.app.DevGasKeeper.GetParams(s.ctx)
s.Require().EqualValues(tc.genesis.Params, params)

gen := devgas.ExportGenesis(s.ctx, s.app.DevGasKeeper)
gen := devgasv1.ExportGenesis(s.ctx, s.app.DevGasKeeper)
s.NoError(gen.Validate())
}
})
Expand Down
Loading

0 comments on commit cd1df04

Please sign in to comment.