Skip to content

Commit

Permalink
Merge branch 'main' into terpay/max-to-target-ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay authored Dec 5, 2023
2 parents 51df770 + 97e3a17 commit 90adbf5
Show file tree
Hide file tree
Showing 31 changed files with 1,313 additions and 291 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ictest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: tests
if: env.GIT_DIFF
run: |
go work init && make test-integration
go work init && make test-e2e
26 changes: 22 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
push:
branches:
- main
paths-ignore:
- tests/**

permissions:
contents: read
Expand All @@ -16,7 +14,7 @@ concurrency:
cancel-in-progress: true

jobs:
test:
test-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -35,4 +33,24 @@ jobs:
- name: tests
if: env.GIT_DIFF
run: |
make test
make test-unit
test-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.21.4
cache: true
cache-dependency-path: go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
**/*.go
go.mod
go.sum
- name: tests
if: env.GIT_DIFF
run: |
make test-integration
33 changes: 18 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ COVER_HTML_FILE := cover.html

use-main:
@go work edit -use .
@go work edit -dropuse ./tests/integration
@go work edit -dropuse ./tests/e2e

use-integration:
use-e2e:
@go work edit -dropuse .
@go work edit -use ./tests/integration
@go work edit -use ./tests/e2e

tidy:
@go mod tidy
Expand Down Expand Up @@ -102,7 +102,7 @@ build-and-start-app: build-test-app

.PHONY: build-test-app build-and-start-app

.PHONY: docker-build docker-build-integration
.PHONY: docker-build docker-build-e2e
###############################################################################
## Docker ##
###############################################################################
Expand All @@ -111,25 +111,27 @@ docker-build: use-main
@echo "Building E2E Docker image..."
@DOCKER_BUILDKIT=1 docker build -t skip-mev/feemarket-e2e -f contrib/images/feemarket.e2e.Dockerfile .

docker-build-integration: use-main
@echo "Building integration-test Docker image..."
@DOCKER_BUILDKIT=1 docker build -t feemarket-integration -f contrib/images/feemarket.integration.Dockerfile .
docker-build-e2e: use-main
@echo "Building e2e-test Docker image..."
@DOCKER_BUILDKIT=1 docker build -t feemarket-e2e -f contrib/images/feemarket.e2e.Dockerfile .

###############################################################################
### Tests ###
###############################################################################

TEST_INTEGRATION_DEPS = docker-build-integration use-integration
TEST_INTEGRATION_TAGS = integration
TEST_E2E_DEPS = docker-build-e2e use-e2e
TEST_E2E_TAGS = e2e

test-integration: $(TEST_INTEGRATION_DEPS)
@echo "Running integration tests..."
@go test ./tests/integration/integration_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_INTEGRATION_TAGS)'
test-e2e: $(TEST_E2E_DEPS)
@echo "Running e2e tests..."
@go test ./tests/e2e/e2e_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_E2E_TAGS)'

test:
test-unit:
@go test -v -race $(shell go list ./... | grep -v tests/)

## test-cover: Run the unit tests and create a coverage html report
test-integration:
@go test -v -race ./tests/integration

test-cover:
@echo Running unit tests and creating coverage report...
@go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE) -covermode=atomic $(shell go list ./... | grep -v tests/ | grep -v api/ | grep -v testutils/)
Expand All @@ -138,8 +140,9 @@ test-cover:
@go tool cover -html=$(COVER_FILE) -o $(COVER_HTML_FILE)
@rm $(COVER_FILE)

test-all: test-unit test-integration test-e2e

.PHONY: test test-integration
.PHONY: test-unit test-e2e test-integration test-cover test-all

###############################################################################
### Protobuf ###
Expand Down
File renamed without changes.
105 changes: 105 additions & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package e2e_test

import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
interchaintest "github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
ictestutil "github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/suite"

"github.com/skip-mev/feemarket/tests/e2e"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)

var (
// config params
numValidators = 3
numFullNodes = 1
denom = "stake"

image = ibc.DockerImage{
Repository: "feemarket-e2e",
Version: "latest",
UidGid: "1000:1000",
}
encodingConfig = MakeEncodingConfig()
noHostMount = false
gasAdjustment = 10.0

genesisKV = []cosmos.GenesisKV{
{
Key: "app_state.feemarket.params",
Value: feemarkettypes.NewParams(
feemarkettypes.DefaultWindow,
feemarkettypes.DefaultAlpha,
feemarkettypes.DefaultBeta,
feemarkettypes.DefaultTheta,
feemarkettypes.DefaultDelta,
feemarkettypes.DefaultTargetBlockUtilization,
feemarkettypes.DefaultMaxBlockUtilization,
sdk.NewInt(1000),
feemarkettypes.DefaultMinLearningRate,
feemarkettypes.DefaultMaxLearningRate,
feemarkettypes.DefaultFeeDenom,
true,
),
},
{
Key: "app_state.feemarket.state",
Value: feemarkettypes.NewState(
feemarkettypes.DefaultWindow,
sdk.NewInt(1000),
feemarkettypes.DefaultMaxLearningRate,
),
},
}

consensusParams = ictestutil.Toml{
"timeout_commit": "3500ms",
}

// interchain specification
spec = &interchaintest.ChainSpec{
ChainName: "feemarket",
Name: "feemarket",
NumValidators: &numValidators,
NumFullNodes: &numFullNodes,
Version: "latest",
NoHostMount: &noHostMount,
ChainConfig: ibc.ChainConfig{
EncodingConfig: encodingConfig,
Images: []ibc.DockerImage{
image,
},
Type: "cosmos",
Name: "feemarket",
Denom: denom,
ChainID: "chain-id-0",
Bin: "feemarketd",
Bech32Prefix: "cosmos",
CoinType: "118",
GasAdjustment: gasAdjustment,
GasPrices: fmt.Sprintf("50%s", denom),
TrustingPeriod: "48h",
NoHostMount: noHostMount,
ModifyGenesis: cosmos.ModifyGenesis(genesisKV),
ConfigFileOverrides: map[string]any{"config/config.toml": ictestutil.Toml{"consensus": consensusParams}},
},
}
)

func MakeEncodingConfig() *testutil.TestEncodingConfig {
cfg := cosmos.DefaultEncoding()
feemarkettypes.RegisterInterfaces(cfg.InterfaceRegistry)
return &cfg
}

func TestE2ETestSuite(t *testing.T) {
s := e2e.NewE2ETestSuiteFromSpec(spec)
suite.Run(t, s)
}
8 changes: 4 additions & 4 deletions tests/integration/go.mod → tests/e2e/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module github.com/skip-mev/feemarket/tests/integration
module github.com/skip-mev/feemarket/tests/e2e

go 1.21.4

replace (
cosmossdk.io/api => cosmossdk.io/api v0.3.1
Expand All @@ -14,11 +16,9 @@ replace (
golang.org/x/exp => golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2
)

go 1.21.4

require (
github.com/cometbft/cometbft v0.37.2
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/cosmos-sdk v0.47.6
github.com/skip-mev/feemarket v0.0.0-00010101000000-000000000000
github.com/strangelove-ventures/interchaintest/v7 v7.0.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/go.sum → tests/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.47.5 h1:n1+WjP/VM/gAEOx3TqU2/Ny734rj/MX1kpUnn7zVJP8=
github.com/cosmos/cosmos-sdk v0.47.5/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/cosmos/cosmos-sdk v0.47.6 h1:uyo/eg9NMB66aQZIZUv/LeOPTdSnsU23wZkgFYpjikQ=
github.com/cosmos/cosmos-sdk v0.47.6/go.mod h1:xTc1chW8HyUWCfrgGbjS5jNu9RzlPVrBNfbL9RmZUio=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down
19 changes: 5 additions & 14 deletions tests/integration/setup.go → tests/e2e/setup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package e2e

import (
"archive/tar"
Expand All @@ -8,14 +8,15 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"os"
"path"
"strconv"
"strings"
"testing"
"time"

"github.com/skip-mev/feemarket/testutils/sample"

rpctypes "github.com/cometbft/cometbft/rpc/core/types"
comettypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -402,7 +403,7 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic(
chain *cosmos.CosmosChain,
) (ibc.Wallet, error) {
chainCfg := chain.Config()
keyName := fmt.Sprintf("%s-%s-%s", keyNamePrefix, chainCfg.ChainID, RandLowerCaseLetterString(3))
keyName := fmt.Sprintf("%s-%s-%s", keyNamePrefix, chainCfg.ChainID, sample.AlphaString(r, 3))
user, err := chain.BuildWallet(ctx, keyName, mnemonic)
if err != nil {
return nil, fmt.Errorf("failed to get source user wallet: %w", err)
Expand Down Expand Up @@ -453,6 +454,7 @@ func (s *TestSuite) GetAndFundTestUsers(
return users
}

// ExecTx executes a cli command on a node, waits a block and queries the Tx to verify it was included on chain.
func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyName string, command ...string) (string, error) {
node := chain.FullNodes[0]

Expand All @@ -469,14 +471,3 @@ func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyNa

return string(stdout), nil
}

// RandLowerCaseLetterString returns a lowercase letter string of given length
func RandLowerCaseLetterString(length int) string {
chars := []byte("abcdefghijklmnopqrstuvwxyz")

b := make([]byte, length)
for i := range b {
b[i] = chars[rand.Intn(len(chars))]
}
return string(b)
}
19 changes: 14 additions & 5 deletions tests/integration/suite.go → tests/e2e/suite.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package integration
package e2e

import (
"context"
"math/rand"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -17,7 +18,15 @@ const (
initBalance = 10000000000000
)

// TestSuite runs the feemarket integration test-suite against a given interchaintest specification
var r *rand.Rand

// initialize random generator with fixed seed for reproducibility
func init() {
s := rand.NewSource(1)
r = rand.New(s)
}

// TestSuite runs the feemarket e2e test-suite against a given interchaintest specification
type TestSuite struct {
suite.Suite
// spec
Expand All @@ -40,7 +49,7 @@ type TestSuite struct {
cdc codec.Codec
}

func NewIntegrationTestSuiteFromSpec(spec *interchaintest.ChainSpec) *TestSuite {
func NewE2ETestSuiteFromSpec(spec *interchaintest.ChainSpec) *TestSuite {
return &TestSuite{
spec: spec,
denom: "stake",
Expand Down Expand Up @@ -109,8 +118,7 @@ func (s *TestSuite) SetupSubTest() {

state := s.QueryState()

s.T().Log("new test case at block height", height+1)
s.T().Log("state:", state.String())
s.T().Log("state at block height", height+1, ":", state.String())
}

func (s *TestSuite) TestQueryParams() {
Expand Down Expand Up @@ -171,5 +179,6 @@ func (s *TestSuite) TestSendTxUpdating() {
gas,
)
s.Require().NoError(err, txResp)
s.T().Log(txResp)
})
}
Loading

0 comments on commit 90adbf5

Please sign in to comment.