Skip to content

Commit

Permalink
Add unit test for delete proposal. (#121)
Browse files Browse the repository at this point in the history
* Add unit test for delete proposal.

* Add testcase delete not exists host zone config for TestDeleteHostZoneProposal.
  • Loading branch information
tnv1 authored Jan 16, 2024
1 parent 4e33a53 commit 8b0c62c
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions x/feeabs/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,83 @@ func (s *KeeperTestSuite) TestAddHostZoneProposal() {
})
}
}

func (s *KeeperTestSuite) TestDeleteHostZoneProposal() {
s.SetupTest()
addrs := simtestutil.AddTestAddrs(s.feeAbsApp.BankKeeper, s.feeAbsApp.StakingKeeper, s.ctx, 10, valTokens)

hostChainConfig := types.HostChainFeeAbsConfig{
IbcDenom: "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518",
OsmosisPoolTokenDenomIn: "ibc/9117A26BA81E29FA4F78F57DC2BD90CD3D26848101BA880445F119B22A1E254E",
PoolId: 1,
Frozen: false,
}

addProposal := &types.AddHostZoneProposal{
Title: "AddHostZoneProposal Title",
Description: "AddHostZoneProposal Description",
HostChainConfig: &hostChainConfig,
}

legacyProposal, err := govv1types.NewLegacyContent(addProposal, authtypes.NewModuleAddress(govtypes.ModuleName).String())
s.Require().NoError(err)

// Store proposal
_, err = s.govKeeper.SubmitProposal(s.ctx, []sdk.Msg{legacyProposal}, "", "", "", addrs[0])
s.Require().NoError(err)

// Execute proposal
handler := s.govKeeper.LegacyRouter().GetRoute(addProposal.ProposalRoute())
err = handler(s.ctx, addProposal)
s.Require().NoError(err)

hostChainConfig, found := s.feeAbsKeeper.GetHostZoneConfig(s.ctx, hostChainConfig.IbcDenom)
s.Require().True(found)
s.Require().Equal(hostChainConfig, hostChainConfig)

testCases := []struct {
desc string
deleteProposal *types.DeleteHostZoneProposal
shouldError bool
}{
{
desc: "should success when delete an exists host zone config.",
deleteProposal: &types.DeleteHostZoneProposal{
Title: "DeleteHostZoneProposal Title",
Description: "DeleteHostZoneProposal Description",
IbcDenom: "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518",
},
shouldError: false,
},
{
deleteProposal: &types.DeleteHostZoneProposal{
Title: "DeleteHostZoneProposal Title",
Description: "DeleteHostZoneProposal Description",
IbcDenom: "ibc/00000",
},
desc: "should error when delete a not exists host zone config.",
shouldError: true,
},
}

for _, tc := range testCases {
s.Run(tc.desc, func() {
legacyProposal, err := govv1types.NewLegacyContent(tc.deleteProposal, authtypes.NewModuleAddress(govtypes.ModuleName).String())
s.Require().NoError(err)

// Store proposal
_, err = s.govKeeper.SubmitProposal(s.ctx, []sdk.Msg{legacyProposal}, "", "", "", addrs[0])
if !tc.shouldError {
s.Require().NoError(err)
} else {
s.Require().Error(err)
return
}

// Execute proposal
handler = s.govKeeper.LegacyRouter().GetRoute(addProposal.ProposalRoute())
err = handler(s.ctx, tc.deleteProposal)
s.Require().NoError(err)
})
}
}

0 comments on commit 8b0c62c

Please sign in to comment.