-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: x/gov deposits querier (Initial Deposit) #9288
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6ea333c
copied from old PR
aleem1314 0de858b
fix errors
aleem1314 64232e8
add test
aleem1314 e185e33
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 0d7b764
Update x/gov/client/utils/query.go
aleem1314 5d8cf40
fix tests
aleem1314 6e81021
Merge branch 'aleem/8758-gov-deposits' of https://github.com/cosmos/c…
aleem1314 8b4d075
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 0048d2a
fix failing test
aleem1314 2a69de4
add test
aleem1314 12457b9
update test
aleem1314 22fe967
fix tests
aleem1314 a1daaa4
fix deposit query
aleem1314 88e4868
fix test
aleem1314 ef11cae
update tests
aleem1314 ff024ce
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 1424885
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 c74c3b8
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 fdbc334
add more tests
aleem1314 5ad7a69
address lint error
aleem1314 1725f6e
address lint error
aleem1314 f4fab49
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 7dc95c1
review changes
aleem1314 8175663
Merge branch 'aleem/8758-gov-deposits' of https://github.com/cosmos/c…
aleem1314 fe6487d
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 4123e05
Merge branch 'master' into aleem/8758-gov-deposits
aleem1314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/stretchr/testify/suite" | ||
tmcli "github.com/tendermint/tendermint/libs/cli" | ||
) | ||
|
||
type DepositTestSuite struct { | ||
suite.Suite | ||
|
||
cfg network.Config | ||
network *network.Network | ||
fees string | ||
} | ||
|
||
func NewDepositTestSuite(cfg network.Config) *DepositTestSuite { | ||
return &DepositTestSuite{cfg: cfg} | ||
} | ||
|
||
func (s *DepositTestSuite) SetupSuite() { | ||
s.T().Log("setting up test suite") | ||
|
||
s.network = network.New(s.T(), s.cfg) | ||
|
||
_, err := s.network.WaitForHeight(1) | ||
s.Require().NoError(err) | ||
s.fees = sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(20))).String() | ||
|
||
} | ||
|
||
func (s *DepositTestSuite) TearDownSuite() { | ||
s.T().Log("tearing down test suite") | ||
s.network.Cleanup() | ||
} | ||
|
||
func (s *DepositTestSuite) TestQueryDepositsInitialDeposit() { | ||
val := s.network.Validators[0] | ||
clientCtx := val.ClientCtx | ||
initialDeposit := sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(20))).String() | ||
|
||
// create a proposal with deposit | ||
_, err := MsgSubmitProposal(val.ClientCtx, val.Address.String(), | ||
"Text Proposal 1", "Where is the title!?", types.ProposalTypeText, | ||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, initialDeposit)) | ||
s.Require().NoError(err) | ||
|
||
// deposit more amount | ||
_, err = MsgDeposit(clientCtx, val.Address.String(), "1", sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(50)).String()) | ||
s.Require().NoError(err) | ||
|
||
// waiting for voting period to end | ||
time.Sleep(20 * time.Second) | ||
|
||
// query deposit & verify initial deposit | ||
deposit := s.queryDeposit(val, "1", false) | ||
s.Require().Equal(deposit.Amount.String(), initialDeposit) | ||
|
||
// query deposits | ||
deposits := s.queryDeposits(val, "1", false) | ||
s.Require().Equal(len(deposits), 2) | ||
// verify initial deposit | ||
s.Require().Equal(deposits[0].Amount.String(), initialDeposit) | ||
} | ||
|
||
func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() { | ||
val := s.network.Validators[0] | ||
clientCtx := val.ClientCtx | ||
|
||
// create a proposal without deposit | ||
_, err := MsgSubmitProposal(val.ClientCtx, val.Address.String(), | ||
"Text Proposal 2", "Where is the title!?", types.ProposalTypeText) | ||
s.Require().NoError(err) | ||
|
||
// deposit amount | ||
_, err = MsgDeposit(clientCtx, val.Address.String(), "2", sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()) | ||
s.Require().NoError(err) | ||
|
||
// waiting for voting period to end | ||
time.Sleep(20 * time.Second) | ||
|
||
// query deposit | ||
deposit := s.queryDeposit(val, "2", false) | ||
s.Require().Equal(deposit.Amount.String(), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()) | ||
|
||
// query deposits | ||
deposits := s.queryDeposits(val, "2", false) | ||
s.Require().Equal(len(deposits), 1) | ||
// verify initial deposit | ||
s.Require().Equal(deposits[0].Amount.String(), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()) | ||
} | ||
|
||
func (s *DepositTestSuite) TestQueryProposalNotEnoughDeposits() { | ||
val := s.network.Validators[0] | ||
clientCtx := val.ClientCtx | ||
initialDeposit := sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(2000))).String() | ||
|
||
// create a proposal with deposit | ||
_, err := MsgSubmitProposal(val.ClientCtx, val.Address.String(), | ||
"Text Proposal 3", "Where is the title!?", types.ProposalTypeText, | ||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, initialDeposit)) | ||
s.Require().NoError(err) | ||
|
||
// query proposal | ||
args := []string{"3", fmt.Sprintf("--%s=json", tmcli.OutputFlag)} | ||
cmd := cli.GetCmdQueryProposal() | ||
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) | ||
s.Require().NoError(err) | ||
|
||
// waiting for deposit period to end | ||
time.Sleep(20 * time.Second) | ||
|
||
// query proposal | ||
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) | ||
s.Require().Error(err) | ||
s.Require().Contains(err.Error(), "proposal 3 doesn't exist") | ||
} | ||
|
||
func (s *DepositTestSuite) TestRejectedProposalDeposits() { | ||
val := s.network.Validators[0] | ||
clientCtx := val.ClientCtx | ||
initialDeposit := sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens) | ||
|
||
// create a proposal with deposit | ||
_, err := MsgSubmitProposal(clientCtx, val.Address.String(), | ||
"Text Proposal 4", "Where is the title!?", types.ProposalTypeText, | ||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, initialDeposit)) | ||
s.Require().NoError(err) | ||
|
||
// query deposits | ||
var deposits types.QueryDepositsResponse | ||
args := []string{"4", fmt.Sprintf("--%s=json", tmcli.OutputFlag)} | ||
cmd := cli.GetCmdQueryDeposits() | ||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &deposits)) | ||
s.Require().Equal(len(deposits.Deposits), 1) | ||
// verify initial deposit | ||
s.Require().Equal(deposits.Deposits[0].Amount.String(), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens).String()) | ||
|
||
// vote | ||
_, err = MsgVote(clientCtx, val.Address.String(), "4", "no") | ||
s.Require().NoError(err) | ||
|
||
time.Sleep(20 * time.Second) | ||
|
||
args = []string{"4", fmt.Sprintf("--%s=json", tmcli.OutputFlag)} | ||
cmd = cli.GetCmdQueryProposal() | ||
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) | ||
s.Require().NoError(err) | ||
|
||
// query deposits | ||
depositsRes := s.queryDeposits(val, "4", false) | ||
s.Require().Equal(len(depositsRes), 1) | ||
// verify initial deposit | ||
s.Require().Equal(depositsRes[0].Amount.String(), initialDeposit.String()) | ||
|
||
} | ||
|
||
func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID string, exceptErr bool) types.Deposits { | ||
args := []string{proposalID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)} | ||
var depositsRes types.Deposits | ||
cmd := cli.GetCmdQueryDeposits() | ||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) | ||
if exceptErr { | ||
s.Require().Error(err) | ||
return nil | ||
} | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositsRes)) | ||
return depositsRes | ||
} | ||
|
||
func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool) *types.Deposit { | ||
args := []string{proposalID, val.Address.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)} | ||
var depositRes types.Deposit | ||
cmd := cli.GetCmdQueryDeposit() | ||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) | ||
if exceptErr { | ||
s.Require().Error(err) | ||
return nil | ||
} | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositRes)) | ||
return &depositRes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's query the deposit before the voting as well.