Skip to content

Commit

Permalink
refactor test to run with new setup (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba authored and brennanjl committed Feb 26, 2024
1 parent 5e3d9e7 commit 3eb3ac2
Show file tree
Hide file tree
Showing 97 changed files with 1,139 additions and 6,507 deletions.
19 changes: 16 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,24 @@ tasks:
cmds:
- go test ./test/acceptance/ -timeout 12h -dev -v

dev:up:no-build:
dev:up:nb:
desc: Start the dev environment without rebuilding docker image
cmds:
- go test ./test/acceptance/ -timeout 12h -dev -v

dev:testnet:up:
desc: Start the dev environment(with testnet)
deps:
- task: build:docker
vars: { VARIANT: 'shell' }
cmds:
- go test ./test/integration/ -timeout 12h -dev -v

dev:testnet:up:nb:
desc: Start the dev environment(with testnet) without rebuilding docker image
cmds:
- go test ./test/integration/ -timeout 12h -dev -v

# ************ test ************
test:act:
desc: Run acceptance tests
Expand All @@ -120,7 +133,7 @@ tasks:
cmds:
- go test ./test/acceptance/ -v

test:act:no-build:
test:act:nb:
desc: Run acceptance tests without building docker image
cmds:
- go test ./test/acceptance/ -count=1 -v
Expand All @@ -136,4 +149,4 @@ tasks:
desc: Run integration tests
#deps: [ build:docker ]
cmds:
- go test -count=1 -timeout 0 ./test/integration-tests/ -v
- go test -count=1 -timeout 0 ./test/integration/ -v
8 changes: 2 additions & 6 deletions build/package/docker/kwild.debug.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ ARG git_commit
WORKDIR /app
RUN apk update && apk add git openssh

RUN echo -e "[url \"[email protected]:\"]\n\tinsteadOf = https://github.com/" >> /root/.gitconfig
RUN cat /root/.gitconfig
RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config

COPY . .
# use `go mod vendor` to speed up build for CI & access private deps
#RUN go mod download
RUN test -f go.work && rm go.work || true

RUN GIT_VERSION=$version GIT_COMMIT=$git_commit BUILD_TIME=$build_time GO_GCFLAGS="all=-N -l" CGO_ENABLED=0 TARGET="/app/dist" ./scripts/build/binary kwild
RUN chmod +x /app/dist/kwild-*

Expand Down
5 changes: 2 additions & 3 deletions build/package/docker/kwild.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ WORKDIR /app
RUN apk update && apk add git openssh

COPY . .
RUN rm go.work
# use `go mod vendor` to speed up build for CI & access private deps
#RUN go mod download
RUN test -f go.work && rm go.work || true

RUN GIT_VERSION=$version GIT_COMMIT=$git_commit BUILD_TIME=$build_time CGO_ENABLED=0 TARGET="/app/dist" ./scripts/build/binary kwild
RUN chmod +x /app/dist/kwild-*

Expand Down
8 changes: 2 additions & 6 deletions build/package/docker/kwild.shell.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ ARG git_commit
WORKDIR /app
RUN apk update && apk add git openssh

RUN echo -e "[url \"[email protected]:\"]\n\tinsteadOf = https://github.com/" >> /root/.gitconfig
RUN cat /root/.gitconfig
RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config

COPY . .
# use `go mod vendor` to speed up build for CI & access private deps
#RUN go mod download
RUN test -f go.work && rm go.work || true

RUN GIT_VERSION=$version GIT_COMMIT=$git_commit BUILD_TIME=$build_time CGO_ENABLED=0 TARGET="/app/dist" ./scripts/build/binary kwild
RUN chmod +x /app/dist/kwild-*

Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/ethereum/go-ethereum v1.12.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.5
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0
github.com/joho/godotenv v1.5.1
github.com/jpillora/backoff v1.0.0
github.com/kwilteam/action-grammar-go v0.0.0
github.com/kwilteam/go-sqlite v0.0.0-20230606000142-c7eaa7111421
Expand Down Expand Up @@ -130,7 +131,6 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/theupdateframework/notary v0.7.0 // indirect
github.com/tidwall/tinylru v1.1.0 // indirect
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 // indirect
github.com/tonistiigi/fsutil v0.0.0-20230105215944-fb433841cbfa // indirect
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
Expand Down Expand Up @@ -221,10 +221,6 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/tidwall/gjson v1.14.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/wal v1.1.7
github.com/tklauser/go-sysconf v0.3.6 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
Expand Down
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
Expand Down Expand Up @@ -838,17 +840,6 @@ github.com/testcontainers/testcontainers-go/modules/compose v0.20.1 h1:I6/IB2gzl
github.com/testcontainers/testcontainers-go/modules/compose v0.20.1/go.mod h1:sCzdl1NTL1KexCVYlTNmY/ji/Y5JAZJRL6zHQlXKSkM=
github.com/theupdateframework/notary v0.7.0 h1:QyagRZ7wlSpjT5N2qQAh/pN+DVqgekv4DzbAiAiEL3c=
github.com/theupdateframework/notary v0.7.0/go.mod h1:c9DRxcmhHmVLDay4/2fUYdISnHqbFDGRSlXPO0AhYWw=
github.com/tidwall/gjson v1.10.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/tinylru v1.1.0 h1:XY6IUfzVTU9rpwdhKUF6nQdChgCdGjkMfLzbWyiau6I=
github.com/tidwall/tinylru v1.1.0/go.mod h1:3+bX+TJ2baOLMWTnlyNWHh4QMnFyARg2TLTQ6OFbzw8=
github.com/tidwall/wal v1.1.7 h1:emc1TRjIVsdKKSnpwGBAcsAGg0767SvUk8+ygx7Bb+4=
github.com/tidwall/wal v1.1.7/go.mod h1:r6lR1j27W9EPalgHiB7zLJDYu3mzW5BQP5KrzBpYY/E=
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 h1:QB54BJwA6x8QU9nHY3xJSZR2kX9bgpZekRKGkLTmEXA=
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375/go.mod h1:xRroudyp5iVtxKqZCrA6n2TLFRBf8bmnjr1UD4x+z7g=
github.com/tklauser/go-sysconf v0.3.6 h1:oc1sJWvKkmvIxhDHeKWvZS4f6AW+YcoguSfRF2/Hmo4=
Expand Down
83 changes: 10 additions & 73 deletions internal/app/kwild/cmd/utils/init.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package utils

import (
"fmt"
"os"
"path/filepath"

"github.com/kwilteam/kwil-db/internal/pkg/nodecfg"
"github.com/spf13/cobra"

cfg "github.com/cometbft/cometbft/config"
cmtrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/privval"
"github.com/cometbft/cometbft/types"
cmttime "github.com/cometbft/cometbft/types/time"
"os"
)

var initFlags = struct {
initialHeight int64
homeDir string
}{}
var initFlags nodecfg.NodeGenerateConfig

// InitFilesCmd initializes a fresh CometBFT instance.
func InitFilesCmd() *cobra.Command {
Expand All @@ -26,68 +15,16 @@ func InitFilesCmd() *cobra.Command {
Short: "Initializes files required for a kwil node",
RunE: initFiles,
}
initFilesCmd.Flags().StringVar(&initFlags.homeDir, "home", "", "comet home directory")
if initFlags.homeDir == "" {
initFlags.homeDir = os.Getenv("COMET_BFT_HOME")
initFilesCmd.Flags().StringVar(&initFlags.HomeDir, "home", "", "comet home directory")
// TODO: let viper handle this
if initFlags.HomeDir == "" {
initFlags.HomeDir = os.Getenv("COMET_BFT_HOME")
}
initFilesCmd.Flags().Int64Var(&initFlags.initialHeight, "initial-height", 0, "initial height of the first block")
initFilesCmd.Flags().Int64Var(&initFlags.InitialHeight, "initial-height", 0, "initial height of the first block")

return initFilesCmd
}
func initFiles(cmd *cobra.Command, args []string) error {
config := cfg.DefaultConfig()
config.SetRoot(initFlags.homeDir)
err := os.MkdirAll(filepath.Join(initFlags.homeDir, "config"), nodeDirPerm)
if err != nil {
_ = os.RemoveAll(initFlags.homeDir)
return err
}

err = os.MkdirAll(filepath.Join(initFlags.homeDir, "data"), nodeDirPerm)
if err != nil {
_ = os.RemoveAll(initFlags.homeDir)
return err
}
err = InitFilesWithConfig(config)
if err != nil {
return err
}
pvKeyFile := filepath.Join(initFlags.homeDir, config.BaseConfig.PrivValidatorKey)
pvStateFile := filepath.Join(initFlags.homeDir, config.BaseConfig.PrivValidatorState)
pv := privval.LoadFilePV(pvKeyFile, pvStateFile)

pubKey, err := pv.GetPubKey()
if err != nil {
return fmt.Errorf("failed to get public key: %w", err)
}

genVal := types.GenesisValidator{
Address: pubKey.Address(),
PubKey: pubKey,
Power: 1,
Name: "node-0",
}

chainIDPrefix := "kwil-chain-"

vals := []types.GenesisValidator{genVal}

genDoc := &types.GenesisDoc{
ChainID: chainIDPrefix + cmtrand.Str(6),
ConsensusParams: types.DefaultConsensusParams(),
GenesisTime: cmttime.Now(),
InitialHeight: initFlags.initialHeight,
Validators: vals,
}

if err := genDoc.SaveAs(filepath.Join(initFlags.homeDir, config.BaseConfig.Genesis)); err != nil {
_ = os.RemoveAll(initFlags.homeDir)
return err
}

config.P2P.AddrBookStrict = false
config.P2P.AllowDuplicateIP = true
config.RPC.ListenAddress = "tcp://0.0.0.0:26657"
cfg.WriteConfigFile(filepath.Join(initFlags.homeDir, "config", "config.toml"), config)
return nil
func initFiles(cmd *cobra.Command, args []string) error {
return nodecfg.GenerateNodeConfig(&initFlags)
}
Loading

0 comments on commit 3eb3ac2

Please sign in to comment.