Skip to content

Commit cd1df04

Browse files
committed
refactor(devgas): For #1866
1 parent 1d543b3 commit cd1df04

15 files changed

+132
-132
lines changed

x/devgas/v1/ante/ante.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package ante
33
import (
44
"encoding/json"
55

6-
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
6+
wasm "github.com/CosmWasm/wasmd/x/wasm/types"
77

88
sdk "github.com/cosmos/cosmos-sdk/types"
99
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
10-
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
10+
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
1111

12-
devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
12+
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
1313
)
1414

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

7878
bz, err := json.Marshal(feesPaidOutput)
7979
if err != nil {
80-
return devgastypes.ErrFeeSharePayment.Wrapf("failed to marshal feesPaidOutput: %s", err.Error())
80+
return devgas.ErrFeeSharePayment.Wrapf("failed to marshal feesPaidOutput: %s", err.Error())
8181
}
8282

8383
return ctx.EventManager().EmitTypedEvent(
84-
&devgastypes.EventPayoutDevGas{Payouts: string(bz)},
84+
&devgas.EventPayoutDevGas{Payouts: string(bz)},
8585
)
8686
}
8787

@@ -92,7 +92,7 @@ type FeeSharePayoutEventOutput struct {
9292

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

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

105105
// pay fees evenly between all withdraw addresses
106106
for i, withdrawAddr := range toPay {
107-
err := a.bankKeeper.SendCoinsFromModuleToAccount(ctx, authtypes.FeeCollectorName, withdrawAddr, splitFees)
107+
err := a.bankKeeper.SendCoinsFromModuleToAccount(ctx, auth.FeeCollectorName, withdrawAddr, splitFees)
108108
feesPaidOutput[i] = FeeSharePayoutEventOutput{
109109
WithdrawAddress: withdrawAddr,
110110
FeesPaid: splitFees,
111111
}
112112

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

122122
// getAllowedFees gets the allowed fees to be paid based on the module
123123
// parameters of x/devgas
124-
func getAllowedFees(params devgastypes.ModuleParams, totalFees sdk.Coins) sdk.Coins {
124+
func getAllowedFees(params devgas.ModuleParams, totalFees sdk.Coins) sdk.Coins {
125125
// Get only allowed governance fees to be paid (helps for taxes)
126126
var allowedFees sdk.Coins
127127
if len(params.AllowedDenoms) == 0 {
@@ -145,9 +145,9 @@ func getAllowedFees(params devgastypes.ModuleParams, totalFees sdk.Coins) sdk.Co
145145
func (a DevGasPayoutDecorator) getWithdrawAddressesFromMsgs(ctx sdk.Context, msgs []sdk.Msg) ([]sdk.AccAddress, error) {
146146
toPay := make([]sdk.AccAddress, 0)
147147
for _, msg := range msgs {
148-
if _, ok := msg.(*wasmtypes.MsgExecuteContract); ok {
148+
if _, ok := msg.(*wasm.MsgExecuteContract); ok {
149149
contractAddr, err := sdk.AccAddressFromBech32(
150-
msg.(*wasmtypes.MsgExecuteContract).Contract,
150+
msg.(*wasm.MsgExecuteContract).Contract,
151151
)
152152
if err != nil {
153153
return nil, err

x/devgas/v1/ante/ante_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import (
66
"testing"
77

88
"cosmossdk.io/math"
9-
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
9+
wasm "github.com/CosmWasm/wasmd/x/wasm/types"
1010
sdkclienttx "github.com/cosmos/cosmos-sdk/client/tx"
1111
"github.com/stretchr/testify/suite"
1212

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

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

1717
"github.com/NibiruChain/nibiru/v2/app"
1818
"github.com/NibiruChain/nibiru/v2/x/common/testutil"
1919
"github.com/NibiruChain/nibiru/v2/x/common/testutil/testapp"
2020
devgasante "github.com/NibiruChain/nibiru/v2/x/devgas/v1/ante"
21-
devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
21+
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
2222
)
2323

2424
type AnteTestSuite struct {
@@ -136,7 +136,7 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
136136
contracts := addrs[:5]
137137
withdrawAddrs := addrs[5:10]
138138
deployerAddr := addrs[10]
139-
wasmExecMsgs := []*wasmtypes.MsgExecuteContract{
139+
wasmExecMsgs := []*wasm.MsgExecuteContract{
140140
{Contract: contracts[0].String()},
141141
{Contract: contracts[1].String()},
142142
{Contract: contracts[2].String()},
@@ -145,8 +145,8 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
145145
}
146146
devGasForWithdrawer := func(
147147
contractIdx int, withdrawerIdx int,
148-
) devgastypes.FeeShare {
149-
return devgastypes.FeeShare{
148+
) devgas.FeeShare {
149+
return devgas.FeeShare{
150150
ContractAddress: contracts[contractIdx].String(),
151151
DeployerAddress: deployerAddr.String(),
152152
WithdrawerAddress: withdrawAddrs[withdrawerIdx].String(),
@@ -155,14 +155,14 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
155155

156156
testCases := []struct {
157157
name string
158-
devGasState []devgastypes.FeeShare
158+
devGasState []devgas.FeeShare
159159
wantWithdrawerRoyalties sdk.Coins
160160
wantErr bool
161161
setup func() (*app.NibiruApp, sdk.Context)
162162
}{
163163
{
164164
name: "1 contract, 1 exec, 1 withdrawer",
165-
devGasState: []devgastypes.FeeShare{
165+
devGasState: []devgas.FeeShare{
166166
devGasForWithdrawer(0, 0),
167167
},
168168
// The expected royalty is gas / num_withdrawers / 2. Thus, We
@@ -173,14 +173,14 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
173173
setup: func() (*app.NibiruApp, sdk.Context) {
174174
bapp, ctx := testapp.NewNibiruTestAppAndContext()
175175
err := testapp.FundModuleAccount(
176-
bapp.BankKeeper, ctx, authtypes.FeeCollectorName, txGasCoins)
176+
bapp.BankKeeper, ctx, auth.FeeCollectorName, txGasCoins)
177177
suite.NoError(err)
178178
return bapp, ctx
179179
},
180180
},
181181
{
182182
name: "1 contract, 4 exec, 2 withdrawer",
183-
devGasState: []devgastypes.FeeShare{
183+
devGasState: []devgas.FeeShare{
184184
devGasForWithdrawer(0, 0),
185185
devGasForWithdrawer(1, 0),
186186
devGasForWithdrawer(2, 1),
@@ -194,14 +194,14 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
194194
setup: func() (*app.NibiruApp, sdk.Context) {
195195
bapp, ctx := testapp.NewNibiruTestAppAndContext()
196196
err := testapp.FundModuleAccount(
197-
bapp.BankKeeper, ctx, authtypes.FeeCollectorName, txGasCoins)
197+
bapp.BankKeeper, ctx, auth.FeeCollectorName, txGasCoins)
198198
suite.NoError(err)
199199
return bapp, ctx
200200
},
201201
},
202202
{
203203
name: "err: empty fee collector module account",
204-
devGasState: []devgastypes.FeeShare{
204+
devGasState: []devgas.FeeShare{
205205
devGasForWithdrawer(0, 0),
206206
},
207207
// The expected royalty is gas / num_withdrawers / 2. Thus, We
@@ -216,7 +216,7 @@ func (suite *AnteTestSuite) TestDevGasPayout() {
216216
},
217217
{
218218
name: "happy: no registered dev gas contracts",
219-
devGasState: []devgastypes.FeeShare{},
219+
devGasState: []devgas.FeeShare{},
220220
// The expected royalty is gas / num_withdrawers / 2. Thus, We
221221
// divide gas by (num_withdrawers * 2). The 2 comes from 50% split.
222222
// wantWithdrawerRoyalties: num_withdrawers * 2 = 2

x/devgas/v1/ante/expected_keepers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package ante
55
import (
66
sdk "github.com/cosmos/cosmos-sdk/types"
77

8-
devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
8+
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
99
)
1010

1111
type BankKeeper interface {
@@ -20,6 +20,6 @@ type BankKeeper interface {
2020
}
2121

2222
type IDevGasKeeper interface {
23-
GetParams(ctx sdk.Context) devgastypes.ModuleParams
24-
GetFeeShare(ctx sdk.Context, contract sdk.Address) (devgastypes.FeeShare, bool)
23+
GetParams(ctx sdk.Context) devgas.ModuleParams
24+
GetFeeShare(ctx sdk.Context, contract sdk.Address) (devgas.FeeShare, bool)
2525
}

x/devgas/v1/exported/exported.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package exported
22

33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
5-
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
5+
params "github.com/cosmos/cosmos-sdk/x/params/types"
66
)
77

88
type (
9-
ParamSet = paramtypes.ParamSet
9+
ParamSet = params.ParamSet
1010

1111
// Subspace defines an interface that implements the legacy x/params
1212
// Subspace type.

x/devgas/v1/genesis_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"github.com/NibiruChain/nibiru/v2/app"
1313
"github.com/NibiruChain/nibiru/v2/x/common/testutil"
1414
"github.com/NibiruChain/nibiru/v2/x/common/testutil/testapp"
15-
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1"
16-
devgastypes "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
15+
devgasv1 "github.com/NibiruChain/nibiru/v2/x/devgas/v1"
16+
devgas "github.com/NibiruChain/nibiru/v2/x/devgas/v1/types"
1717
)
1818

1919
type GenesisTestSuite struct {
@@ -22,7 +22,7 @@ type GenesisTestSuite struct {
2222
app *app.NibiruApp
2323
ctx sdk.Context
2424

25-
genesis devgastypes.GenesisState
25+
genesis devgas.GenesisState
2626
}
2727

2828
func TestGenesisTestSuite(t *testing.T) {
@@ -35,14 +35,14 @@ func (s *GenesisTestSuite) SetupTest() {
3535
s.app = app
3636
s.ctx = ctx
3737

38-
s.genesis = *devgastypes.DefaultGenesisState()
38+
s.genesis = *devgas.DefaultGenesisState()
3939
}
4040

4141
func (s *GenesisTestSuite) TestGenesis() {
4242
randomAddr := testutil.AccAddress().String()
4343
testCases := []struct {
4444
name string
45-
genesis devgastypes.GenesisState
45+
genesis devgas.GenesisState
4646
expPanic bool
4747
}{
4848
{
@@ -52,19 +52,19 @@ func (s *GenesisTestSuite) TestGenesis() {
5252
},
5353
{
5454
name: "custom genesis - feeshare disabled",
55-
genesis: devgastypes.GenesisState{
56-
Params: devgastypes.ModuleParams{
55+
genesis: devgas.GenesisState{
56+
Params: devgas.ModuleParams{
5757
EnableFeeShare: false,
58-
DeveloperShares: devgastypes.DefaultDeveloperShares,
58+
DeveloperShares: devgas.DefaultDeveloperShares,
5959
AllowedDenoms: []string{"unibi"},
6060
},
6161
},
6262
expPanic: false,
6363
},
6464
{
6565
name: "custom genesis - feeshare enabled, 0% developer shares",
66-
genesis: devgastypes.GenesisState{
67-
Params: devgastypes.ModuleParams{
66+
genesis: devgas.GenesisState{
67+
Params: devgas.ModuleParams{
6868
EnableFeeShare: true,
6969
DeveloperShares: math.LegacyNewDecWithPrec(0, 2),
7070
AllowedDenoms: []string{"unibi"},
@@ -74,8 +74,8 @@ func (s *GenesisTestSuite) TestGenesis() {
7474
},
7575
{
7676
name: "custom genesis - feeshare enabled, 100% developer shares",
77-
genesis: devgastypes.GenesisState{
78-
Params: devgastypes.ModuleParams{
77+
genesis: devgas.GenesisState{
78+
Params: devgas.ModuleParams{
7979
EnableFeeShare: true,
8080
DeveloperShares: math.LegacyNewDecWithPrec(100, 2),
8181
AllowedDenoms: []string{"unibi"},
@@ -85,13 +85,13 @@ func (s *GenesisTestSuite) TestGenesis() {
8585
},
8686
{
8787
name: "custom genesis - feeshare enabled, all denoms allowed",
88-
genesis: devgastypes.GenesisState{
89-
Params: devgastypes.ModuleParams{
88+
genesis: devgas.GenesisState{
89+
Params: devgas.ModuleParams{
9090
EnableFeeShare: true,
9191
DeveloperShares: math.LegacyNewDecWithPrec(10, 2),
9292
AllowedDenoms: []string{},
9393
},
94-
FeeShare: []devgastypes.FeeShare{
94+
FeeShare: []devgas.FeeShare{
9595
{
9696
ContractAddress: randomAddr,
9797
DeployerAddress: randomAddr,
@@ -103,7 +103,7 @@ func (s *GenesisTestSuite) TestGenesis() {
103103
},
104104
{
105105
name: "empty genesis",
106-
genesis: devgastypes.GenesisState{},
106+
genesis: devgas.GenesisState{},
107107
expPanic: true,
108108
},
109109
}
@@ -114,17 +114,17 @@ func (s *GenesisTestSuite) TestGenesis() {
114114

115115
if tc.expPanic {
116116
s.Require().Panics(func() {
117-
devgas.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
117+
devgasv1.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
118118
})
119119
} else {
120120
s.Require().NotPanics(func() {
121-
devgas.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
121+
devgasv1.InitGenesis(s.ctx, s.app.DevGasKeeper, tc.genesis)
122122
})
123123

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

127-
gen := devgas.ExportGenesis(s.ctx, s.app.DevGasKeeper)
127+
gen := devgasv1.ExportGenesis(s.ctx, s.app.DevGasKeeper)
128128
s.NoError(gen.Validate())
129129
}
130130
})

0 commit comments

Comments
 (0)