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

tests: superfluid delegator voting #1586

Merged
merged 25 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2c87381
change to osmo no stake
czarcas7ic May 23, 2022
f416f6f
currently working
czarcas7ic May 23, 2022
6d7c5d4
superfluid vote overwrite test
czarcas7ic May 25, 2022
9f0ff0a
change docker file
czarcas7ic May 25, 2022
9d33f0d
refactor: e2e setup to be more extensible for state sync (#1565)
p0mvn May 24, 2022
12d4a57
add extract oper address
czarcas7ic May 25, 2022
cac90ee
extract val addr
czarcas7ic May 25, 2022
6904461
new line
czarcas7ic May 25, 2022
ee095d0
delete no longer needed script
czarcas7ic May 25, 2022
e4ec2fb
Merge branch 'main' into adam/sf-tests-2
czarcas7ic May 25, 2022
6a84b6a
Delete .bash_history
czarcas7ic May 25, 2022
966d361
add helper functions to declutter
czarcas7ic May 26, 2022
02bbe8c
remove majority boilerplate
czarcas7ic May 27, 2022
9767416
move docker file back to distroless
czarcas7ic May 27, 2022
eb16e72
Merge branch 'main' into adam/sf-tests-2
czarcas7ic May 27, 2022
a4cabdd
no longer use bash to add account
czarcas7ic May 27, 2022
1e7ee23
Merge branch 'main' into adam/sf-tests-2
czarcas7ic May 27, 2022
c3ea676
remove debugging print statements
czarcas7ic May 27, 2022
0a8d28d
Merge branch 'adam/sf-tests-2' of https://github.com/osmosis-labs/osm…
czarcas7ic May 27, 2022
6c0e355
Delete .bash_history
czarcas7ic May 27, 2022
4c4358f
remove extra line in docker file
czarcas7ic May 27, 2022
e209efb
Apply suggestions from code review
czarcas7ic May 29, 2022
360abcf
code review suggestions
czarcas7ic May 29, 2022
b9b14ef
further validator abstractions
czarcas7ic May 30, 2022
ff4935c
Merge branch 'main' into adam/sf-tests-2
czarcas7ic May 30, 2022
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
# syntax=docker/dockerfile:1

ARG BASE_IMG_TAG=nonroot
Expand Down
175 changes: 173 additions & 2 deletions tests/e2e/chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
staketypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/spf13/viper"
tmconfig "github.com/tendermint/tendermint/config"
tmjson "github.com/tendermint/tendermint/libs/json"

epochtypes "github.com/osmosis-labs/osmosis/v7/x/epochs/types"
gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types"
incentivestypes "github.com/osmosis-labs/osmosis/v7/x/incentives/types"
minttypes "github.com/osmosis-labs/osmosis/v7/x/mint/types"
poolitypes "github.com/osmosis-labs/osmosis/v7/x/pool-incentives/types"
txfeestypes "github.com/osmosis-labs/osmosis/v7/x/txfees/types"

"github.com/osmosis-labs/osmosis/v7/tests/e2e/util"
)

Expand Down Expand Up @@ -52,9 +61,9 @@ const (

var (
StakeAmountIntA = sdk.NewInt(StakeAmountA)
StakeAmountCoinA = sdk.NewCoin(StakeDenom, StakeAmountIntA)
StakeAmountCoinA = sdk.NewCoin(OsmoDenom, StakeAmountIntA)
StakeAmountIntB = sdk.NewInt(StakeAmountB)
StakeAmountCoinB = sdk.NewCoin(StakeDenom, StakeAmountIntB)
StakeAmountCoinB = sdk.NewCoin(OsmoDenom, StakeAmountIntB)

InitBalanceStrA = fmt.Sprintf("%d%s,%d%s", OsmoBalanceA, OsmoDenom, StakeBalanceA, StakeDenom)
InitBalanceStrB = fmt.Sprintf("%d%s,%d%s", OsmoBalanceB, OsmoDenom, StakeBalanceB, StakeDenom)
Expand Down Expand Up @@ -171,6 +180,166 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error {
}
appGenState[banktypes.ModuleName] = bz

// modify stake module genesis params
var stakeGenState staketypes.GenesisState
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
if err := util.Cdc.UnmarshalJSON(appGenState[staketypes.ModuleName], &stakeGenState); err != nil {
return err
}

stakeGenState.Params = staketypes.Params{
BondDenom: OsmoDenom,
MaxValidators: 100,
MaxEntries: 7,
HistoricalEntries: 10000,
UnbondingTime: 240000000000,
MinCommissionRate: sdk.ZeroDec(),
}

sz, err := util.Cdc.MarshalJSON(&stakeGenState)
if err != nil {
return err
}
appGenState[staketypes.ModuleName] = sz
Comment on lines +184 to +202
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For a future PR) I think we should move these to be independent functions, and think of ways to lower the boilerplate involved with them. (e.g. Go Generics)


// modify pool incentives module genesis params
var pooliGenState poolitypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[poolitypes.ModuleName], &pooliGenState); err != nil {
return err
}

pooliGenState.LockableDurations =
[]time.Duration{
time.Second * 120,
time.Second * 180,
time.Second * 240,
}

pooliGenState.Params = poolitypes.Params{
MintedDenom: OsmoDenom,
}

pz, err := util.Cdc.MarshalJSON(&pooliGenState)
if err != nil {
return err
}
appGenState[poolitypes.ModuleName] = pz

// modify incentives module genesis params
var incentivesGenState incentivestypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[incentivestypes.ModuleName], &incentivesGenState); err != nil {
return err
}

incentivesGenState.LockableDurations =
[]time.Duration{
time.Second,
time.Second * 120,
time.Second * 180,
time.Second * 240,
}

incentivesGenState.Params = incentivestypes.Params{
DistrEpochIdentifier: "day",
}

iz, err := util.Cdc.MarshalJSON(&incentivesGenState)
if err != nil {
return err
}
appGenState[incentivestypes.ModuleName] = iz

// modify mint module genesis params
var mintGenState minttypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[minttypes.ModuleName], &mintGenState); err != nil {
return err
}

mintGenState.Params.MintDenom = OsmoDenom
mintGenState.Params.EpochIdentifier = "day"

mz, err := util.Cdc.MarshalJSON(&mintGenState)
if err != nil {
return err
}
appGenState[minttypes.ModuleName] = mz

// modify txfees module genesis params
var txfeesGenState txfeestypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[txfeestypes.ModuleName], &txfeesGenState); err != nil {
return err
}

txfeesGenState.Basedenom = OsmoDenom

tz, err := util.Cdc.MarshalJSON(&txfeesGenState)
if err != nil {
return err
}
appGenState[txfeestypes.ModuleName] = tz

// modify gamm module genesis params
var gammGenState gammtypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[gammtypes.ModuleName], &gammGenState); err != nil {
return err
}

gammGenState.Params.PoolCreationFee = sdk.Coins{sdk.NewInt64Coin(OsmoDenom, 10000000)}

gaz, err := util.Cdc.MarshalJSON(&gammGenState)
if err != nil {
return err
}
appGenState[gammtypes.ModuleName] = gaz

// modify epoch module genesis params
var epochGenState epochtypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[epochtypes.ModuleName], &epochGenState); err != nil {
return err
}

epochGenState.Epochs =
[]epochtypes.EpochInfo{
{
Identifier: "week",
StartTime: time.Time{},
Duration: time.Hour * 24 * 7,
CurrentEpoch: 0,
CurrentEpochStartHeight: 0,
CurrentEpochStartTime: time.Time{},
EpochCountingStarted: false,
},
{
Identifier: "day",
StartTime: time.Time{},
Duration: time.Second * 60,
CurrentEpoch: 0,
CurrentEpochStartHeight: 0,
CurrentEpochStartTime: time.Time{},
EpochCountingStarted: false,
},
}

ez, err := util.Cdc.MarshalJSON(&epochGenState)
if err != nil {
return err
}
appGenState[epochtypes.ModuleName] = ez

// modify crisis module genesis params
var crisisGenState crisistypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[crisistypes.ModuleName], &crisisGenState); err != nil {
return err
}

crisisGenState.ConstantFee.Denom = OsmoDenom

cz, err := util.Cdc.MarshalJSON(&crisisGenState)
if err != nil {
return err
}
appGenState[crisistypes.ModuleName] = cz

// modify gov module genesis params
var govGenState govtypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState); err != nil {
return err
Expand All @@ -180,6 +349,8 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error {
VotingPeriod: votingPeriod,
}

govGenState.DepositParams.MinDeposit = sdk.Coins{sdk.NewInt64Coin(OsmoDenom, 10000000)}

gz, err := util.Cdc.MarshalJSON(&govGenState)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/chain/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Validator struct {
Index int `json:"index"`
Mnemonic string `json:"mnemonic"`
PublicAddress string `json:"publicAddress"`
PublicKey string `json:"publicKey"`
OperAddress string `json:"operAddress"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as it is not used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to store this value for each validator so we are able to SFS to their operator address

Copy link
Member

@p0mvn p0mvn May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to keep these Validator and Chain structs only used for transferring state between the "chain-initialization" part (that happens inside a Docker container) and the test runner part (in e2e package). The goal of this is to decouple the chain initialization and test runner components as much as possible.

I know there is still some coupling present right now but the goal is to eventually get to completely independent components with incremental refactoring.

So this OperAddress is never used during chain initialization. I think if we want to keep adding more state to Validator or Chain structs, we should wrap them into structs that are local to the e2e package:

type validatorConfig struct {
	validator chain.Validator
        operatorAddress   string
}

We already do something similar with chain.Chain:

type chainConfig struct {
// voting period is number of blocks it takes to deposit, 1.2 seconds per validator to vote on the prop, and a buffer.
votingPeriod float32
// upgrade proposal height for chain.
propHeight int
// Indexes of the validators to skip from running during initialization.
// This is needed for testing functionality like state-sync where we would
// like to start a node during tests post-initialization.
skipRunValidatorIndexes map[int]struct{}
latestProposalNumber int
latestLockNumber int
chain *chain.Chain
}

Here, instead of adding the fields directly to chain.Chain we wrap it into the chainConfig struct

Please let me know what you think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this to an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get to it now, if it proves to be a difficult change (it shouldn't be) then I will make an issue instead and merge

}

type Chain struct {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/chain/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (v *internalValidator) export() *Validator {
Index: v.index,
Mnemonic: v.mnemonic,
PublicAddress: v.keyInfo.GetAddress().String(),
PublicKey: v.keyInfo.GetPubKey().Address().String(),
}
}

Expand Down
13 changes: 9 additions & 4 deletions tests/e2e/chain_init/chain-init.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ RUN apk add linux-headers
WORKDIR /osmosis
COPY . /osmosis

# From https://github.com/CosmWasm/wasmd/blob/master/Dockerfile
# For more details see https://github.com/CosmWasm/wasmvm#builds-of-libwasmvm
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479
# CosmWasm: see https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 7d2239e9f25e96d0d4daba982ce92367aacf0cbd95d2facb8442268f2b1cc1fc
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479

# CosmWasm: copy the right library according to architecture. The final location will be found by the linker flag `-lwasmvm_muslc`
RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a

RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build-e2e-chain-init

## Deploy image
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/docker/image_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const (
// It should be uploaded to Docker Hub. OSMOSIS_E2E_SKIP_UPGRADE should be unset
// for this functionality to be used.
previousVersionOsmoRepository = "osmolabs/osmosis-dev"
previousVersionOsmoTag = "v8.0.0-debug"
previousVersionOsmoTag = "v8.0.0-2-debug"
// Pre-upgrade repo/tag for osmosis initialization (this should be one version below upgradeVersion)
previousVersionInitRepository = "osmolabs/osmosis-init"
previousVersionInitTag = "v8.0.0"
previousVersionInitTag = "v8.0.0-4-osmo"
// Hermes repo/version for relayer
relayerRepository = "osmolabs/hermes"
relayerTag = "0.13.0"
Expand Down
17 changes: 12 additions & 5 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type syncInfo struct {
SyncInfo status `json:"SyncInfo"`
}

type operInfo struct {
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
Bech32Val string `json:"bech32_val"`
}

type chainConfig struct {
// voting period is number of blocks it takes to deposit, 1.2 seconds per validator to vote on the prop, and a buffer.
votingPeriod float32
Expand All @@ -42,6 +46,8 @@ type chainConfig struct {
// This is needed for testing functionality like state-sync where we would
// like to start a node during tests post-initialization.
skipRunValidatorIndexes map[int]struct{}
propNumber int
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
lockNumber int
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
chain *chain.Chain
}

Expand Down Expand Up @@ -167,6 +173,7 @@ func (s *IntegrationTestSuite) SetupSuite() {

for i, chainConfig := range s.chainConfigs {
s.runValidators(chainConfig, s.dockerImages.OsmosisRepository, s.dockerImages.OsmosisTag, i*10)
s.extractValidatorOperatorAddress(chainConfig)
}

// Run a relayer between every possible pair of chains.
Expand Down Expand Up @@ -474,10 +481,10 @@ func (s *IntegrationTestSuite) upgrade() {
// submit, deposit, and vote for upgrade proposal
// prop height = current height + voting period + time it takes to submit proposal + small buffer
for _, chainConfig := range s.chainConfigs {
currentHeight := s.getCurrentChainHeight(s.valResources[chainConfig.chain.ChainMeta.Id][0].Container.ID)
currentHeight := s.getCurrentChainHeight(chainConfig.chain, 0)
chainConfig.propHeight = currentHeight + int(chainConfig.votingPeriod) + int(propSubmitBlocks) + int(propBufferBlocks)
s.submitProposal(chainConfig.chain, chainConfig.propHeight)
s.depositProposal(chainConfig.chain)
s.submitUpgradeProposal(chainConfig)
s.depositProposal(chainConfig)
s.voteProposal(chainConfig)
}

Expand All @@ -495,7 +502,7 @@ func (s *IntegrationTestSuite) upgrade() {
s.T().Logf("waiting to reach upgrade height on %s validator container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], s.valResources[curChain.ChainMeta.Id][i].Container.ID)
s.Require().Eventually(
func() bool {
currentHeight := s.getCurrentChainHeight(s.valResources[curChain.ChainMeta.Id][i].Container.ID)
currentHeight := s.getCurrentChainHeight(chainConfig.chain, i)
if currentHeight != chainConfig.propHeight {
s.T().Logf("current block height on %s is %v, waiting for block %v container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], currentHeight, chainConfig.propHeight, s.valResources[curChain.ChainMeta.Id][i].Container.ID)
}
Expand Down Expand Up @@ -574,7 +581,7 @@ func (s *IntegrationTestSuite) upgradeContainers(chainConfig *chainConfig, propH

s.Require().Eventually(
func() bool {
currentHeight := s.getCurrentChainHeight(s.valResources[chain.ChainMeta.Id][i].Container.ID)
currentHeight := s.getCurrentChainHeight(chainConfig.chain, i)
if currentHeight <= propHeight {
s.T().Logf("current block height on %s is %v, waiting to create blocks container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], currentHeight, s.valResources[chain.ChainMeta.Id][i].Container.ID)
}
Expand Down
Loading