Skip to content

Commit

Permalink
fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
skyargos committed Nov 14, 2023
1 parent 796581c commit 6386e69
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 108 deletions.
11 changes: 6 additions & 5 deletions tests/e2e/e2e_bounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

sdkflags "github.com/cosmos/cosmos-sdk/client/flags"

bountycli "github.com/shentufoundation/shentu/v2/x/bounty/client/cli"
bountytypes "github.com/shentufoundation/shentu/v2/x/bounty/types"
)
Expand All @@ -15,7 +16,7 @@ func (s *IntegrationTestSuite) executeCreateProgram(c *chain, valIdx int, pid, n
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

s.T().Logf("Executing shentu bounty open program %s on %s", pid, c.id)
s.T().Logf("Executing shentu bounty create program %s on %s", pid, c.id)

command := []string{
shentuBinary,
Expand All @@ -40,7 +41,7 @@ func (s *IntegrationTestSuite) executeCreateProgram(c *chain, valIdx int, pid, n
s.T().Logf("%s successfully create program", creatorAddr)
}

func (s *IntegrationTestSuite) executeActivateProgram(c *chain, valIdx int, pid, creatorAddr, fees string) {
func (s *IntegrationTestSuite) executeActivateProgram(c *chain, valIdx int, pid, operatorAddr, fees string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

Expand All @@ -52,7 +53,7 @@ func (s *IntegrationTestSuite) executeActivateProgram(c *chain, valIdx int, pid,
bountytypes.ModuleName,
"activate-program",
fmt.Sprintf("%s", pid),
fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, creatorAddr),
fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, operatorAddr),
fmt.Sprintf("--%s=%s", sdkflags.FlagChainID, c.id),
fmt.Sprintf("--%s=%s", sdkflags.FlagGas, "auto"),
fmt.Sprintf("--%s=%s", sdkflags.FlagFees, fees),
Expand All @@ -64,7 +65,7 @@ func (s *IntegrationTestSuite) executeActivateProgram(c *chain, valIdx int, pid,
s.T().Logf("cmd: %s", strings.Join(command, " "))

s.execShentuTxCmd(ctx, c, command, valIdx, s.defaultExecValidation(c, valIdx))
s.T().Logf("%s successfully create program", creatorAddr)
s.T().Logf("%s successfully create program", operatorAddr)
}

func (s *IntegrationTestSuite) executeSubmitFinding(c *chain, valIdx int, pid, fid, submitAddr, title, desc, poc, detail, fees string) {
Expand All @@ -84,7 +85,7 @@ func (s *IntegrationTestSuite) executeSubmitFinding(c *chain, valIdx int, pid, f
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", bountycli.FlagFindingSeverityLevel, bountytypes.Low.String()),
fmt.Sprintf("--%s=%s", sdkflags.FlagFrom, submitAddr),
fmt.Sprintf("--%s=%s", sdkflags.FlagChainID, c.id),
fmt.Sprintf("--%s=%s", sdkflags.FlagGas, "auto"),
Expand Down
111 changes: 14 additions & 97 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package e2e
import (
"bytes"
"encoding/hex"
"github.com/shentufoundation/shentu/v2/x/bounty/types"
"strings"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/shentufoundation/shentu/v2/x/bounty/types"
)

func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
Expand Down Expand Up @@ -291,25 +290,22 @@ func (s *IntegrationTestSuite) TestCoreShield() {

func (s *IntegrationTestSuite) TestBounty() {
chainAAPIEndpoint := s.valResources[s.chainA.id][0].GetHostPort("9090/tcp")
accountA := s.chainA.accounts[0]
accountAAddr := accountA.keyInfo.GetAddress()
accountB := s.chainA.accounts[1]
accountBAddr := accountB.keyInfo.GetAddress()
programCli := s.chainA.accounts[0]
programCliAddr := programCli.keyInfo.GetAddress()
//accountB := s.chainA.accounts[1]
//accountBAddr := accountB.keyInfo.GetAddress()

validatorA := s.chainA.validators[0]
validatorAAddr := validatorA.keyInfo.GetAddress()
bountyAdmin := s.chainA.validators[0]
bountyAdminAddr := bountyAdmin.keyInfo.GetAddress()
s.Run("create_program", func() {
bountyProgramCounter++
pid := string(rune(bountyProgramCounter))
s.T().Logf("Creating program %d on chain %s", bountyProgramCounter, s.chainA.id)
var (
programName = "name"
programDesc = "program-desc"
)
s.executeCreateProgram(s.chainA, 0, pid, programName, programDesc, accountAAddr.String(), feesAmountCoin.String())
s.T().Logf("Creating program %s on chain %s", pid, s.chainA.id)
name, detail := "name", "detail"
s.executeCreateProgram(s.chainA, 0, pid, name, detail, programCliAddr.String(), feesAmountCoin.String())
s.Require().Eventually(
func() bool {
rsp, err := queryBountyProgram(chainAAPIEndpoint, string(rune(bountyProgramCounter)))
rsp, err := queryBountyProgram(chainAAPIEndpoint, pid)
s.Require().NoError(err)
return rsp.GetProgram().Status == types.ProgramStatusInactive
},
Expand All @@ -318,10 +314,11 @@ func (s *IntegrationTestSuite) TestBounty() {
)
})

// todo edit-program
s.Run("activate_program", func() {
pid := string(rune(bountyProgramCounter))
s.T().Logf("Open program %s on chain %s", pid, s.chainA.id)
s.executeActivateProgram(s.chainA, 0, pid, validatorAAddr.String(), feesAmountCoin.String())
s.T().Logf("Activate program %s on chain %s", pid, s.chainA.id)
s.executeActivateProgram(s.chainA, 0, pid, bountyAdminAddr.String(), feesAmountCoin.String())
s.Require().Eventually(
func() bool {
rsp, err := queryBountyProgram(chainAAPIEndpoint, pid)
Expand All @@ -332,86 +329,6 @@ func (s *IntegrationTestSuite) TestBounty() {
5*time.Second,
)
})

s.Run("submit_finding", func() {
bountyFindingCounter++
pid := string(rune(bountyProgramCounter))
fid := string(rune(bountyFindingCounter))
s.T().Logf("Submit finding %d on program %d chain %s", bountyFindingCounter, bountyProgramCounter, s.chainA.id)
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)
s.Require().NoError(err)
return rsp.GetFinding().Status == 0
},
20*time.Second,
5*time.Second,
)
})

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.executeCloseFinding(s.chainA, 0, fid, accountAAddr.String(), feesAmountCoin.String())
s.Require().Eventually(
func() bool {
rsp, err := queryBountyFinding(chainAAPIEndpoint, fid)
s.Require().NoError(err)
return rsp.GetFinding().Status == types.FindingStatusClosed
},
20*time.Second,
5*time.Second,
)
})

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.executeConfirmFinding(s.chainA, 0, fid, accountAAddr.String(), feesAmountCoin.String())
s.Require().Eventually(
func() bool {
rsp, err := queryBountyFinding(chainAAPIEndpoint, fid)
s.Require().NoError(err)
return rsp.GetFinding().Status == types.FindingStatusConfirmed
},
20*time.Second,
5*time.Second,
)
})

//s.Run("release_finding", func() {
// s.T().Logf("Release finding %d on program %d chain %s", bountyFindingCounter, bountyProgramCounter, s.chainA.id)
// s.executeReleaseFinding(s.chainA, 0, bountyFindingCounter, accountAAddr.String(), bountyKeyPath, feesAmountCoin.String())
// s.Require().Eventually(
// func() bool {
// rsp, err := queryBountyFinding(chainAAPIEndpoint, bountyFindingCounter)
// s.Require().NoError(err)
// findingPoc, err := base64.StdEncoding.DecodeString(rsp.Finding.FindingPoc)
// s.Require().NoError(err)
// return string(findingPoc) == "finding-poc"
// },
// 20*time.Second,
// 5*time.Second,
// )
//})

s.Run("close-program", func() {
pid := string(rune(bountyProgramCounter))
s.T().Logf("End program %d chain %s", bountyProgramCounter, s.chainA.id)
s.executeEndProgram(s.chainA, 0, pid, accountAAddr.String(), feesAmountCoin.String())
s.Require().Eventually(
func() bool {
rsp, err := queryBountyProgram(chainAAPIEndpoint, pid)
s.Require().NoError(err)
return rsp.GetProgram().Status == types.ProgramStatusClosed
},
20*time.Second,
5*time.Second,
)
})
}

func (s *IntegrationTestSuite) TestOracle() {
Expand Down
1 change: 1 addition & 0 deletions x/bounty/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"crypto/sha256"
"encoding/hex"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand Down
12 changes: 6 additions & 6 deletions x/oracle/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ func TasksInvariant(k Keeper) sdk.Invariant {
}
}

//three invariants are checked
// 1. sum of operator's collater should be equal to stored totalCollateral
// 2. module account balance minus totalCollateral should be larger or equal to
// sum of operator's reward plus sum of pending task's bounty
// 3. module account balance should be larger or equal to
// sum of operator's collateral plus sum of withdraw amount
// three invariants are checked
// 1. sum of operator's collater should be equal to stored totalCollateral
// 2. module account balance minus totalCollateral should be larger or equal to
// sum of operator's reward plus sum of pending task's bounty
// 3. module account balance should be larger or equal to
// sum of operator's collateral plus sum of withdraw amount
func FundInvariant(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
broken := false
Expand Down

0 comments on commit 6386e69

Please sign in to comment.