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

test: Unit tests for global fee module #1858

Merged
merged 11 commits into from
Nov 15, 2022
62 changes: 62 additions & 0 deletions x/globalfee/types/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package types

import (
"cosmossdk.io/math"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

func TestDefaultParams(t *testing.T) {
p := DefaultParams()
require.EqualValues(t, p.MinimumGasPrices, sdk.DecCoins{})
}

func Test_validateParams(t *testing.T) {
tests := map[string]struct {
coins interface{} // not sdk.DeCoins, but Decoins defined in glboalfee
expectErr bool
}{
"DefaultParams, pass": {
DefaultParams().MinimumGasPrices,
false,
},
"DecCoins conversion fails, fail": {
sdk.Coins{sdk.NewCoin("photon", math.OneInt())},
true,
},
"coins amounts are zero, pass": {
sdk.DecCoins{
sdk.NewDecCoin("atom", math.ZeroInt()),
sdk.NewDecCoin("photon", math.ZeroInt()),
},
false,
},
"duplicate coins denoms, fail": {
sdk.DecCoins{
sdk.NewDecCoin("photon", math.OneInt()),
sdk.NewDecCoin("photon", math.OneInt()),
},
true,
},
"coins are not sorted by denom alphabetically, fail": {
sdk.DecCoins{
sdk.NewDecCoin("photon", math.OneInt()),
sdk.NewDecCoin("atom", math.OneInt()),
},
true,
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
err := validateMinimumGasPrices(test.coins)
if test.expectErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}