Skip to content

Commit

Permalink
imp(e2e): voting test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Dec 8, 2023
1 parent ead674a commit a058d87
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
37 changes: 24 additions & 13 deletions e2e/interchaintest/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,18 @@ func (s *ContractTestSuite) IcaContractExecutionTestWithEncoding(encoding string
},
},
}
// Vote on the proposal through CosmosMsgs:
voteCosmosMsg := types.ContractCosmosMsg{
Gov: &types.GovCosmosMsg{
Vote: &types.GovVoteCosmosMsg{
ProposalID: 1,
Vote: "yes",
},
},
}

// Execute the contract:
err = s.Contract.ExecSendCosmosMsgs(ctx, wasmdUser.KeyName(), []types.ContractCosmosMsg{stakeCosmosMsg}, nil, nil)
err = s.Contract.ExecSendCosmosMsgs(ctx, wasmdUser.KeyName(), []types.ContractCosmosMsg{stakeCosmosMsg, voteCosmosMsg}, nil, nil)

Check failure on line 417 in e2e/interchaintest/contract_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) -s prefix(github.com/strangelove-ventures/interchaintest) -s prefix(github.com/srdtrk/cw-ica-controller/interchaintest) --custom-order (gci)
s.Require().NoError(err)

err = testutil.WaitForBlocks(ctx, 5, wasmd, simd)
Expand All @@ -424,24 +433,26 @@ func (s *ContractTestSuite) IcaContractExecutionTestWithEncoding(encoding string

delegationsQuerier := mysuite.NewGRPCQuerier[stakingtypes.QueryDelegationResponse](s.T(), simd, "/cosmos.staking.v1beta1.Query/Delegation")

gRPCRequest := stakingtypes.QueryDelegationRequest{
delRequest := stakingtypes.QueryDelegationRequest{
DelegatorAddr: s.IcaAddress,
ValidatorAddr: validator,
}
resp, err := delegationsQuerier.GRPCQuery(ctx, &gRPCRequest)
delResp, err := delegationsQuerier.GRPCQuery(ctx, &delRequest)
s.Require().NoError(err)
s.Require().Equal(sdkmath.NewInt(10_000_000), delResp.DelegationResponse.Balance.Amount)

// response := resp.(*stakingtypes.QueryDelegationResponse)
s.Require().Equal(sdkmath.NewInt(10_000_000), resp.DelegationResponse.Balance.Amount)
// Check if the vote was successful:
votesQuerier := mysuite.NewGRPCQuerier[govtypes.QueryVoteResponse](s.T(), simd, "/cosmos.gov.v1beta1.Query/Vote")

// // Vote on the proposal through CosmosMsgs:
// voteCosmosMsg := types.ContractCosmosMsg {
// Gov: &types.GovCosmosMsg{
// Vote: &types.GovVoteCosmosMsg{
// ProposalID: "1",
// },
// },
// }
voteRequest := govtypes.QueryVoteRequest{
ProposalId: 1,
Voter: s.IcaAddress,
}
voteResp, err := votesQuerier.GRPCQuery(ctx, &voteRequest)
s.Require().NoError(err)
s.Require().Len(voteResp.Vote.Options, 1)
s.Require().Equal(govtypes.OptionYes, voteResp.Vote.Options[0].Option)
s.Require().Equal(sdkmath.LegacyNewDec(1), voteResp.Vote.Options[0].Weight)
})

s.Run(fmt.Sprintf("TestSendCustomIcaMessagesError-%s", encoding), func() {
Expand Down
19 changes: 9 additions & 10 deletions e2e/interchaintest/types/cosmos_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ type StargateCosmosMsg struct {
}

type BankCosmosMsg struct {
Send *BankSendCosmosMsg `json:"send"`
Send *BankSendCosmosMsg `json:"send,omitempty"`
}

type IbcCosmosMsg struct {
Transfer *IbcTransferCosmosMsg `json:"transfer"`
Transfer *IbcTransferCosmosMsg `json:"transfer,omitempty"`
}

type GovCosmosMsg struct {
Vote *GovVoteCosmosMsg `json:"vote"`
VoteWeighted *GovVoteWeightedCosmosMsg `json:"vote_weighted"`
Vote *GovVoteCosmosMsg `json:"vote,omitempty"`
VoteWeighted *GovVoteWeightedCosmosMsg `json:"vote_weighted,omitempty"`
}

type StakingCosmosMsg struct {
Expand Down Expand Up @@ -61,23 +61,22 @@ type IbcTransferCosmosMsg struct {
ChannelID string `json:"channel_id"`
ToAddress string `json:"to_address"`
Amount Coin `json:"amount"`
// This is optional
// Timeout string `json:"timeout"`
}

type GovVoteCosmosMsg struct {
ProposalID string `json:"proposal_id"`
VoteOption string `json:"vote_option"`
ProposalID uint64 `json:"proposal_id"`
Vote string `json:"vote"`
}

type GovVoteWeightedCosmosMsg struct {
ProposalID string `json:"proposal_id"`
ProposalID uint64 `json:"proposal_id"`
Options []GovVoteWeightedOption `json:"options"`
}

type GovVoteWeightedOption struct {
VoteOption string `json:"option"`
Weight string `json:"weight"`
Option string `json:"option"`
Weight string `json:"weight"`
}

type Coin struct {
Expand Down

0 comments on commit a058d87

Please sign in to comment.