Skip to content

Commit

Permalink
test: allow config private rpc
Browse files Browse the repository at this point in the history
Add support to config private_rpc, so that following cmds work:

    KACT_PRIVATE_RPC=true task dev:up:nb
    KIT_PRIVATE_RPC=true task dev:testnet:up:nb

This helps to test KGW.
change AuthenticateRPCs to PrivateRPC
  • Loading branch information
Yaiba authored Sep 27, 2024
1 parent efe878f commit 297ef97
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ tasks:
desc: Start the dev environment(with testnet) without rebuilding docker image
dir: test # different module
cmds:
- go test ./integration -run ^TestLocalDevSetup$ -timeout 12h -dev -v
- go test ./integration -run ^TestLocalDevSetup$ -timeout 12h -dev -v {{.CLI_ARGS}}

# ************ test ************
# test with build:docker task support passing CLI_ARGS to go test, e.g. task test:act -- -debug
Expand Down
3 changes: 3 additions & 0 deletions cmd/kwil-admin/nodecfg/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type TestnetGenerateConfig struct {
SnapshotHeights uint64
Forks map[string]*uint64
PrivateMode bool
PrivateRPC bool
}

// ConfigOpts is a struct to alter the generation of the node config.
Expand Down Expand Up @@ -389,6 +390,8 @@ func GenerateTestnetConfig(genCfg *TestnetGenerateConfig, opts *ConfigOpts) erro
}
}

cfg.AppConfig.PrivateRPC = genCfg.PrivateRPC

err = WriteConfigFile(kwildcfg.ConfigFilePath(nodeDir), cfg)
if err != nil {
return fmt.Errorf("failed to write config file: %w", err)
Expand Down
9 changes: 6 additions & 3 deletions test/acceptance/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type ActTestCfg struct {
CreatorSigner auth.Signer
VisitorSigner auth.Signer

GasEnabled bool
AuthenticateRPCs bool
GasEnabled bool
PrivateRPC bool
}

func (e *ActTestCfg) CreatorIdent() []byte {
Expand Down Expand Up @@ -134,6 +134,9 @@ func (r *ActHelper) LoadConfig() *ActTestCfg {
DockerComposeOverrideFile: getEnv("KACT_DOCKER_COMPOSE_OVERRIDE_FILE", "./docker-compose.override.yml"),
}

cfg.PrivateRPC, err = strconv.ParseBool(getEnv("KACT_PRIVATE_RPC", "false"))
require.NoError(r.t, err, "invalid privateRPC bool")

cfg.GasEnabled, err = strconv.ParseBool(getEnv("KACT_GAS_ENABLED", "false"))
require.NoError(r.t, err, "invalid gasEnabled bool")

Expand Down Expand Up @@ -189,7 +192,7 @@ func (r *ActHelper) generateNodeConfig() {
OutputDir: tmpPath,
JoinExpiry: 14400,
WithoutGasCosts: !r.cfg.GasEnabled,
AuthenticateRPCs: r.cfg.AuthenticateRPCs,
AuthenticateRPCs: r.cfg.PrivateRPC,
Allocs: map[string]*big.Int{
creatorIdent: bal,
},
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/kwild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestTypes(t *testing.T) {
}
}

func TestPrivateMode(t *testing.T) {
func TestDataPrivateMode(t *testing.T) {
if testing.Short() {
t.Skip()
}
Expand All @@ -270,7 +270,7 @@ func TestPrivateMode(t *testing.T) {
// setup for each driver
helper := acceptance.NewActHelper(t)
cfg := helper.LoadConfig()
cfg.AuthenticateRPCs = true
cfg.PrivateRPC = true
if !*remote {
helper.Setup(ctx)
}
Expand Down
12 changes: 11 additions & 1 deletion test/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type IntTestConfig struct {
WithGas bool
PopulatePersistentPeers bool
PrivateMode bool
PrivateRPC bool

// The following options are mutually exclusive, as they are used to use
// alternate docker images with kwild variants with differnet extensions.
Expand Down Expand Up @@ -322,6 +323,12 @@ func WithPrivateMode() HelperOpt {
}
}

func WithPrivateRPC() HelperOpt {
return func(r *IntHelper) {
r.cfg.PrivateRPC = true
}
}

func WithWaitTimeout(timeout time.Duration) HelperOpt {
return func(r *IntHelper) {
r.cfg.WaitTimeout = timeout
Expand All @@ -346,6 +353,9 @@ func (r *IntHelper) LoadConfig() {
DockerComposeOverrideFile: getEnv("KIT_DOCKER_COMPOSE_OVERRIDE_FILE", "./docker-compose.override.yml"),
}

r.cfg.PrivateRPC, err = strconv.ParseBool(getEnv("KIT_PRIVATE_RPC", "false"))
require.NoError(r.t, err, "invalid privateRPC bool")

creatorPk, err := crypto.Secp256k1PrivateKeyFromHex(r.cfg.CreatorRawPk)
require.NoError(r.t, err, "invalid creator private key")

Expand All @@ -359,7 +369,6 @@ func (r *IntHelper) LoadConfig() {
r.cfg.VoteExpiry = 14400
r.cfg.JoinExpiry = 14400
r.cfg.PopulatePersistentPeers = true
r.cfg.PrivateMode = false
r.cfg.AdminRPC = "/tmp/admin.socket"
r.cfg.WaitTimeout = 30 * time.Second
}
Expand Down Expand Up @@ -449,6 +458,7 @@ func (r *IntHelper) generateNodeConfig(homeDir string) {
HostnamePrefix: "kwil-",
HostnameSuffix: "",
PrivateMode: r.cfg.PrivateMode,
PrivateRPC: r.cfg.PrivateRPC,

// use this to ease the process running test parallel
// NOTE: need to match docker-compose kwild service name
Expand Down

0 comments on commit 297ef97

Please # to comment.