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: Interchaintests for provider actions run on provider #2368

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
454 changes: 454 additions & 0 deletions tests/interchain/chainsuite/chain.go

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions tests/interchain/chainsuite/chain_spec_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package chainsuite

import (
"strconv"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"

"github.com/strangelove-ventures/interchaintest/v8"
)

func GetProviderSpec() *interchaintest.ChainSpec {
fullNodes := FullNodeCount
validators := ValidatorCount

return &interchaintest.ChainSpec{
Name: ProviderChainID,
NumFullNodes: &fullNodes,
NumValidators: &validators,
Version: ProviderImageVersion,
ChainConfig: ibc.ChainConfig{
Type: CosmosChainType,
Bin: ProviderBin,
Bech32Prefix: ProviderBech32Prefix,
Denom: Stake,
GasPrices: GasPrices + Stake,
GasAdjustment: 2.0,
TrustingPeriod: "504h",
ConfigFileOverrides: map[string]any{
"config/config.toml": DefaultConfigToml(),
},
Images: []ibc.DockerImage{{
Repository: ProviderImageName,
UIDGID: "1025:1025",
}},
ModifyGenesis: cosmos.ModifyGenesis(providerModifiedGenesis()),
ModifyGenesisAmounts: DefaultGenesisAmounts(Stake),
},
}
}

func providerModifiedGenesis() []cosmos.GenesisKV {
return []cosmos.GenesisKV{
cosmos.NewGenesisKV("app_state.staking.params.unbonding_time", ProviderUnbondingTime.String()),
cosmos.NewGenesisKV("app_state.gov.params.voting_period", GovVotingPeriod.String()),
cosmos.NewGenesisKV("app_state.gov.params.max_deposit_period", GovDepositPeriod.String()),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.denom", Stake),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.amount", strconv.Itoa(GovMinDepositAmount)),
cosmos.NewGenesisKV("app_state.slashing.params.signed_blocks_window", strconv.Itoa(ProviderSlashingWindow)),
cosmos.NewGenesisKV("app_state.slashing.params.downtime_jail_duration", DowntimeJailDuration.String()),
cosmos.NewGenesisKV("app_state.provider.params.slash_meter_replenish_period", ProviderReplenishPeriod),
cosmos.NewGenesisKV("app_state.provider.params.slash_meter_replenish_fraction", ProviderReplenishFraction),
cosmos.NewGenesisKV("app_state.provider.params.blocks_per_epoch", "1"),
}
}
63 changes: 63 additions & 0 deletions tests/interchain/chainsuite/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package chainsuite

import (
"time"

"github.com/strangelove-ventures/interchaintest/v8/testutil"

sdkmath "cosmossdk.io/math"
sdktypes "github.com/cosmos/cosmos-sdk/types"
)

const (
ProviderImageName = "ghcr.io/cosmos/interchain-security"
ProviderImageVersion = "v6.1.0"
ProviderBin = "interchain-security-pd"
ProviderBech32Prefix = "cosmos"
ProviderValOperPrefix = "cosmosvaloper"
ProviderChainID = "ics-provider"
Stake = "stake"
DowntimeJailDuration = 10 * time.Second
ProviderSlashingWindow = 10
ProviderUnbondingTime = 10 * time.Second
ProviderReplenishPeriod = "2s"
ProviderReplenishFraction = "1.00"
GovMinDepositAmount = 1000
GovMinDepositString = "1000" + Stake
GovDepositPeriod = 10 * time.Second
GovVotingPeriod = 15 * time.Second
GasPrices = "0.005"
UpgradeDelta = 30
SlashingWindowConsumer = 20
CommitTimeout = 2 * time.Second
TotalValidatorFunds = 11_000_000_000
ValidatorFunds = 30_000_000
ValidatorCount = 1
FullNodeCount = 0
ChainSpawnWait = 155 * time.Second
CosmosChainType = "cosmos"
GovModuleAddress = "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
TestWalletsNumber = 5 // Ensure that test accounts are used in a way that maintains the mutual independence of tests
)

func DefaultConfigToml() testutil.Toml {
configToml := make(testutil.Toml)
consensusToml := make(testutil.Toml)
consensusToml["timeout_commit"] = CommitTimeout
configToml["consensus"] = consensusToml
configToml["block_sync"] = false
configToml["fast_sync"] = false
return configToml
}

func DefaultGenesisAmounts(denom string) func(i int) (sdktypes.Coin, sdktypes.Coin) {
return func(i int) (sdktypes.Coin, sdktypes.Coin) {
return sdktypes.Coin{
Denom: denom,
Amount: sdkmath.NewInt(TotalValidatorFunds),
}, sdktypes.Coin{
Denom: denom,
Amount: sdkmath.NewInt(ValidatorFunds),
}
}
}
81 changes: 81 additions & 0 deletions tests/interchain/chainsuite/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package chainsuite

import (
"context"
"fmt"
"time"

"github.com/docker/docker/client"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)

type testReporterKey struct{}

type relayerExecReporterKey struct{}

type loggerKey struct{}

type dockerKey struct{}

type dockerContext struct {
NetworkID string
Client *client.Client
}

func WithDockerContext(ctx context.Context, d *dockerContext) context.Context {
return context.WithValue(ctx, dockerKey{}, d)
}

func GetDockerContext(ctx context.Context) (*client.Client, string) {
d, _ := ctx.Value(dockerKey{}).(*dockerContext)
return d.Client, d.NetworkID
}

func WithTestReporter(ctx context.Context, r *testreporter.Reporter) context.Context {
return context.WithValue(ctx, testReporterKey{}, r)
}

func WithRelayerExecReporter(ctx context.Context, r *testreporter.RelayerExecReporter) context.Context {
return context.WithValue(ctx, relayerExecReporterKey{}, r)
}

func GetRelayerExecReporter(ctx context.Context) *testreporter.RelayerExecReporter {
r, _ := ctx.Value(relayerExecReporterKey{}).(*testreporter.RelayerExecReporter)
return r
}

func WithLogger(ctx context.Context, l *zap.Logger) context.Context {
return context.WithValue(ctx, loggerKey{}, l)
}

func GetLogger(ctx context.Context) *zap.Logger {
l, _ := ctx.Value(loggerKey{}).(*zap.Logger)
return l
}

func NewSuiteContext(s *suite.Suite) (context.Context, error) {
ctx := context.Background()

dockerClient, dockerNetwork := interchaintest.DockerSetup(s.T())
dockerContext := &dockerContext{
NetworkID: dockerNetwork,
Client: dockerClient,
}
ctx = WithDockerContext(ctx, dockerContext)
logger := zaptest.NewLogger(s.T())
ctx = WithLogger(ctx, logger)

f, err := interchaintest.CreateLogFile(fmt.Sprintf("%d.json", time.Now().Unix()))
if err != nil {
return nil, err
}
testReporter := testreporter.NewReporter(f)
ctx = WithTestReporter(ctx, testReporter)
relayerExecReporter := testReporter.RelayerExecReporter(s.T())
ctx = WithRelayerExecReporter(ctx, relayerExecReporter)
return ctx, nil
}
179 changes: 179 additions & 0 deletions tests/interchain/chainsuite/query_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package chainsuite

import (
"time"
)

type Metadata struct {
Name string `json:"name"`
Description string `json:"description"`
Metadata string `json:"metadata"`
}

type ConsumerChain struct {
ChainID string `json:"chain_id"`
ClientID string `json:"client_id"`
TopN int `json:"top_N"`
MinPowerInTopN string `json:"min_power_in_top_N"`
ValidatorsPowerCap int `json:"validators_power_cap"`
ValidatorSetCap int `json:"validator_set_cap"`
Allowlist []string `json:"allowlist"`
Denylist []string `json:"denylist"`
Phase string `json:"phase"`
Metadata Metadata `json:"metadata"`
MinStake string `json:"min_stake"`
AllowInactiveVals bool `json:"allow_inactive_vals"`
ConsumerID string `json:"consumer_id"`
}

type Pagination struct {
NextKey interface{} `json:"next_key"`
Total string `json:"total"`
}

type ListConsumerChainsResponse struct {
Chains []ConsumerChain `json:"chains"`
Pagination Pagination `json:"pagination"`
}

type ConsumerResponse struct {
ChainID string `json:"chain_id"`
ConsumerID string `json:"consumer_id"`
InitParams InitParams `json:"init_params"`
Metadata Metadata `json:"metadata"`
OwnerAddress string `json:"owner_address"`
Phase string `json:"phase"`
PowerShapingParams PowerShapingParams `json:"power_shaping_params"`
}

type InitParams struct {
BinaryHash string `json:"binary_hash"`
BlocksPerDistributionTransmission string `json:"blocks_per_distribution_transmission"`
CCVTimeoutPeriod string `json:"ccv_timeout_period"`
ConsumerRedistributionFraction string `json:"consumer_redistribution_fraction"`
DistributionTransmissionChannel string `json:"distribution_transmission_channel"`
GenesisHash string `json:"genesis_hash"`
HistoricalEntries string `json:"historical_entries"`
InitialHeight InitialHeight `json:"initial_height"`
SpawnTime time.Time `json:"spawn_time"`
TransferTimeoutPeriod string `json:"transfer_timeout_period"`
UnbondingPeriod string `json:"unbonding_period"`
}

type InitialHeight struct {
RevisionHeight string `json:"revision_height"`
RevisionNumber string `json:"revision_number"`
}

type PowerShapingParams struct {
AllowInactiveVals bool `json:"allow_inactive_vals"`
Allowlist []string `json:"allowlist"`
Denylist []string `json:"denylist"`
MinStake string `json:"min_stake"`
TopN int `json:"top_N"`
ValidatorSetCap int `json:"validator_set_cap"`
ValidatorsPowerCap int `json:"validators_power_cap"`
}

type Params struct {
Enabled bool `json:"enabled"`
BlocksPerDistributionTransmission string `json:"blocks_per_distribution_transmission"`
DistributionTransmissionChannel string `json:"distribution_transmission_channel"`
ProviderFeePoolAddrStr string `json:"provider_fee_pool_addr_str"`
CCVTimeoutPeriod string `json:"ccv_timeout_period"`
TransferTimeoutPeriod string `json:"transfer_timeout_period"`
ConsumerRedistributionFraction string `json:"consumer_redistribution_fraction"`
HistoricalEntries string `json:"historical_entries"`
UnbondingPeriod string `json:"unbonding_period"`
SoftOptOutThreshold string `json:"soft_opt_out_threshold"`
RewardDenoms []string `json:"reward_denoms"`
ProviderRewardDenoms []string `json:"provider_reward_denoms"`
RetryDelayPeriod string `json:"retry_delay_period"`
}

type TrustLevel struct {
Numerator string `json:"numerator"`
Denominator string `json:"denominator"`
}

type Height struct {
RevisionNumber string `json:"revision_number"`
RevisionHeight string `json:"revision_height"`
}

type ClientState struct {
ChainID string `json:"chain_id"`
TrustLevel TrustLevel `json:"trust_level"`
TrustingPeriod string `json:"trusting_period"` // Duration as string (e.g., "100s")
UnbondingPeriod string `json:"unbonding_period"` // Duration as string (e.g., "100s")
MaxClockDrift string `json:"max_clock_drift"` // Duration as string (e.g., "100s")
FrozenHeight Height `json:"frozen_height"`
LatestHeight Height `json:"latest_height"`
ProofSpecs []ProofSpec `json:"proof_specs"`
UpgradePath []string `json:"upgrade_path"`
AllowUpdateAfterExpiry bool `json:"allow_update_after_expiry"`
AllowUpdateAfterMisbehaviour bool `json:"allow_update_after_misbehaviour"`
}

type Root struct {
Hash string `json:"hash"`
}

type ConsensusState struct {
Timestamp string `json:"timestamp"`
Root Root `json:"root"`
NextValidatorsHash string `json:"next_validators_hash"`
}

type ProofSpec struct {
LeafSpec LeafSpec `json:"leaf_spec"`
InnerSpec InnerSpec `json:"inner_spec"`
}

type LeafSpec struct {
Hash string `json:"hash"`
PrehashValue string `json:"prehash_value"`
Length string `json:"length"`
Prefix string `json:"prefix"`
}

type InnerSpec struct {
ChildOrder []int `json:"child_order"`
ChildSize int `json:"child_size"`
MinPrefixLength int `json:"min_prefix_length"`
MaxPrefixLength int `json:"max_prefix_length"`
Hash string `json:"hash"`
}

type Provider struct {
ClientState ClientState `json:"client_state"`
ConsensusState ConsensusState `json:"consensus_state"`
InitialValSet []InitialValidator `json:"initial_val_set"`
}

type InitialValidator struct {
PubKey PubKey `json:"pub_key"`
Power string `json:"power"`
}

type PubKey struct {
Ed25519 string `json:"ed25519"`
}

type ConsumerGenesisResponse struct {
Params Params `json:"params"`
NewChain bool `json:"new_chain"`
Provider Provider `json:"provider"`
}

type OptInValidatorsResponse struct {
ValidatorsProviderAddresses []string `json:"validators_provider_addresses"`
}

type ValidatorConsumerAddressResponse struct {
ConsumerAddress string `json:"consumer_address"`
}

type ValidatorProviderAddressResponse struct {
ProviderAddress string `json:"provider_address"`
}
Loading
Loading