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

test: revive test module and working acceptance dev test #1171

Merged
merged 3 commits into from
Dec 19, 2024
Merged
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
4 changes: 0 additions & 4 deletions .github/workflows/ci-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ jobs:
run: go build -o /dev/null
working-directory: core/gatewayclient/example

- name: Pull math extension docker image
run: |
docker pull kwilbrennan/extensions-math:multi-arch --platform linux/amd64

- name: Build kwild image
id: docker_build_kwild
uses: docker/build-push-action@v5
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/kgw-test-reuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ jobs:
run: |
task build:cli

- name: Pull math extension docker image
run: |
docker pull kwilbrennan/extensions-math:multi-arch --platform linux/amd64

- name: Run kgw integration test
run: |
testUserID=$(id -u)
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tasks:

work:
cmds:
- cmd: go work init . ./core ./parse
- cmd: go work init . ./core ./parse ./test
ignore_error: true
generates:
- go.work
Expand Down
299 changes: 0 additions & 299 deletions _previous/test/go.mod

This file was deleted.

4 changes: 2 additions & 2 deletions app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

var defaultRoot = func() string {
home, _ := os.UserHomeDir()
return filepath.Join(home, ".kwil2")
return filepath.Join(home, ".kwild")
}()

func RootCmd() *cobra.Command {
Expand All @@ -36,7 +36,7 @@ func RootCmd() *cobra.Command {
DisableDefaultCmd: true,
},
Version: version.KwilVersion,
Example: custom.BinaryConfig.NodeCmd + " -r ~/.kwil2",
Example: custom.BinaryConfig.NodeCmd + " -r ~/.kwild",
// PersistentPreRunE so k has all the settings in all (sub)command's RunE funcs
PersistentPreRunE: bind.ChainPreRuns(bind.MaybeEnableCLIDebug, conf.PreRunBindConfigFile,
conf.PreRunBindFlags, conf.PreRunBindEnvMatching, conf.PreRunPrintEffectiveConfig),
Expand Down
105 changes: 69 additions & 36 deletions app/setup/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestnetCmd() *cobra.Command {
Use: "testnet",
Short: "Generate configuration for multiple nodes",
RunE: func(cmd *cobra.Command, args []string) error {
return generateNodeConfig(outDir, numVals, numNVals, noPex, startingPort)
return GenerateTestnetConfigs(outDir, numVals, numNVals, noPex, startingPort)
},
}

Expand All @@ -54,15 +54,15 @@ func TestnetCmd() *cobra.Command {
return cmd
}

func generateNodeConfig(rootDir string, numVals, numNVals int, noPex bool, startingPort uint64) error {
func GenerateTestnetConfigs(outDir string, numVals, numNVals int, noPex bool, startingPort uint64) error {
// ensure that the directory exists
// expand the directory path
rootDir, err := node.ExpandPath(rootDir)
outDir, err := node.ExpandPath(outDir)
if err != nil {
return err
}

if err := os.MkdirAll(rootDir, 0755); err != nil {
if err := os.MkdirAll(outDir, 0755); err != nil {
return err
}

Expand All @@ -80,8 +80,6 @@ func generateNodeConfig(rootDir string, numVals, numNVals int, noPex bool, start

// key 0 is leader
leaderPub := keys[0].Public()
// leaderPeerID, err := node.PeerIDFromPubKey(leaderPub)
leaderPubType := leaderPub.Type()

genConfig := &config.GenesisConfig{
ChainID: "kwil-testnet",
Expand All @@ -103,49 +101,84 @@ func generateNodeConfig(rootDir string, numVals, numNVals int, noPex bool, start

// generate the configuration for the nodes
for i := range numVals + numNVals {
nodeDir := filepath.Join(rootDir, fmt.Sprintf("node%d", i))
if err := os.MkdirAll(nodeDir, 0755); err != nil {
err = GenerateNodeRoot(&NodeGenConfig{
PortOffset: i,
IP: "127.0.0.1",
NoPEX: noPex,
RootDir: filepath.Join(outDir, fmt.Sprintf("node%d", i)),
NodeKey: keys[i],
Genesis: genConfig,
})
if err != nil {
return err
}
}

cfg := custom.DefaultConfig() // not config.DefaultConfig(), so custom command config is used
return nil
}

// P2P
cfg.P2P.Port = startingPort + uint64(i)
cfg.P2P.IP = "127.0.0.1"
cfg.P2P.Pex = !noPex
type NodeGenConfig struct {
RootDir string
PortOffset int
DBPort uint16 // leave zero for default plus any offset
IP string
NoPEX bool
NodeKey crypto.PrivateKey
Genesis *config.GenesisConfig

if i != 0 {
cfg.P2P.BootNodes = []string{node.FormatPeerString(
leaderPub.Bytes(), leaderPubType, cfg.P2P.IP, int(startingPort))}
}
// TODO: gasEnabled, private p2p, auth RPC, join expiry, allocs, etc.
}

// DB
cfg.DB.Port = strconv.Itoa(5432 + i)
func GenerateNodeRoot(ncfg *NodeGenConfig) error {
if err := os.MkdirAll(ncfg.RootDir, 0755); err != nil {
return err
}

// RPC
cfg.RPC.ListenAddress = net.JoinHostPort("0.0.0.0", strconv.FormatUint(uint64(8484+i), 10))
cfg := custom.DefaultConfig() // not config.DefaultConfig(), so custom command config is used

// Admin RPC
cfg.Admin.ListenAddress = net.JoinHostPort("127.0.0.1", strconv.FormatUint(uint64(8584+i), 10))
// P2P
cfg.P2P.Port = uint64(ncfg.PortOffset + 6600)
cfg.P2P.IP = "127.0.0.1"
if ncfg.IP != "" {
cfg.P2P.IP = ncfg.IP
}
cfg.P2P.Pex = !ncfg.NoPEX

if err := cfg.SaveAs(filepath.Join(nodeDir, config.ConfigFileName)); err != nil {
return err
}
leaderPub, err := crypto.UnmarshalPublicKey(ncfg.Genesis.Leader, crypto.KeyTypeSecp256k1)
if err != nil {
return err
}

// save the genesis configuration to the root directory
genFile := filepath.Join(nodeDir, config.GenesisFileName)
if err := genConfig.SaveAs(genFile); err != nil {
return err
}
if !ncfg.NodeKey.Public().Equals(leaderPub) {
// make everyone connect to leader
cfg.P2P.BootNodes = []string{node.FormatPeerString(
leaderPub.Bytes(), leaderPub.Type(), cfg.P2P.IP, 6600)}
}

err = key.SaveNodeKey(filepath.Join(nodeDir, "nodekey.json"), keys[i])
if err != nil {
return err
}
// DB
dbPort := ncfg.DBPort
if dbPort == 0 {
dbPort = uint16(5432 + ncfg.PortOffset)
}
cfg.DB.Port = strconv.FormatUint(uint64(dbPort), 10)

return nil
// RPC
cfg.RPC.ListenAddress = net.JoinHostPort("0.0.0.0", strconv.FormatUint(uint64(8484+ncfg.PortOffset), 10))

// Admin RPC
cfg.Admin.ListenAddress = net.JoinHostPort("127.0.0.1", strconv.FormatUint(uint64(8584+ncfg.PortOffset), 10))

if err := cfg.SaveAs(filepath.Join(ncfg.RootDir, config.ConfigFileName)); err != nil {
return err
}

// save the genesis configuration to the root directory
genFile := filepath.Join(ncfg.RootDir, config.GenesisFileName)
if err := ncfg.Genesis.SaveAs(genFile); err != nil {
return err
}

return key.SaveNodeKey(filepath.Join(ncfg.RootDir, "nodekey.json"), ncfg.NodeKey)
}

type deterministicPRNG struct {
Expand Down
2 changes: 2 additions & 0 deletions app/shared/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func BindRootDirVar(cmd *cobra.Command, rootDir *string, defaultVal, desc string
// BindRootDir is like [BindRootDirVar] but the bound variable is internal and
// returned as a *string, which may be ignored when using [RootDir].
func BindRootDir(cmd *cobra.Command, defaultVal, desc string) *string {
// cmd.PersistentFlags().String("root-dir", defaultVal, desc) // legacy
// cmd.PersistentFlags().MarkHidden("root-dir")
return cmd.PersistentFlags().StringP(RootFlagName, rootShortName, defaultVal, desc)
}

Expand Down
4 changes: 2 additions & 2 deletions app/shared/display/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ MsgFormatter = (*TxHashAndExecResponse)(nil)
var _ MsgFormatter = (*RespTxQuery)(nil)

type TxHashResponse struct {
TxHash string `json:"tx_hash"`
TxHash types.Hash `json:"tx_hash"`
}

// RespTxHash is used to represent a transaction hash in cli
Expand All @@ -65,7 +65,7 @@ func (h RespTxHash) Hex() string {
}

func (h RespTxHash) MarshalJSON() ([]byte, error) {
return json.Marshal(TxHashResponse{TxHash: h.Hex()})
return json.Marshal(TxHashResponse{TxHash: types.Hash(h)})
}

func (h RespTxHash) MarshalText() ([]byte, error) {
Expand Down
9 changes: 4 additions & 5 deletions contrib/docker/compose/kwil/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ volumes:
services:
pg:
container_name: postgres-kwild-single
image: kwildb/postgres:16.4-1
image: kwildb/postgres:16.5-1
ports:
- "15432:5432"
restart: always
Expand Down Expand Up @@ -38,8 +38,7 @@ services:
dockerfile: ./build/package/docker/kwild.dockerfile
ports:
- "8484:8484"
- "26656:26656"
- "26657:26657"
- "6600:6600"
environment:
- LOG=${LOG:-cometbft.log}
- KWILD_HOME=/app/.kwild
Expand All @@ -53,8 +52,8 @@ services:
ipv4_address: 172.5.100.2
command: |
--autogen
--root-dir=/app/.kwild
--log.level=debug
--root=/app/.kwild
--log-level=debug
--app.admin-listen-addr=/tmp/admin.socket
--chain.p2p.external-address=tcp://0.0.0.0:26656
--chain.rpc.listen-addr=tcp://0.0.0.0:26657
Expand Down
2 changes: 1 addition & 1 deletion contrib/docker/compose/postgres/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
pg:
container_name: postgres
image: kwildb/postgres:16.4-1
image: kwildb/postgres:16.5-1
ports:
- "5432:5432"
restart: always
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ services:
image: kwild:latest
ports:
- "8484:8484"
- "26656:26656"
- "26657:26657"
- "6600:6600"
- "40000:40000" # debugger, if build with debug dockerfile
#env_file:
# NOTE: docker compose by default will use `.env` file if presented
Expand All @@ -20,33 +19,29 @@ services:
target: /app/kwil
- /tmp:/var/run/kwil:rw
depends_on:
ext:
condition: service_started
pg:
condition: service_healthy
networks:
- kwil-act-testnet
command: |
--root-dir=/app/kwil
--log.level=${LOG_LEVEL:-info}
--log.format=plain
--log.time-format=rfc3339milli
--app.extension-endpoints=ext:50051
--app.admin-listen-addr=/tmp/admin.socket
--chain.p2p.external-address=tcp://0.0.0.0:26656
--chain.rpc.listen-addr=tcp://0.0.0.0:26657
--app.pg-db-host=pg
--app.pg-db-port=5432
--app.pg-db-user=kwild
--app.pg-db-pass=kwild
--root=/app/kwil
--log-level=${LOG_LEVEL:-info}
--log-format=plain
--admin.listen=/tmp/admin.socket
--p2p.ip=0.0.0.0
--p2p.port=6600
--db.host=pg
--db.port=5432
--db.user=kwild
--db.pass=kwild
healthcheck:
test: ["CMD", "curl", "--fail-with-body", "-s", "http://127.0.0.1:8484/api/v1/health/user"]
interval: 2s
timeout: 6s
retries: 10

pg:
image: kwildb/postgres:16.4-1
image: kwildb/postgres:16.5-1
ports:
- "5454:5432"
restart: always
Expand All @@ -62,12 +57,5 @@ services:
timeout: 6s
retries: 20

ext:
image: kwilbrennan/extensions-math:multi-arch
ports:
- "50051"
networks:
- kwil-act-testnet

networks:
kwil-act-testnet:
Loading
Loading