Skip to content

Commit

Permalink
fix e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
skyargos committed Nov 13, 2023
1 parent bf820a4 commit e493a5f
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 74 deletions.
24 changes: 13 additions & 11 deletions tests/e2e/e2e_bounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"),
Expand All @@ -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()

Expand All @@ -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),
Expand All @@ -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()

Expand All @@ -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"),
Expand All @@ -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()

Expand All @@ -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),
Expand All @@ -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()

Expand All @@ -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),
Expand Down
19 changes: 8 additions & 11 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/gogo/protobuf/proto"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 9 additions & 10 deletions x/bounty/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
35 changes: 19 additions & 16 deletions x/bounty/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -204,22 +202,23 @@ 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)
},
}

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)

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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,
),
Expand All @@ -325,9 +326,11 @@ func ConfirmFinding(cmd *cobra.Command, args []string) error {
return err
}

fingerPrint, err := cmd.Flags().GetString(FlagFindingFingerPrint)

Check failure on line 329 in x/bounty/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

ineffectual assignment to err (ineffassign)

Check failure on line 329 in x/bounty/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ineffectual assignment to err (ineffassign)

// 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)
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
8 changes: 2 additions & 6 deletions x/bounty/keeper/finding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/bounty/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ func (suite *KeeperTestSuite) TestGRPCQueryFinding() {
"valid request",
func() {
req = &types.QueryFindingRequest{FindingId: "1"}
suite.InitSubmitFinding("1", "1")
suite.InitSubmitFinding(pid, "1")
},
true,
},
{
"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]))
Expand Down
5 changes: 3 additions & 2 deletions x/bounty/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit e493a5f

Please sign in to comment.