github.com/Finschia/finschia-sdk@v0.48.1/x/foundation/keeper/internal/proposal_handler_test.go (about) 1 package internal_test 2 3 import ( 4 "github.com/Finschia/finschia-sdk/testutil/testdata" 5 sdk "github.com/Finschia/finschia-sdk/types" 6 authtypes "github.com/Finschia/finschia-sdk/x/auth/types" 7 "github.com/Finschia/finschia-sdk/x/foundation" 8 govtypes "github.com/Finschia/finschia-sdk/x/gov/types" 9 ) 10 11 func (s *KeeperTestSuite) TestProposalHandler() { 12 testCases := map[string]struct { 13 malleate func(ctx sdk.Context) 14 msg sdk.Msg 15 valid bool 16 require func(ctx sdk.Context) 17 }{ 18 "valid": { 19 malleate: func(ctx sdk.Context) { 20 s.impl.SetCensorship(ctx, foundation.Censorship{ 21 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 22 Authority: foundation.CensorshipAuthorityGovernance, 23 }) 24 }, 25 msg: &foundation.MsgUpdateCensorship{ 26 Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), 27 Censorship: foundation.Censorship{ 28 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 29 Authority: foundation.CensorshipAuthorityUnspecified, 30 }, 31 }, 32 valid: true, 33 require: func(ctx sdk.Context) { 34 s.Require().False(s.impl.IsCensoredMessage(ctx, sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)))) 35 }, 36 }, 37 "bad signer": { 38 malleate: func(ctx sdk.Context) { 39 s.impl.SetCensorship(ctx, foundation.Censorship{ 40 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 41 Authority: foundation.CensorshipAuthorityGovernance, 42 }) 43 }, 44 msg: &foundation.MsgUpdateCensorship{ 45 Authority: s.impl.GetAuthority(), 46 Censorship: foundation.Censorship{ 47 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 48 Authority: foundation.CensorshipAuthorityUnspecified, 49 }, 50 }, 51 }, 52 "message type not allowed": { 53 malleate: func(ctx sdk.Context) { 54 s.impl.SetCensorship(ctx, foundation.Censorship{ 55 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 56 Authority: foundation.CensorshipAuthorityGovernance, 57 }) 58 }, 59 msg: newMsgCreateDog("doge"), 60 }, 61 "no handler found": { 62 malleate: func(ctx sdk.Context) { 63 s.impl.SetCensorship(ctx, foundation.Censorship{ 64 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 65 Authority: foundation.CensorshipAuthorityGovernance, 66 }) 67 }, 68 msg: testdata.NewTestMsg(authtypes.NewModuleAddress(govtypes.ModuleName)), 69 }, 70 "message execution failed": { 71 malleate: func(ctx sdk.Context) { 72 s.impl.SetCensorship(ctx, foundation.Censorship{ 73 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 74 Authority: foundation.CensorshipAuthorityGovernance, 75 }) 76 }, 77 msg: &foundation.MsgUpdateCensorship{ 78 Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), 79 Censorship: foundation.Censorship{ 80 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 81 Authority: foundation.CensorshipAuthorityFoundation, 82 }, 83 }, 84 }, 85 "authority is not x/gov yet": { 86 msg: &foundation.MsgUpdateCensorship{ 87 Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), 88 Censorship: foundation.Censorship{ 89 MsgTypeUrl: sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)), 90 Authority: foundation.CensorshipAuthorityUnspecified, 91 }, 92 }, 93 }, 94 } 95 96 for name, tc := range testCases { 97 s.Run(name, func() { 98 ctx, _ := s.ctx.CacheContext() 99 if tc.malleate != nil { 100 tc.malleate(ctx) 101 } 102 103 proposal := &foundation.FoundationExecProposal{} 104 proposal.SetMessages([]sdk.Msg{tc.msg}) 105 106 err := s.proposalHandler(ctx, proposal) 107 if !tc.valid { 108 s.Require().Error(err) 109 return 110 } 111 s.Require().NoError(err) 112 113 tc.require(ctx) 114 }) 115 } 116 }