Skip to content
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

ci: Add auth module test to interchaintests #3522

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions tests/interchain/delegator/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package delegator_test

import (
"encoding/json"
"fmt"
"testing"

"github.com/stretchr/testify/suite"
"github.com/tidwall/sjson"

"github.com/cosmos/gaia/v23/tests/interchain/chainsuite"
"github.com/cosmos/gaia/v23/tests/interchain/delegator"
)

type AuthSuite struct {
*delegator.Suite
}

func (s *AuthSuite) SetupSuite() {
s.Suite.SetupSuite()
// Delegate >1 ATOM with delegator account
node := s.Chain.GetNode()
node.StakingDelegate(s.GetContext(), s.DelegatorWallet.KeyName(), s.Chain.ValidatorWallets[0].ValoperAddress, string(govStakeAmount)+s.Chain.Config().Denom)
node.StakingDelegate(s.GetContext(), s.DelegatorWallet2.KeyName(), s.Chain.ValidatorWallets[0].ValoperAddress, string(govStakeAmount)+s.Chain.Config().Denom)
}

func (s *AuthSuite) TestParamChange() {
authParams, err := s.Chain.QueryJSON(s.GetContext(), "params", "auth", "params")
s.Require().NoError(err)
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Params: %s", authParams)
currentMemoLimit := authParams.Get("max_memo_characters").Int()
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Current max memo characters: %d", currentMemoLimit)
newLimit := int64(512)

chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Submitting transaction with more than %d characters (must fail).", currentMemoLimit)
_, err = s.Chain.GetNode().ExecTx(
s.GetContext(),
s.DelegatorWallet.FormattedAddress(),
"bank", "send",
s.DelegatorWallet.FormattedAddress(), s.DelegatorWallet2.FormattedAddress(), txAmountUatom(), "--note=7c97b5bdfefff77ecd8d8ffa2be7e09a9e8b0c599accdae5a74d132c7c19c9c08127742d2ab6547d202be9dc96ef13bb131f482670967bf0de765792462171de524c8f1509b2d1d7ce7f2c473b30b71e4bfe41a85e7f78d02846dfc2f7ae31da29585e8b39547215d143e772ba5be11bbe896e98f3f196dfa2b1a37dc17c3cd4fdd3",
)
s.Require().Error(err)

authority, err := s.Chain.GetGovernanceAddress(s.GetContext())
s.Require().NoError(err)

updatedParams, err := sjson.Set(authParams.String(), "max_memo_characters", fmt.Sprintf("%d", newLimit))
s.Require().NoError(err)
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Updated params: %s", updatedParams)

paramChangeMessage := fmt.Sprintf(`{
"@type": "/cosmos.auth.v1beta1.MsgUpdateParams",
"authority": "%s",
"params": %s
}`, authority, updatedParams)

chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Message: %s", paramChangeMessage)

// Submit proposal
prop, err := s.Chain.BuildProposal(nil, "Auth Param Change Proposal", "Test Proposal", "ipfs://CID", chainsuite.GovDepositAmount, s.DelegatorWallet.KeyName(), false)
s.Require().NoError(err)
prop.Messages = []json.RawMessage{json.RawMessage(paramChangeMessage)}
result, err := s.Chain.SubmitProposal(s.GetContext(), s.DelegatorWallet.KeyName(), prop)
s.Require().NoError(err)
proposalId := result.ProposalID

json, _, err := s.Chain.GetNode().ExecQuery(s.GetContext(), "gov", "proposal", proposalId)
s.Require().NoError(err)
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", string(json))

// Pass proposal
s.Require().NoError(s.Chain.PassProposal(s.GetContext(), proposalId))

// Test
authParams, err = s.Chain.QueryJSON(s.GetContext(), "params", "auth", "params")
s.Require().NoError(err)
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Params: %s", authParams)
currentMemoLimit = authParams.Get("max_memo_characters").Int()
s.Require().Equal(newLimit, currentMemoLimit)

chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Submitting transaction with more than %d characters (must pass).", currentMemoLimit)
_, err = s.Chain.GetNode().ExecTx(
s.GetContext(),
s.DelegatorWallet.FormattedAddress(),
"bank", "send",
s.DelegatorWallet.FormattedAddress(), s.DelegatorWallet2.FormattedAddress(), txAmountUatom(), "--note=7c97b5bdfefff77ecd8d8ffa2be7e09a9e8b0c599accdae5a74d132c7c19c9c08127742d2ab6547d202be9dc96ef13bb131f482670967bf0de765792462171de524c8f1509b2d1d7ce7f2c473b30b71e4bfe41a85e7f78d02846dfc2f7ae31da29585e8b39547215d143e772ba5be11bbe896e98f3f196dfa2b1a37dc17c3cd4fdd3",
)
s.Require().NoError(err)
}

func TestAuthModule(t *testing.T) {
s := &AuthSuite{Suite: &delegator.Suite{Suite: chainsuite.NewSuite(chainsuite.SuiteConfig{
UpgradeOnSetup: true,
})}}
suite.Run(t, s)
}
18 changes: 9 additions & 9 deletions tests/interchain/delegator/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func txAmountUatom() string {
return fmt.Sprintf("%d%s", txAmount, chainsuite.Uatom)
}

type AuthSuite struct {
type AuthzSuite struct {
*delegator.Suite
}

func (s *AuthSuite) TestSend() {
func (s *AuthzSuite) TestSend() {
balanceBefore, err := s.Chain.GetBalance(s.GetContext(), s.DelegatorWallet3.FormattedAddress(), chainsuite.Uatom)
s.Require().NoError(err)
_, err = s.Chain.GetNode().ExecTx(
Expand Down Expand Up @@ -56,7 +56,7 @@ func (s *AuthSuite) TestSend() {
s.Require().Error(s.authzGenExec(s.GetContext(), s.DelegatorWallet2, "bank", "send", s.DelegatorWallet.FormattedAddress(), s.DelegatorWallet3.FormattedAddress(), txAmountUatom()))
}

func (s *AuthSuite) TestDelegate() {
func (s *AuthzSuite) TestDelegate() {
_, err := s.Chain.GetNode().ExecTx(
s.GetContext(),
s.DelegatorWallet.FormattedAddress(),
Expand All @@ -77,7 +77,7 @@ func (s *AuthSuite) TestDelegate() {
s.Require().Error(s.authzGenExec(s.GetContext(), s.DelegatorWallet2, "staking", "delegate", s.Chain.ValidatorWallets[0].ValoperAddress, txAmountUatom(), "--from", s.DelegatorWallet.FormattedAddress()))
}

func (s *AuthSuite) TestUnbond() {
func (s *AuthzSuite) TestUnbond() {
valHex, err := s.Chain.GetValidatorHex(s.GetContext(), 0)
s.Require().NoError(err)
powerBefore, err := s.Chain.GetValidatorPower(s.GetContext(), valHex)
Expand Down Expand Up @@ -122,7 +122,7 @@ func (s *AuthSuite) TestUnbond() {
s.Require().Error(s.authzGenExec(s.GetContext(), s.DelegatorWallet2, "staking", "unbond", s.Chain.ValidatorWallets[0].ValoperAddress, txAmountUatom(), "--from", s.DelegatorWallet.FormattedAddress()))
}

func (s AuthSuite) TestRedelegate() {
func (s AuthzSuite) TestRedelegate() {
val0Hex, err := s.Chain.GetValidatorHex(s.GetContext(), 0)
s.Require().NoError(err)
val2Hex, err := s.Chain.GetValidatorHex(s.GetContext(), 1)
Expand Down Expand Up @@ -171,7 +171,7 @@ func (s AuthSuite) TestRedelegate() {
s.Require().Error(s.authzGenExec(s.GetContext(), s.DelegatorWallet2, "staking", "redelegate", s.Chain.ValidatorWallets[0].ValoperAddress, s.Chain.ValidatorWallets[1].ValoperAddress, txAmountUatom(), "--from", s.Chain.ValidatorWallets[0].Address))
}

func (s AuthSuite) TestGeneric() {
func (s AuthzSuite) TestGeneric() {
_, err := s.Chain.GetNode().ExecTx(
s.GetContext(),
s.Chain.ValidatorWallets[0].Moniker,
Expand All @@ -187,9 +187,9 @@ func (s AuthSuite) TestGeneric() {
s.Require().NoError(s.authzGenExec(s.GetContext(), s.DelegatorWallet, "gov", "vote", result.ProposalID, "yes", "--from", s.Chain.ValidatorWallets[0].Address))
}

func TestAuthz(t *testing.T) {
func TestAuthzModule(t *testing.T) {
two := 2
s := &AuthSuite{Suite: &delegator.Suite{Suite: chainsuite.NewSuite(chainsuite.SuiteConfig{
s := &AuthzSuite{Suite: &delegator.Suite{Suite: chainsuite.NewSuite(chainsuite.SuiteConfig{
UpgradeOnSetup: true,
ChainSpec: &interchaintest.ChainSpec{
NumValidators: &two,
Expand All @@ -198,7 +198,7 @@ func TestAuthz(t *testing.T) {
suite.Run(t, s)
}

func (s AuthSuite) authzGenExec(ctx context.Context, grantee ibc.Wallet, command ...string) error {
func (s AuthzSuite) authzGenExec(ctx context.Context, grantee ibc.Wallet, command ...string) error {
txjson, err := s.Chain.GenerateTx(ctx, 1, command...)
s.Require().NoError(err)

Expand Down
44 changes: 22 additions & 22 deletions tests/interchain/delegator/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
)

const (
stakeAmount = "10000000" // 10 ATOM
submissionDeposit = "100"
proposalDepositInt = chainsuite.GovMinDepositAmount
communityPoolAmount = "200000000" // 200 ATOM
yesWeight = 0.6
noWeight = 0.3
abstainWeight = 0.06
vetoWeight = 0.04
queryScaleMultiplier = 1000000000000000000 // 18 zeroes
govStakeAmount = "10000000" // 10 ATOM
govSubmissionDeposit = "100"
govProposalDepositInt = chainsuite.GovMinDepositAmount
govCommunityPoolAmount = "200000000" // 200 ATOM
govYesWeight = 0.6
govNoWeight = 0.3
govAbstainWeight = 0.06
govVetoWeight = 0.04
govQueryScaleMultiplier = 1000000000000000000 // 18 zeroes
)

type GovSuite struct {
Expand All @@ -37,8 +37,8 @@ func (s *GovSuite) SetupSuite() {
s.Suite.SetupSuite()
// Delegate >1 ATOM with delegator account
node := s.Chain.GetNode()
node.StakingDelegate(s.GetContext(), s.DelegatorWallet.KeyName(), s.Chain.ValidatorWallets[0].ValoperAddress, string(stakeAmount)+s.Chain.Config().Denom)
node.StakingDelegate(s.GetContext(), s.DelegatorWallet2.KeyName(), s.Chain.ValidatorWallets[0].ValoperAddress, string(stakeAmount)+s.Chain.Config().Denom)
node.StakingDelegate(s.GetContext(), s.DelegatorWallet.KeyName(), s.Chain.ValidatorWallets[0].ValoperAddress, string(govStakeAmount)+s.Chain.Config().Denom)
node.StakingDelegate(s.GetContext(), s.DelegatorWallet2.KeyName(), s.Chain.ValidatorWallets[0].ValoperAddress, string(govStakeAmount)+s.Chain.Config().Denom)
}

func (s *GovSuite) TestProposal() {
Expand All @@ -49,7 +49,7 @@ func (s *GovSuite) TestProposal() {
// 4. Weighted vote

// Submit proposal
prop, err := s.Chain.BuildProposal(nil, "Test Proposal", "Test Proposal", "ipfs://CID", submissionDeposit+"uatom", s.DelegatorWallet.FormattedAddress(), false)
prop, err := s.Chain.BuildProposal(nil, "Test Proposal", "Test Proposal", "ipfs://CID", govSubmissionDeposit+"uatom", s.DelegatorWallet.FormattedAddress(), false)
s.Require().NoError(err)
result, err := s.Chain.SubmitProposal(s.GetContext(), s.DelegatorWallet.KeyName(), prop)
s.Require().NoError(err)
Expand All @@ -65,13 +65,13 @@ func (s *GovSuite) TestProposal() {
s.Require().Equal("PROPOSAL_STATUS_DEPOSIT_PERIOD", currentStatus)

// Submit deposit to proposal
proposalDeposit := strconv.Itoa(proposalDepositInt)
proposalDeposit := strconv.Itoa(govProposalDepositInt)
node := s.Chain.GetNode()
_, err = node.ExecTx(s.GetContext(), s.DelegatorWallet.KeyName(), "gov", "deposit", proposalId, proposalDeposit+"uatom", "--gas", "auto")
s.Require().NoError(err)
submissionDepositUint, err := strconv.ParseUint(submissionDeposit, 10, 64)
submissionDepositUint, err := strconv.ParseUint(govSubmissionDeposit, 10, 64)
s.Require().NoError(err)
depositTotal := proposalDepositInt + submissionDepositUint
depositTotal := govProposalDepositInt + submissionDepositUint

// Get status
proposalIDuint, err = strconv.ParseUint(proposalId, 10, 64)
Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *GovSuite) TestProposal() {
s.Require().Equal(float64(1.0), actual_yes_weight.Float())

// Submit weighted vote
_, err = node.ExecTx(s.GetContext(), s.DelegatorWallet2.KeyName(), "gov", "weighted-vote", proposalId, fmt.Sprintf("yes=%0.2f,no=%0.2f,abstain=%0.2f,no_with_veto=%0.2f", yesWeight, noWeight, abstainWeight, vetoWeight), "--gas", "auto")
_, err = node.ExecTx(s.GetContext(), s.DelegatorWallet2.KeyName(), "gov", "weighted-vote", proposalId, fmt.Sprintf("yes=%0.2f,no=%0.2f,abstain=%0.2f,no_with_veto=%0.2f", govYesWeight, govNoWeight, govAbstainWeight, govVetoWeight), "--gas", "auto")
s.Require().NoError(err)

// Test weighted vote
Expand All @@ -109,16 +109,16 @@ func (s *GovSuite) TestProposal() {
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", vote)
actual_yes_weight = vote.Get("options.#(option==\"VOTE_OPTION_YES\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_yes_weight.String())
s.Require().Equal(float64(yesWeight), actual_yes_weight.Float())
s.Require().Equal(float64(govYesWeight), actual_yes_weight.Float())
actual_no_weight := vote.Get("options.#(option==\"VOTE_OPTION_NO\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_no_weight.String())
s.Require().Equal(float64(noWeight), actual_no_weight.Float())
s.Require().Equal(float64(govNoWeight), actual_no_weight.Float())
actual_abstain_weight := vote.Get("options.#(option==\"VOTE_OPTION_ABSTAIN\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_abstain_weight.String())
s.Require().Equal(float64(abstainWeight), actual_abstain_weight.Float())
s.Require().Equal(float64(govAbstainWeight), actual_abstain_weight.Float())
actual_veto_weight := vote.Get("options.#(option==\"VOTE_OPTION_NO_WITH_VETO\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_veto_weight.String())
s.Require().Equal(float64(vetoWeight), actual_veto_weight.Float())
s.Require().Equal(float64(govVetoWeight), actual_veto_weight.Float())
}

func (s *GovSuite) TestParamChange() {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (s *GovSuite) TestGovFundCommunityPool() {
}
],
"depositor": "%s"
}`, communityPoolAmount, authority)
}`, govCommunityPoolAmount, authority)

// Submit proposal
prop, err := s.Chain.BuildProposal(nil, "Community Pool Funding Proposal", "Test Proposal", "ipfs://CID", chainsuite.GovDepositAmount, s.DelegatorWallet.FormattedAddress(), false)
Expand All @@ -224,7 +224,7 @@ func (s *GovSuite) TestGovFundCommunityPool() {
s.Require().NoError(err)
balanceDifference := endingPoolBalance.Uint64() - startingPoolBalance.Uint64()
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("The community pool balance increased by %d", balanceDifference)
fundAmount, err := strconv.ParseUint(communityPoolAmount, 10, 64)
fundAmount, err := strconv.ParseUint(govCommunityPoolAmount, 10, 64)
s.Require().NoError(err)
s.Require().GreaterOrEqual(balanceDifference, fundAmount)
}
Expand Down
Loading