-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5adc74
commit 41c09e5
Showing
5 changed files
with
212 additions
and
40 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package interchain_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cosmos/gaia/v20/tests/interchain/chainsuite" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/tidwall/gjson" | ||
"github.com/tidwall/sjson" | ||
) | ||
|
||
type ConsensusSuite struct { | ||
*chainsuite.Suite | ||
} | ||
|
||
func (s *ConsensusSuite) TestInactiveValidators() { | ||
authority, err := s.Chain.GetGovernanceAddress(s.GetContext()) | ||
s.Require().NoError(err) | ||
|
||
stakingProposal := fmt.Sprintf(`{ | ||
"@type": "/cosmos.staking.v1beta1.MsgUpdateParams", | ||
"authority": "%s", | ||
"params": { | ||
"unbonding_time": "1814400s", | ||
"max_validators": 5, | ||
"max_entries": 7, | ||
"historical_entries": 10000, | ||
"bond_denom": "%s", | ||
"min_commission_rate": "0.050000000000000000", | ||
"validator_bond_factor": "250.000000000000000000", | ||
"global_liquid_staking_cap": "0.250000000000000000", | ||
"validator_liquid_staking_cap": "0.500000000000000000" | ||
} | ||
}`, authority, s.Chain.Config().Denom) | ||
|
||
prop, err := s.Chain.BuildProposal(nil, "update staking params", "update staking params", "", chainsuite.GovDepositAmount, "", false) | ||
s.Require().NoError(err) | ||
prop.Messages = []json.RawMessage{json.RawMessage(stakingProposal)} | ||
result, err := s.Chain.SubmitProposal(s.GetContext(), s.Chain.ValidatorWallets[0].Moniker, prop) | ||
s.Require().NoError(err) | ||
s.Require().NoError(s.Chain.PassProposal(s.GetContext(), result.ProposalID)) | ||
s.UpgradeChain() | ||
|
||
stakingParams, _, err := s.Chain.GetNode().ExecQuery(s.GetContext(), "staking", "params") | ||
s.Require().NoError(err) | ||
s.Require().Equal(uint64(200), gjson.GetBytes(stakingParams, "params.max_validators").Uint(), string(stakingParams)) | ||
|
||
providerParams, _, err := s.Chain.GetNode().ExecQuery(s.GetContext(), "provider", "params") | ||
s.Require().NoError(err) | ||
s.Require().Equal(uint64(180), gjson.GetBytes(providerParams, "max_provider_consensus_validators").Uint(), string(providerParams)) | ||
providerParams, err = sjson.SetBytes(providerParams, "max_provider_consensus_validators", 4) | ||
s.Require().NoError(err) | ||
providerProposal, err := sjson.SetRaw(fmt.Sprintf(`{ | ||
"@type": "/interchain_security.ccv.provider.v1.MsgUpdateParams", | ||
"authority": "%s" | ||
}`, authority), "params", string(providerParams)) | ||
s.Require().NoError(err) | ||
|
||
stakingProposal, err = sjson.Set(stakingProposal, "params.max_validators", 5) | ||
s.Require().NoError(err) | ||
prop, err = s.Chain.BuildProposal(nil, "update staking params", "update staking params", "", chainsuite.GovDepositAmount, "", false) | ||
s.Require().NoError(err) | ||
prop.Messages = append(prop.Messages, json.RawMessage(stakingProposal)) | ||
result, err = s.Chain.SubmitProposal(s.GetContext(), s.Chain.ValidatorWallets[0].Moniker, prop) | ||
s.Require().NoError(err) | ||
s.Require().NoError(s.Chain.PassProposal(s.GetContext(), result.ProposalID)) | ||
|
||
prop, err = s.Chain.BuildProposal(nil, "update provider params", "update provider params", "", chainsuite.GovDepositAmount, "", false) | ||
s.Require().NoError(err) | ||
prop.Messages = []json.RawMessage{json.RawMessage(providerProposal)} | ||
result, err = s.Chain.SubmitProposal(s.GetContext(), s.Chain.ValidatorWallets[0].Moniker, prop) | ||
s.Require().NoError(err) | ||
s.Require().NoError(s.Chain.PassProposal(s.GetContext(), result.ProposalID)) | ||
|
||
for i := 1; i < 4; i++ { | ||
jailed, err := s.Chain.IsValidatorJailedForConsumerDowntime(s.GetContext(), s.Relayer, s.Chain, i) | ||
s.Require().NoError(err) | ||
s.Assert().True(jailed, "validator %d should be jailed", i) | ||
} | ||
for i := 4; i < 6; i++ { | ||
jailed, err := s.Chain.IsValidatorJailedForConsumerDowntime(s.GetContext(), s.Relayer, s.Chain, i) | ||
s.Require().NoError(err) | ||
s.Assert().False(jailed, "validator %d should not be jailed", i) | ||
} | ||
|
||
cfg := chainsuite.ConsumerConfig{ | ||
ChainName: "ics-consumer", | ||
Version: "v5.0.0", | ||
ShouldCopyProviderKey: allProviderKeysCopied(), | ||
Denom: chainsuite.Ucon, | ||
TopN: 100, | ||
} | ||
consumer, err := s.Chain.AddConsumerChain(s.GetContext(), s.Relayer, cfg) | ||
s.Require().NoError(err) | ||
|
||
vals, err := consumer.QueryJSON(s.GetContext(), "validators", "comet-validator-set") | ||
s.Require().NoError(err) | ||
s.Require().Equal(4, len(vals.Array()), vals) | ||
|
||
err = s.Chain.CheckCCV(s.GetContext(), consumer, s.Relayer, 1_000_000, 0, 1) | ||
s.Require().NoError(err) | ||
|
||
for i := 1; i < 4; i++ { | ||
jailed, err := s.Chain.IsValidatorJailedForConsumerDowntime(s.GetContext(), s.Relayer, consumer, i) | ||
s.Require().NoError(err) | ||
s.Assert().True(jailed, "validator %d should be jailed", i) | ||
} | ||
for i := 4; i < 6; i++ { | ||
jailed, err := s.Chain.IsValidatorJailedForConsumerDowntime(s.GetContext(), s.Relayer, consumer, i) | ||
s.Require().NoError(err) | ||
s.Assert().False(jailed, "validator %d should not be jailed", i) | ||
} | ||
|
||
_, err = s.Chain.Validators[4].ExecTx(s.GetContext(), s.Chain.ValidatorWallets[4].Moniker, "provider", "opt-in", consumer.Config().ChainID) | ||
s.Require().NoError(err) | ||
jailed, err := s.Chain.IsValidatorJailedForConsumerDowntime(s.GetContext(), s.Relayer, consumer, 4) | ||
s.Require().NoError(err) | ||
s.Assert().True(jailed, "validator 4 should be jailed") | ||
|
||
_, err = s.Chain.Validators[5].ExecTx(s.GetContext(), s.Chain.ValidatorWallets[5].Moniker, "provider", "opt-in", consumer.Config().ChainID) | ||
s.Require().Error(err) | ||
jailed, err = s.Chain.IsValidatorJailedForConsumerDowntime(s.GetContext(), s.Relayer, consumer, 5) | ||
s.Require().NoError(err) | ||
s.Assert().False(jailed, "validator 5 should not be jailed") | ||
} | ||
|
||
func TestConsensus(t *testing.T) { | ||
s := &ConsensusSuite{ | ||
Suite: chainsuite.NewSuite(chainsuite.SuiteConfig{CreateRelayer: true}), | ||
} | ||
suite.Run(t, s) | ||
} |
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