Skip to content

Commit

Permalink
Query tx in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech committed Feb 13, 2024
1 parent d9ebe72 commit 0b963f6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
39 changes: 23 additions & 16 deletions tests/e2e/foundation/suite.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package foundation

import (
"encoding/hex"
"encoding/json"
"fmt"
"time"

"github.com/stretchr/testify/suite"
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/core/address"
"cosmossdk.io/math"
Expand Down Expand Up @@ -135,23 +137,13 @@ func (s *E2ETestSuite) SetupSuite() {
s.createAccount("leavingmember", leavingMemberMnemonic)
s.createAccount("permanentmember", permanentMemberMnemonic)

s.submitProposal(&foundation.MsgWithdrawFromTreasury{
s.proposalID = s.submitProposal(&foundation.MsgWithdrawFromTreasury{
Authority: s.bytesToString(s.authority),
To: s.bytesToString(s.stranger),
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))),
}, false)
s.proposalID = 1
s.vote(s.proposalID, []sdk.AccAddress{s.leavingMember, s.permanentMember})

// submit another two proposals without votes
for range make([]struct{}, 2) {
s.submitProposal(&foundation.MsgWithdrawFromTreasury{
Authority: s.bytesToString(s.authority),
To: s.bytesToString(s.stranger),
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))),
}, false)
}

s.setupHeight, err = s.network.LatestHeight()
s.Require().NoError(err)
}
Expand All @@ -168,7 +160,7 @@ func (s *E2ETestSuite) bytesToString(addr sdk.AccAddress) string {
}

// submit a proposal
func (s *E2ETestSuite) submitProposal(msg sdk.Msg, try bool) {
func (s *E2ETestSuite) submitProposal(msg sdk.Msg, try bool) uint64 {
val := s.network.Validators[0]

proposers := []string{s.bytesToString(s.permanentMember)}
Expand All @@ -190,7 +182,18 @@ func (s *E2ETestSuite) submitProposal(msg sdk.Msg, try bool) {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String())
s.Require().Zero(res.Code, out.String())

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)

dataBytes, err := hex.DecodeString(res.Data)
s.Require().NoError(err)
var data sdk.TxMsgData
s.Require().NoError(proto.Unmarshal(dataBytes, &data))
var msgResp foundation.MsgSubmitProposalResponse
s.Require().NoError(proto.Unmarshal(data.MsgResponses[0].Value, &msgResp), data.MsgResponses[0])

return msgResp.ProposalId
}

func (s *E2ETestSuite) vote(proposalID uint64, voters []sdk.AccAddress) {
Expand All @@ -209,9 +212,11 @@ func (s *E2ETestSuite) vote(proposalID uint64, voters []sdk.AccAddress) {
var res sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String())
s.Require().Zero(res.Code, out.String())
}

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
}
}

func (s *E2ETestSuite) msgToString(msg sdk.Msg) string {
Expand Down Expand Up @@ -260,5 +265,7 @@ func (s *E2ETestSuite) createAccount(uid, mnemonic string) {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String())
s.Require().Zero(res.Code, out.String())

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
}
38 changes: 30 additions & 8 deletions tests/e2e/foundation/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func (s *E2ETestSuite) TestNewTxCmdFundTreasury() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
s.Require().Zero(res.Code, out)

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
})
}
}
Expand Down Expand Up @@ -276,7 +278,9 @@ func (s *E2ETestSuite) TestNewTxCmdSubmitProposal() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
s.Require().Zero(res.Code, out)

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
})
}
}
Expand All @@ -290,7 +294,12 @@ func (s *E2ETestSuite) TestNewTxCmdWithdrawProposal() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)))),
}

proposalID := 2
proposalID := s.submitProposal(&foundation.MsgWithdrawFromTreasury{
Authority: s.bytesToString(s.authority),
To: s.bytesToString(s.stranger),
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))),
}, false)

testCases := map[string]struct {
args []string
valid bool
Expand Down Expand Up @@ -328,7 +337,9 @@ func (s *E2ETestSuite) TestNewTxCmdWithdrawProposal() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
s.Require().Zero(res.Code, out)

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
})
}
}
Expand All @@ -342,7 +353,12 @@ func (s *E2ETestSuite) TestNewTxCmdVote() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)))),
}

proposalID := 3
proposalID := s.submitProposal(&foundation.MsgWithdrawFromTreasury{
Authority: s.bytesToString(s.authority),
To: s.bytesToString(s.stranger),
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))),
}, false)

testCases := map[string]struct {
args []string
valid bool
Expand Down Expand Up @@ -384,7 +400,9 @@ func (s *E2ETestSuite) TestNewTxCmdVote() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
s.Require().Zero(res.Code, out)

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
})
}
}
Expand Down Expand Up @@ -435,7 +453,9 @@ func (s *E2ETestSuite) TestNewTxCmdExec() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
s.Require().Zero(res.Code, out)

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
})
}
}
Expand Down Expand Up @@ -547,7 +567,9 @@ func (s *E2ETestSuite) TestNewTxCmdLeaveFoundation() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
s.Require().Zero(res.Code, out)

s.Require().NoError(s.network.WaitForNextBlock())
res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash)
s.Require().NoError(err)
s.Require().Zero(res.Code, res.RawLog)
})
}
}
Expand Down

0 comments on commit 0b963f6

Please sign in to comment.