diff --git a/tests/e2e/e2e_bounty_test.go b/tests/e2e/e2e_bounty_test.go index 5cd9206f7..6f4e674a2 100644 --- a/tests/e2e/e2e_bounty_test.go +++ b/tests/e2e/e2e_bounty_test.go @@ -11,7 +11,7 @@ import ( bountytypes "github.com/shentufoundation/shentu/v2/x/bounty/types" ) -func (s *IntegrationTestSuite) executeCreateProgram(c *chain, valIdx int, pid, name, desc, creatorAddr, fees string) { +func (s *IntegrationTestSuite) executeCreateProgram(c *chain, valIdx int, pid, name, detail, creatorAddr, fees string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -24,7 +24,7 @@ func (s *IntegrationTestSuite) executeCreateProgram(c *chain, valIdx int, pid, n "create-program", fmt.Sprintf("--%s=%s", bountycli.FlagProgramID, pid), fmt.Sprintf("--%s=%s", bountycli.FlagName, name), - fmt.Sprintf("--%s=%s", bountycli.FlagDesc, desc), + fmt.Sprintf("--%s=%s", bountycli.FlagDetail, detail), fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, creatorAddr), fmt.Sprintf("--%s=%s", sdkflags.FlagChainID, c.id), fmt.Sprintf("--%s=%s", sdkflags.FlagGas, "auto"), @@ -40,7 +40,7 @@ func (s *IntegrationTestSuite) executeCreateProgram(c *chain, valIdx int, pid, n s.T().Logf("%s successfully create program", creatorAddr) } -func (s *IntegrationTestSuite) executeOpenProgram(c *chain, valIdx int, pid, creatorAddr, fees string) { +func (s *IntegrationTestSuite) executeActivateProgram(c *chain, valIdx int, pid, creatorAddr, fees string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -50,7 +50,7 @@ func (s *IntegrationTestSuite) executeOpenProgram(c *chain, valIdx int, pid, cre shentuBinary, txCommand, bountytypes.ModuleName, - "open-program", + "activate-program", fmt.Sprintf("%s", pid), fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, creatorAddr), fmt.Sprintf("--%s=%s", sdkflags.FlagChainID, c.id), @@ -67,7 +67,7 @@ func (s *IntegrationTestSuite) executeOpenProgram(c *chain, valIdx int, pid, cre s.T().Logf("%s successfully create program", creatorAddr) } -func (s *IntegrationTestSuite) executeSubmitFinding(c *chain, valIdx int, pid, fid, submitAddr, title, desc, fees string) { +func (s *IntegrationTestSuite) executeSubmitFinding(c *chain, valIdx int, pid, fid, submitAddr, title, desc, poc, detail, fees string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -81,8 +81,10 @@ func (s *IntegrationTestSuite) executeSubmitFinding(c *chain, valIdx int, pid, f fmt.Sprintf("--%s=%s", bountycli.FlagProgramID, pid), fmt.Sprintf("--%s=%s", bountycli.FlagFindingID, fid), fmt.Sprintf("--%s=%s", bountycli.FlagFindingTitle, title), - fmt.Sprintf("--%s=%s", bountycli.FlagDesc, desc), - fmt.Sprintf("--%s=%d", bountycli.FlagFindingSeverityLevel, bountytypes.SeverityLevelMedium), + fmt.Sprintf("--%s=%s", bountycli.FlagFindingDescription, desc), + fmt.Sprintf("--%s=%s", bountycli.FlagFindingProofOfContent, poc), + fmt.Sprintf("--%s=%s", bountycli.FlagDetail, detail), + fmt.Sprintf("--%s=%d", bountycli.FlagFindingSeverityLevel, bountytypes.Medium), fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, submitAddr), fmt.Sprintf("--%s=%s", sdkflags.FlagChainID, c.id), fmt.Sprintf("--%s=%s", sdkflags.FlagGas, "auto"), @@ -97,7 +99,7 @@ func (s *IntegrationTestSuite) executeSubmitFinding(c *chain, valIdx int, pid, f s.T().Logf("%s successfully submit finding", submitAddr) } -func (s *IntegrationTestSuite) executeAcceptFinding(c *chain, valIdx int, findingId, hostAddr, fees string) { +func (s *IntegrationTestSuite) executeConfirmFinding(c *chain, valIdx int, findingId, hostAddr, fees string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -107,7 +109,7 @@ func (s *IntegrationTestSuite) executeAcceptFinding(c *chain, valIdx int, findin shentuBinary, txCommand, bountytypes.ModuleName, - "accept-finding", + "confirm-finding", fmt.Sprintf("%s", findingId), fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, hostAddr), fmt.Sprintf("--%s=%s", sdkflags.FlagChainID, c.id), @@ -124,7 +126,7 @@ func (s *IntegrationTestSuite) executeAcceptFinding(c *chain, valIdx int, findin s.T().Logf("%s successfully accept finding", hostAddr) } -func (s *IntegrationTestSuite) executeRejectFinding(c *chain, valIdx int, findingId, hostAddr, fees string) { +func (s *IntegrationTestSuite) executeCloseFinding(c *chain, valIdx int, findingId, hostAddr, fees string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -134,7 +136,7 @@ func (s *IntegrationTestSuite) executeRejectFinding(c *chain, valIdx int, findin shentuBinary, txCommand, bountytypes.ModuleName, - "reject-finding", + "close-finding", fmt.Sprintf("%s", findingId), fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, hostAddr), fmt.Sprintf("--%s=%s", sdkflags.FlagChainID, c.id), diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 624349570..0ec4a50c5 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -318,10 +318,10 @@ func (s *IntegrationTestSuite) TestBounty() { ) }) - s.Run("open_program", func() { + s.Run("activate_program", func() { pid := string(rune(bountyProgramCounter)) s.T().Logf("Open program %s on chain %s", pid, s.chainA.id) - s.executeOpenProgram(s.chainA, 0, pid, validatorAAddr.String(), feesAmountCoin.String()) + s.executeActivateProgram(s.chainA, 0, pid, validatorAAddr.String(), feesAmountCoin.String()) s.Require().Eventually( func() bool { rsp, err := queryBountyProgram(chainAAPIEndpoint, pid) @@ -338,11 +338,8 @@ func (s *IntegrationTestSuite) TestBounty() { pid := string(rune(bountyProgramCounter)) fid := string(rune(bountyFindingCounter)) s.T().Logf("Submit finding %d on program %d chain %s", bountyFindingCounter, bountyProgramCounter, s.chainA.id) - var ( - findingTitle = "finding-title" - findingDesc = "finding-desc" - ) - s.executeSubmitFinding(s.chainA, 0, pid, fid, accountBAddr.String(), findingTitle, findingDesc, feesAmountCoin.String()) + title, desc, poc, detail := "title", "desc", "poc", "detail" + s.executeSubmitFinding(s.chainA, 0, pid, fid, accountBAddr.String(), title, desc, poc, detail, feesAmountCoin.String()) s.Require().Eventually( func() bool { rsp, err := queryBountyFinding(chainAAPIEndpoint, pid) @@ -354,11 +351,11 @@ func (s *IntegrationTestSuite) TestBounty() { ) }) - s.Run("reject_finding", func() { + s.Run("close_finding", func() { fid := string(rune(bountyFindingCounter)) s.T().Logf("Accept finding %d on program %d chain %s", bountyFindingCounter, bountyProgramCounter, s.chainA.id) - s.executeRejectFinding(s.chainA, 0, fid, accountAAddr.String(), feesAmountCoin.String()) + s.executeCloseFinding(s.chainA, 0, fid, accountAAddr.String(), feesAmountCoin.String()) s.Require().Eventually( func() bool { rsp, err := queryBountyFinding(chainAAPIEndpoint, fid) @@ -370,10 +367,10 @@ func (s *IntegrationTestSuite) TestBounty() { ) }) - s.Run("accept_finding", func() { + s.Run("confirm_finding", func() { fid := string(rune(bountyFindingCounter)) s.T().Logf("Accept finding %d on program %d chain %s", bountyFindingCounter, bountyProgramCounter, s.chainA.id) - s.executeAcceptFinding(s.chainA, 0, fid, accountAAddr.String(), feesAmountCoin.String()) + s.executeConfirmFinding(s.chainA, 0, fid, accountAAddr.String(), feesAmountCoin.String()) s.Require().Eventually( func() bool { rsp, err := queryBountyFinding(chainAAPIEndpoint, fid) diff --git a/tests/e2e/genesis.go b/tests/e2e/genesis.go index 31c05a557..49fc57c95 100644 --- a/tests/e2e/genesis.go +++ b/tests/e2e/genesis.go @@ -5,6 +5,7 @@ import ( "fmt" "os" + "github.com/gogo/protobuf/proto" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/server" @@ -14,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" certtypes "github.com/shentufoundation/shentu/v2/x/cert/types" ) @@ -130,7 +132,23 @@ func addCertifierAccount(path, moniker string, accAddr sdk.AccAddress) error { certifier := certtypes.Certifier{ Address: accAddr.String(), } + + content := certtypes.AssembleContent("bountyadmin", accAddr.String()) + msg, ok := content.(proto.Message) + if !ok { + panic(fmt.Errorf("%T does not implement proto.Message", content)) + } + any, err := codectypes.NewAnyWithValue(msg) + certificate := certtypes.Certificate{ + CertificateId: 1, + Content: any, + CompilationContent: nil, + Description: "", + Certifier: accAddr.String(), + } + certGenState.Certifiers = append(certGenState.Certifiers, certifier) + certGenState.Certificates = append(certGenState.Certificates, certificate) certGenStateBz, err := cdc.MarshalJSON(&certGenState) if err != nil { diff --git a/x/bounty/client/cli/flags.go b/x/bounty/client/cli/flags.go index 31c14d803..e006dc899 100644 --- a/x/bounty/client/cli/flags.go +++ b/x/bounty/client/cli/flags.go @@ -4,15 +4,14 @@ const ( FlagProgramID = "program-id" FlagFindingID = "finding-id" - FlagName = "name" - FlagMembers = "members" - - FlagFindingTitle = "title" - FlagFindingSeverityLevel = "severity-level" - FlagFindingDescription = "description" - FlagFindingPoc = "poc" - FlagFindingAddress = "finding-address" - FlagSubmitterAddress = "submitter-address" - + FlagName = "name" FlagDetail = "detail" + + FlagFindingTitle = "title" + FlagFindingSeverityLevel = "severity-level" + FlagFindingDescription = "desc" + FlagFindingProofOfContent = "poc" + FlagFindingFingerPrint = "fingerPrint," + FlagFindingAddress = "finding-address" + FlagSubmitterAddress = "submitter-address" ) diff --git a/x/bounty/client/cli/tx.go b/x/bounty/client/cli/tx.go index cb56417b2..ef5f47e5b 100644 --- a/x/bounty/client/cli/tx.go +++ b/x/bounty/client/cli/tx.go @@ -71,7 +71,6 @@ func NewCreateProgramCmd() *cobra.Command { cmd.Flags().String(FlagProgramID, "", "The program's id") cmd.Flags().String(FlagName, "", "The program's name") cmd.Flags().String(FlagDetail, "", "The program's detail") - cmd.Flags().StringArray(FlagMembers, []string{}, "") flags.AddTxFlagsToCmd(cmd) _ = cmd.MarkFlagRequired(FlagProgramID) @@ -115,7 +114,6 @@ func NewEditProgramCmd() *cobra.Command { cmd.Flags().String(FlagProgramID, "", "The program's id") cmd.Flags().String(FlagName, "", "The program's name") cmd.Flags().String(FlagDetail, "", "The program's detail") - cmd.Flags().StringArray(FlagMembers, []string{}, "") flags.AddTxFlagsToCmd(cmd) _ = cmd.MarkFlagRequired(FlagProgramID) @@ -126,9 +124,9 @@ func NewEditProgramCmd() *cobra.Command { func NewActivateProgramCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "open-program [program-id]", + Use: "activate-program [program-id]", Args: cobra.ExactArgs(1), - Short: "open the program", + Short: "activate the program", RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -204,14 +202,13 @@ func NewSubmitFindingCmd() *cobra.Command { if err != nil { return err } - poc, err := cmd.Flags().GetString(FlagFindingPoc) + poc, err := cmd.Flags().GetString(FlagFindingProofOfContent) if err != nil { return err } hash := sha256.Sum256([]byte(desc + poc + submitAddr.String())) - hashString := hex.EncodeToString(hash[:]) - msg := types.NewMsgSubmitFinding(pid, fid, title, detail, hashString, submitAddr, types.SeverityLevel(severityLevel)) + msg := types.NewMsgSubmitFinding(pid, fid, title, detail, hex.EncodeToString(hash[:]), submitAddr, types.SeverityLevel(severityLevel)) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } @@ -219,7 +216,9 @@ func NewSubmitFindingCmd() *cobra.Command { cmd.Flags().String(FlagProgramID, "", "The program's ID") cmd.Flags().String(FlagFindingID, "", "The finding's ID") cmd.Flags().String(FlagFindingTitle, "", "The finding's title") - cmd.Flags().String(FlagDetail, "", "The finding's description") + cmd.Flags().String(FlagFindingDescription, "", "The finding's description") + cmd.Flags().String(FlagFindingProofOfContent, "", "The finding's proof of content") + cmd.Flags().String(FlagDetail, "", "The finding's detail") cmd.Flags().Int32(FlagFindingSeverityLevel, 0, "The finding's severity level") flags.AddTxFlagsToCmd(cmd) @@ -228,7 +227,7 @@ func NewSubmitFindingCmd() *cobra.Command { _ = cmd.MarkFlagRequired(FlagFindingID) _ = cmd.MarkFlagRequired(FlagFindingTitle) _ = cmd.MarkFlagRequired(FlagFindingDescription) - _ = cmd.MarkFlagRequired(FlagFindingPoc) + _ = cmd.MarkFlagRequired(FlagFindingProofOfContent) return cmd } @@ -269,7 +268,7 @@ func NewEditFindingCmd() *cobra.Command { if err != nil { return err } - poc, err := cmd.Flags().GetString(FlagFindingPoc) + poc, err := cmd.Flags().GetString(FlagFindingProofOfContent) if err != nil { return err } @@ -284,8 +283,10 @@ func NewEditFindingCmd() *cobra.Command { cmd.Flags().String(FlagProgramID, "", "The program's ID") cmd.Flags().String(FlagFindingID, "", "The finding's ID") cmd.Flags().String(FlagFindingTitle, "", "The finding's title") + cmd.Flags().String(FlagFindingDescription, "", "The finding's description") + cmd.Flags().String(FlagFindingProofOfContent, "", "The finding's proof of content") cmd.Flags().String(FlagDetail, "", "The finding's detail") - cmd.Flags().Int32(FlagFindingSeverityLevel, 8, "The finding's severity level") + cmd.Flags().Int32(FlagFindingSeverityLevel, 0, "The finding's severity level") flags.AddTxFlagsToCmd(cmd) _ = cmd.MarkFlagRequired(flags.FlagFrom) @@ -304,7 +305,7 @@ func NewConfirmFinding() *cobra.Command { Long: strings.TrimSpace( fmt.Sprintf(`Host accept a finding for a program.Meantime, you can also add some comments, which will be encrypted. Example: -$ %s tx bounty accept-finding 1 --comment "Looks good to me" +$ %s tx bounty confirm-finding 1 --comment "Looks good to me" `, version.AppName, ), @@ -325,9 +326,11 @@ func ConfirmFinding(cmd *cobra.Command, args []string) error { return err } + fingerPrint, err := cmd.Flags().GetString(FlagFindingFingerPrint) + // Get host address hostAddr := clientCtx.GetFromAddress() - msg := types.NewMsgConfirmFinding(args[0], hostAddr) + msg := types.NewMsgConfirmFinding(args[0], fingerPrint, hostAddr) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } @@ -368,7 +371,7 @@ func NewReleaseFindingCmd() *cobra.Command { if err != nil { return err } - poc, err := cmd.Flags().GetString(FlagFindingPoc) + poc, err := cmd.Flags().GetString(FlagFindingProofOfContent) if err != nil { return err } @@ -378,11 +381,11 @@ func NewReleaseFindingCmd() *cobra.Command { } cmd.Flags().String(FlagFindingDescription, "", "The finding's description") - cmd.Flags().String(FlagFindingPoc, "", "The finding's poc") + cmd.Flags().String(FlagFindingProofOfContent, "", "The finding's poc") flags.AddTxFlagsToCmd(cmd) _ = cmd.MarkFlagRequired(FlagFindingDescription) - _ = cmd.MarkFlagRequired(FlagFindingPoc) + _ = cmd.MarkFlagRequired(FlagFindingProofOfContent) return cmd } diff --git a/x/bounty/keeper/finding.go b/x/bounty/keeper/finding.go index e160016da..50f195a5b 100644 --- a/x/bounty/keeper/finding.go +++ b/x/bounty/keeper/finding.go @@ -47,7 +47,7 @@ func (k Keeper) GetPidFindingIDList(ctx sdk.Context, pid string) ([]string, erro findingIDs := store.Get(types.GetProgramIDFindingListKey(pid)) if findingIDs == nil { - return nil, types.ErrProgramFindingListEmpty + return []string{}, nil } findingIDList, err := BytesToStrings(findingIDs) @@ -60,11 +60,7 @@ func (k Keeper) GetPidFindingIDList(ctx sdk.Context, pid string) ([]string, erro func (k Keeper) AppendFidToFidList(ctx sdk.Context, pid, fid string) error { fids, err := k.GetPidFindingIDList(ctx, pid) if err != nil { - if err == types.ErrProgramFindingListEmpty { - fids = []string{} - } else { - return err - } + return err } fids = append(fids, fid) diff --git a/x/bounty/keeper/grpc_query_test.go b/x/bounty/keeper/grpc_query_test.go index ac5bcf2ab..2dd6505f8 100644 --- a/x/bounty/keeper/grpc_query_test.go +++ b/x/bounty/keeper/grpc_query_test.go @@ -155,7 +155,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryFinding() { "valid request", func() { req = &types.QueryFindingRequest{FindingId: "1"} - suite.InitSubmitFinding("1", "1") + suite.InitSubmitFinding(pid, "1") }, true, }, @@ -163,7 +163,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryFinding() { "valid request", func() { req = &types.QueryFindingRequest{FindingId: "2"} - suite.InitSubmitFinding("1", "2") + suite.InitSubmitFinding(pid, "2") ctx := sdk.WrapSDKContext(suite.ctx) suite.msgServer.ReleaseFinding(ctx, types.NewMsgReleaseFinding("2", "desc", "poc", suite.address[0])) diff --git a/x/bounty/keeper/msg_server.go b/x/bounty/keeper/msg_server.go index 28e80aca3..1cbb635a5 100644 --- a/x/bounty/keeper/msg_server.go +++ b/x/bounty/keeper/msg_server.go @@ -344,12 +344,13 @@ func (k msgServer) CloseFinding(goCtx context.Context, msg *types.MsgCloseFindin // check operator // program, certificate, finding owner - if finding.SubmitterAddress != msg.OperatorAddress && !k.certKeeper.IsBountyAdmin(ctx, operatorAddr) && finding.SubmitterAddress != program.AdminAddress { + if finding.SubmitterAddress != msg.OperatorAddress && !k.certKeeper.IsBountyAdmin(ctx, operatorAddr) && program.AdminAddress != msg.OperatorAddress { return nil, types.ErrFindingOperatorNotAllowed } k.DeleteFidFromFidList(ctx, finding.ProgramId, finding.FindingId) - k.DeleteFinding(ctx, finding.FindingId) + finding.Status = types.FindingStatusClosed + k.SetFinding(ctx, finding) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( diff --git a/x/bounty/keeper/msg_server_test.go b/x/bounty/keeper/msg_server_test.go index 9f0f06f8b..ce4b70ec9 100644 --- a/x/bounty/keeper/msg_server_test.go +++ b/x/bounty/keeper/msg_server_test.go @@ -1,11 +1,14 @@ package keeper_test import ( + "crypto/sha256" + "encoding/hex" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" + shentuapp "github.com/shentufoundation/shentu/v2/app" "github.com/shentufoundation/shentu/v2/x/bounty/types" ) @@ -70,6 +73,7 @@ func (suite *KeeperTestSuite) TestSubmitFinding() { } pid := uuid.NewString() + fid := uuid.NewString() suite.InitCreateProgram(pid) suite.InitActivateProgram(pid) @@ -83,7 +87,7 @@ func (suite *KeeperTestSuite) TestSubmitFinding() { msgSubmitFindings: []types.MsgSubmitFinding{ { ProgramId: pid, - FindingId: "1", + FindingId: fid, Title: "Test bug 1", Detail: "detail", SubmitterAddress: suite.address[0].String(), @@ -95,12 +99,12 @@ func (suite *KeeperTestSuite) TestSubmitFinding() { shouldPass: true, }, }, - {"Submit finding(2) -> submit: Simple", + {"Submit finding(2) -> fid repeat", args{ msgSubmitFindings: []types.MsgSubmitFinding{ { - ProgramId: "Not exist pid", - FindingId: "1", + ProgramId: pid, + FindingId: fid, Title: "Test bug 1", Detail: "detail", SubmitterAddress: suite.address[0].String(), @@ -112,7 +116,7 @@ func (suite *KeeperTestSuite) TestSubmitFinding() { shouldPass: false, }, }, - {"Submit finding(3) -> submit: Simple", + {"Submit finding(3) -> pid not exist", args{ msgSubmitFindings: []types.MsgSubmitFinding{ { @@ -151,11 +155,19 @@ func (suite *KeeperTestSuite) TestSubmitFinding() { } func (suite *KeeperTestSuite) TestConfirmFinding() { - pid, fid := "1", "1" + pid, fid := uuid.NewString(), uuid.NewString() suite.InitCreateProgram(pid) suite.InitActivateProgram(pid) suite.InitSubmitFinding(pid, fid) + finding, found := suite.keeper.GetFinding(suite.ctx, fid) + suite.Require().True(found) + + // fingerprint calculate + cdc := shentuapp.MakeEncodingConfig().Marshaler + bz := cdc.MustMarshal(&finding) + hash := sha256.Sum256(bz) + testCases := []struct { name string req *types.MsgConfirmFinding @@ -171,6 +183,7 @@ func (suite *KeeperTestSuite) TestConfirmFinding() { &types.MsgConfirmFinding{ FindingId: fid, OperatorAddress: suite.address[0].String(), + FingerPrint: hex.EncodeToString(hash[:]), }, true, }, @@ -195,10 +208,10 @@ func (suite *KeeperTestSuite) TestConfirmFinding() { } func (suite *KeeperTestSuite) TestCloseFinding() { - pid, fid := "1", "1" + pid, fid := uuid.NewString(), uuid.NewString() suite.InitCreateProgram(pid) suite.InitActivateProgram(pid) - findingId := suite.InitSubmitFinding(pid, fid) + suite.InitSubmitFinding(pid, fid) testCases := []struct { name string @@ -211,9 +224,9 @@ func (suite *KeeperTestSuite) TestCloseFinding() { false, }, { - "valid request => comment is empty", + "valid request", &types.MsgCloseFinding{ - FindingId: "1", + FindingId: fid, OperatorAddress: suite.address[0].String(), }, true, @@ -224,8 +237,7 @@ func (suite *KeeperTestSuite) TestCloseFinding() { suite.Run(fmt.Sprintf("Case %s", testCase.name), func() { ctx := sdk.WrapSDKContext(suite.ctx) _, err := suite.msgServer.CloseFinding(ctx, testCase.req) - - finding, _ := suite.keeper.GetFinding(suite.ctx, findingId) + finding, _ := suite.keeper.GetFinding(suite.ctx, fid) if testCase.expPass { suite.Require().NoError(err) @@ -238,6 +250,52 @@ func (suite *KeeperTestSuite) TestCloseFinding() { } } +func (suite *KeeperTestSuite) TestReleaseFinding() { + pid, fid := uuid.NewString(), uuid.NewString() + suite.InitCreateProgram(pid) + suite.InitActivateProgram(pid) + suite.InitSubmitFinding(pid, fid) + + testCases := []struct { + name string + req *types.MsgReleaseFinding + expPass bool + }{ + { + "empty request", + &types.MsgReleaseFinding{}, + false, + }, + { + "valid request", + &types.MsgReleaseFinding{ + FindingId: fid, + OperatorAddress: suite.address[0].String(), + Description: "desc", + ProofOfConcept: "poc", + }, + true, + }, + } + + for _, testCase := range testCases { + suite.Run(fmt.Sprintf("Case %s", testCase.name), func() { + ctx := sdk.WrapSDKContext(suite.ctx) + _, err := suite.msgServer.ReleaseFinding(ctx, testCase.req) + + finding, _ := suite.keeper.GetFinding(suite.ctx, fid) + + if testCase.expPass { + suite.Require().NoError(err) + suite.Require().Equal(finding.Description, "desc") + } else { + suite.Require().Error(err) + suite.Require().Equal(finding.Status, types.FindingStatusSubmitted) + } + }) + } +} + func (suite *KeeperTestSuite) InitCreateProgram(pid string) { msgCreateProgram := &types.MsgCreateProgram{ ProgramId: pid, @@ -263,11 +321,14 @@ func (suite *KeeperTestSuite) InitActivateProgram(pid string) { } func (suite *KeeperTestSuite) InitSubmitFinding(pid, fid string) string { + desc, poc := "desc", "poc" + hash := sha256.Sum256([]byte(desc + poc + suite.address[0].String())) + msgSubmitFinding := &types.MsgSubmitFinding{ ProgramId: pid, FindingId: fid, Title: "title", - FindingHash: "finding hash", + FindingHash: hex.EncodeToString(hash[:]), SubmitterAddress: suite.address[0].String(), SeverityLevel: types.Critical, Detail: "detail", diff --git a/x/bounty/keeper/program_test.go b/x/bounty/keeper/program_test.go index c8d1a7b68..7df5df338 100644 --- a/x/bounty/keeper/program_test.go +++ b/x/bounty/keeper/program_test.go @@ -74,7 +74,7 @@ func (suite *KeeperTestSuite) TestOpenCloseProgram() { suite.Require().Equal(true, isExist) suite.Require().Equal(program.ProgramId, storedProgram.ProgramId) - isCert := suite.app.CertKeeper.IsCertifier(suite.ctx, suite.address[3]) + isCert := suite.app.CertKeeper.IsBountyAdmin(suite.ctx, suite.address[3]) suite.Require().True(isCert) // normal addr open program diff --git a/x/bounty/types/msgs.go b/x/bounty/types/msgs.go index 221dbe524..142037867 100644 --- a/x/bounty/types/msgs.go +++ b/x/bounty/types/msgs.go @@ -296,10 +296,11 @@ func (msg MsgCloseProgram) ValidateBasic() error { return nil } -func NewMsgConfirmFinding(findingID string, hostAddr sdk.AccAddress) *MsgConfirmFinding { +func NewMsgConfirmFinding(findingID, fingerPrint string, hostAddr sdk.AccAddress) *MsgConfirmFinding { return &MsgConfirmFinding{ FindingId: findingID, OperatorAddress: hostAddr.String(), + FingerPrint: fingerPrint, } } diff --git a/x/bounty/types/msgs_test.go b/x/bounty/types/msgs_test.go index 7c0417b3b..591cf47cb 100644 --- a/x/bounty/types/msgs_test.go +++ b/x/bounty/types/msgs_test.go @@ -125,7 +125,7 @@ func TestMsgConfirmFinding(t *testing.T) { } for _, tc := range testCases { - msg := NewMsgConfirmFinding(tc.fid, tc.addr) + msg := NewMsgConfirmFinding(tc.fid, "", tc.addr) require.Equal(t, msg.Route(), RouterKey) require.Equal(t, msg.Type(), TypeMsgConfirmFinding)