From 8b0c62c0350b36dc9629c588bffc4babca388643 Mon Sep 17 00:00:00 2001 From: Tien Nguyen Date: Tue, 16 Jan 2024 21:01:16 +0700 Subject: [PATCH] Add unit test for delete proposal. (#121) * Add unit test for delete proposal. * Add testcase delete not exists host zone config for TestDeleteHostZoneProposal. --- x/feeabs/keeper/proposal_test.go | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/x/feeabs/keeper/proposal_test.go b/x/feeabs/keeper/proposal_test.go index 6ed11fc9..446beadf 100644 --- a/x/feeabs/keeper/proposal_test.go +++ b/x/feeabs/keeper/proposal_test.go @@ -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) + }) + } +}