Skip to content

Commit

Permalink
Merge branch 'cosmos-sdk-v0.47' of https://github.com/bandprotocol/chain
Browse files Browse the repository at this point in the history
 into add-simulation-oracle
  • Loading branch information
RogerKSI committed Sep 25, 2023
2 parents b6364ab + 275bc41 commit cf8a49c
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 11 deletions.
73 changes: 67 additions & 6 deletions x/globalfee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *IntegrationTestSuite) TestParams() {
testCases := []struct {
name string
input types.Params
expectErr bool
expectErr string
}{
{
name: "set full valid params",
Expand All @@ -63,18 +63,79 @@ func (s *IntegrationTestSuite) TestParams() {
sdk.NewDecCoinFromDec("BLX", sdk.NewDecWithPrec(1, 3)),
),
},
expectErr: false,
expectErr: "",
},
{
name: "set empty coin",
input: types.Params{
MinimumGasPrices: sdk.DecCoins(nil),
},
expectErr: "",
},
{
name: "set invalid denom",
input: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "1AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(1)),
},
},
},
expectErr: "invalid denom",
},
{
name: "set negative value",
input: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(-1)),
},
},
},
expectErr: "is not positive",
},
{
name: "set duplicated denom",
input: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(1)),
},
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(2)),
},
},
},
expectErr: "duplicate denomination",
},
{
name: "set unsorted denom",
input: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "BBBB",
Amount: sdk.NewDecFromInt(sdk.NewInt(1)),
},
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(2)),
},
},
},
expectErr: "is not sorted",
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
expected := s.globalfeeKeeper.GetParams(s.ctx)
err := s.globalfeeKeeper.SetParams(s.ctx, tc.input)
if tc.expectErr {
s.Require().Error(err)
if tc.expectErr != "" {
s.Require().ErrorContains(err, tc.expectErr)
} else {
expected = tc.input
s.Require().NoError(err)
Expand Down
88 changes: 83 additions & 5 deletions x/globalfee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
testCases := []struct {
name string
request *types.MsgUpdateParams
expectErr bool
expectErr string
}{
{
name: "set invalid authority",
request: &types.MsgUpdateParams{
Authority: "foo",
},
expectErr: true,
expectErr: "invalid authority",
},
{
name: "set full valid params",
Expand All @@ -30,16 +30,94 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
),
},
},
expectErr: false,
expectErr: "",
},
{
name: "set empty coin",
request: &types.MsgUpdateParams{
Authority: s.globalfeeKeeper.GetAuthority(),
Params: types.Params{
MinimumGasPrices: sdk.DecCoins(nil),
},
},
expectErr: "",
},
{
name: "set invalid denom",
request: &types.MsgUpdateParams{
Authority: s.globalfeeKeeper.GetAuthority(),
Params: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "1AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(1)),
},
},
},
},
expectErr: "invalid denom",
},
{
name: "set negative value",
request: &types.MsgUpdateParams{
Authority: s.globalfeeKeeper.GetAuthority(),
Params: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(-1)),
},
},
},
},
expectErr: "is not positive",
},
{
name: "set duplicated denom",
request: &types.MsgUpdateParams{
Authority: s.globalfeeKeeper.GetAuthority(),
Params: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(1)),
},
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(2)),
},
},
},
},
expectErr: "duplicate denomination",
},
{
name: "set unsorted denom",
request: &types.MsgUpdateParams{
Authority: s.globalfeeKeeper.GetAuthority(),
Params: types.Params{
MinimumGasPrices: []sdk.DecCoin{
{
Denom: "BBBB",
Amount: sdk.NewDecFromInt(sdk.NewInt(1)),
},
{
Denom: "AAAA",
Amount: sdk.NewDecFromInt(sdk.NewInt(2)),
},
},
},
},
expectErr: "is not sorted",
},
}

for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
_, err := s.msgServer.UpdateParams(s.ctx, tc.request)
if tc.expectErr {
s.Require().Error(err)
if tc.expectErr != "" {
s.Require().ErrorContains(err, tc.expectErr)
} else {
s.Require().NoError(err)
}
Expand Down

0 comments on commit cf8a49c

Please sign in to comment.