Skip to content

Commit

Permalink
test: upgrade testing automation (#1389)
Browse files Browse the repository at this point in the history
* upgrade init

* add voting period to init image

* upgrade mvp

* move upgrade to setup

* permission fix

* github permissions

* delete to readd

* readd

* remove chmod

* permissions attempt

* permission change

* clean up

* remove init docker image creation

* test yml

* re add git diff

* revert dockerfile

* final github ci test

* revert

* initial code review changes

* Apply suggestions from code review

Co-authored-by: Roman <roman@osmosis.team>

* code review

* simple code 0 check

* Add scaling factors (#1354)

Closes: #1277

## What is the purpose of the change

This PR adds scaling factors to current stable swap implementation. 

For context on why scaling factors are needed: Suppose 1000 stablecoin1 equals 1 dollars, 100 stablecoin2 equals 2 dollars due to precision difference. Currently we compare each pool assets without considering these differences in precisions in `calcOutAmtGivenIn`, `calcInAmtGivenOut`, `SpotPrice`. 

This PR adds a field of scaling factors for each pool asset so that when internally calculating in `amm.go`, we compare two different assets upon same precision points. We do this by feeding the internal functions assets / scaling factors.

## Brief change log

- Adds scaling factor to stableswap
*(for example:)*
 
  - *The metadata is stored in the blob store on job creation time as a persistent artifact*
  - *Deployments RPC transmits only the blob storage reference*
  - *Daemons retrieve the RPC data from the blob cache*


## Testing and Verifying

This change is a trivial rework / code cleanup without any test coverage.


## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? yes
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? no
  - How is the feature or change documented? not applicable

* address roman comments

Co-authored-by: Roman <roman@osmosis.team>
Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
  • Loading branch information
4 people authored May 5, 2022
1 parent 5166db4 commit 94caf2b
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 48 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ jobs:
- name: Build Docker Image
run: |
make docker-build-debug
make docker-build-e2e-chain-init
if: env.GIT_DIFF
- name: Test E2E
run: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN sha256sum /lib/libwasmvm_muslc.a | grep d0152067a5609bfdfb3f0d5d6c0f2760f79d
RUN BUILD_TAGS=muslc make build

## Deploy image
FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG}
FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG}

COPY --from=build /osmosis/build/osmosisd /bin/osmosisd

Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/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"
"github.com/spf13/viper"
tmconfig "github.com/tendermint/tendermint/config"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand All @@ -27,6 +28,7 @@ const (
IbcDenom = "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518"
MinGasPrice = "0.000"
IbcSendAmount = 3300000000
VotingPeriod = 30000000000 // 30 seconds
// chainA
ChainAID = "osmo-test-a"
OsmoBalanceA = 200000000000
Expand Down Expand Up @@ -158,6 +160,21 @@ func initGenesis(c *internalChain) error {
}
appGenState[banktypes.ModuleName] = bz

var govGenState govtypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState); err != nil {
return err
}

govGenState.VotingParams = govtypes.VotingParams{
VotingPeriod: VotingPeriod,
}

gz, err := util.Cdc.MarshalJSON(&govGenState)
if err != nil {
return err
}
appGenState[govtypes.ModuleName] = gz

var genUtilGenState genutiltypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[genutiltypes.ModuleName], &genUtilGenState); err != nil {
return err
Expand Down
107 changes: 100 additions & 7 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ type IntegrationTestSuite struct {
valResources map[string][]*dockertest.Resource
}

type status struct {
LatestHeight string `json:"latest_block_height"`
}

type syncInfo struct {
SyncInfo status `json:"SyncInfo"`
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
Expand All @@ -58,13 +66,13 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.configureDockerResources(chain.ChainAID, chain.ChainBID)

s.configureChain(chain.ChainAID)
s.Require().NoError(s.dkrPool.Purge(s.initResource))
s.configureChain(chain.ChainBID)
s.Require().NoError(s.dkrPool.Purge(s.initResource))

s.runValidators(s.chains[0], 0)
s.runValidators(s.chains[1], 10)
s.runIBCRelayer()
s.initUpgrade()
s.upgrade()
}

func (s *IntegrationTestSuite) TearDownSuite() {
Expand Down Expand Up @@ -100,7 +108,6 @@ func (s *IntegrationTestSuite) TearDownSuite() {

func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) {
s.T().Logf("starting Osmosis %s validator containers...", c.ChainMeta.Id)

s.valResources[c.ChainMeta.Id] = make([]*dockertest.Resource, len(c.Validators))
for i, val := range c.Validators {
runOpts := &dockertest.RunOptions{
Expand All @@ -109,8 +116,11 @@ func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) {
Mounts: []string{
fmt.Sprintf("%s/:/osmosis/.osmosisd", val.ConfigDir),
},
Repository: "osmosis",
Tag: "debug",
Repository: "osmolabs/osmosis-dev",
Tag: "v7.2.1-debug",
Cmd: []string{
"start",
},
}

// expose the first validator for debugging and communication
Expand Down Expand Up @@ -267,8 +277,8 @@ func (s *IntegrationTestSuite) configureChain(chainId string) {
s.initResource, err = s.dkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: fmt.Sprintf("%s", chainId),
Repository: "osmosis-e2e-chain-init",
Tag: "debug",
Repository: "osmolabs/osmosis-init",
Tag: "v7.2.1",
NetworkID: s.dkrNet.Network.ID,
Cmd: []string{
fmt.Sprintf("--data-dir=%s", tmpDir),
Expand Down Expand Up @@ -306,6 +316,7 @@ func (s *IntegrationTestSuite) configureChain(chainId string) {
}
}
s.chains = append(s.chains, &newChain)
s.Require().NoError(s.dkrPool.Purge(s.initResource))
}

func (s *IntegrationTestSuite) configureDockerResources(chainIDOne, chainIDTwo string) {
Expand All @@ -325,3 +336,85 @@ func noRestart(config *docker.HostConfig) {
Name: "no",
}
}

func (s *IntegrationTestSuite) initUpgrade() {
// submit, deposit, and vote for upgrade proposal
s.submitProposal(s.chains[0])
s.submitProposal(s.chains[1])
s.depositProposal(s.chains[0])
s.depositProposal(s.chains[1])
s.voteProposal(s.chains[0])
s.voteProposal(s.chains[1])

// wait till all chains halt at upgrade height
for _, chain := range s.chains {
for i := range chain.Validators {
s.T().Logf("waiting to reach upgrade height on %s validator container: %s", chain.ChainMeta.Id, s.valResources[chain.ChainMeta.Id][i].Container.ID)
s.Require().Eventually(
func() bool {
out := s.chainStatus(s.valResources[chain.ChainMeta.Id][i].Container.ID)
var syncInfo syncInfo
json.Unmarshal(out, &syncInfo)
if syncInfo.SyncInfo.LatestHeight != "75" {
s.T().Logf("current block height is %v, waiting for block 75 container: %s", syncInfo.SyncInfo.LatestHeight, s.valResources[chain.ChainMeta.Id][i].Container.ID)
}
return syncInfo.SyncInfo.LatestHeight == "75"
},
2*time.Minute,
5*time.Second,
)
s.T().Logf("reached upgrade height on %s validator container: %s", chain.ChainMeta.Id, s.valResources[chain.ChainMeta.Id][i].Container.ID)
}
}

// remove all containers so we can upgrade them to the new version
for _, chain := range s.chains {
for i := range chain.Validators {
s.Require().NoError(s.dkrPool.RemoveContainerByName(s.valResources[chain.ChainMeta.Id][i].Container.Name))
}
}
}

func (s *IntegrationTestSuite) upgrade() {
// upgrade containers to the locally compiled daemon
for _, chain := range s.chains {
s.T().Logf("starting upgrade for chain-id: %s...", chain.ChainMeta.Id)
for i, val := range chain.Validators {
runOpts := &dockertest.RunOptions{
Name: val.Name,
Repository: "osmosis",
Tag: "debug",
NetworkID: s.dkrNet.Network.ID,
User: "root:root",
Mounts: []string{
fmt.Sprintf("%s/:/osmosis/.osmosisd", val.ConfigDir),
},
}
resource, err := s.dkrPool.RunWithOptions(runOpts, noRestart)
s.Require().NoError(err)

s.valResources[chain.ChainMeta.Id][i] = resource
s.T().Logf("started Osmosis %s validator container: %s", chain.ChainMeta.Id, resource.Container.ID)
}
}

// check that we are hitting blocks again
for _, chain := range s.chains {
for i := range chain.Validators {
s.Require().Eventually(
func() bool {
out := s.chainStatus(s.valResources[chain.ChainMeta.Id][i].Container.ID)
var syncInfo syncInfo
json.Unmarshal(out, &syncInfo)
if syncInfo.SyncInfo.LatestHeight <= "75" {
fmt.Printf("current block height is %v, waiting to hit blocks\n", syncInfo.SyncInfo.LatestHeight)
}
return syncInfo.SyncInfo.LatestHeight > "75"
},
2*time.Minute,
5*time.Second,
)
s.T().Logf("upgrade successful on %s validator container: %s", chain.ChainMeta.Id, s.valResources[chain.ChainMeta.Id][i].Container.ID)
}
}
}
78 changes: 39 additions & 39 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,45 @@ import (
"github.com/osmosis-labs/osmosis/v7/tests/e2e/util"
)

func (s *IntegrationTestSuite) TestQueryBalances() {
func (s *IntegrationTestSuite) Test001IBCTokenTransfer() {
var ibcStakeDenom string

s.Run("send_uosmo_to_chainB", func() {
recipient := s.chains[1].Validators[0].PublicAddress
token := sdk.NewInt64Coin(chain.OsmoDenom, chain.IbcSendAmount) // 3,300uosmo
s.sendIBC(s.chains[0].ChainMeta.Id, s.chains[1].ChainMeta.Id, recipient, token)

chainBAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chains[1].ChainMeta.Id][0].GetHostPort("1317/tcp"))

// require the recipient account receives the IBC tokens (IBC packets ACKd)
var (
balances sdk.Coins
err error
)
s.Require().Eventually(
func() bool {
balances, err = queryBalances(chainBAPIEndpoint, recipient)
s.Require().NoError(err)

return balances.Len() == 3
},
time.Minute,
5*time.Second,
)

for _, c := range balances {
if strings.Contains(c.Denom, "ibc/") {
ibcStakeDenom = c.Denom
s.Require().Equal(token.Amount.Int64(), c.Amount.Int64())
break
}
}

s.Require().NotEmpty(ibcStakeDenom)
})
}

func (s *IntegrationTestSuite) Test002QueryBalances() {
var (
expectedDenomsA = []string{chain.OsmoDenom, chain.StakeDenom}
expectedDenomsB = []string{chain.OsmoDenom, chain.StakeDenom, chain.IbcDenom}
Expand Down Expand Up @@ -95,41 +133,3 @@ func queryBalances(endpoint, addr string) (sdk.Coins, error) {

return balancesResp.GetBalances(), nil
}

func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
var ibcStakeDenom string

s.Run("send_uosmo_to_chainB", func() {
recipient := s.chains[1].Validators[0].PublicAddress
token := sdk.NewInt64Coin(chain.OsmoDenom, chain.IbcSendAmount) // 3,300uosmo
s.sendIBC(s.chains[0].ChainMeta.Id, s.chains[1].ChainMeta.Id, recipient, token)

chainBAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chains[1].ChainMeta.Id][0].GetHostPort("1317/tcp"))

// require the recipient account receives the IBC tokens (IBC packets ACKd)
var (
balances sdk.Coins
err error
)
s.Require().Eventually(
func() bool {
balances, err = queryBalances(chainBAPIEndpoint, recipient)
s.Require().NoError(err)

return balances.Len() == 3
},
time.Minute,
5*time.Second,
)

for _, c := range balances {
if strings.Contains(c.Denom, "ibc/") {
ibcStakeDenom = c.Denom
s.Require().Equal(token.Amount.Int64(), c.Amount.Int64())
break
}
}

s.Require().NotEmpty(ibcStakeDenom)
})
}
Loading

0 comments on commit 94caf2b

Please sign in to comment.