Skip to content

Commit

Permalink
test: ganache => hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
jchappelow committed Jun 7, 2024
1 parent 61cc13c commit 942e909
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 50 deletions.
15 changes: 0 additions & 15 deletions deployments/compose/ganache/docker-compose.yml

This file was deleted.

8 changes: 8 additions & 0 deletions deployments/compose/hardhat/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3"

services:
hardhat:
container_name: hardhat
image: kwildb/hardhat:latest
ports:
- "8545:8545"
11 changes: 2 additions & 9 deletions test/integration/docker-compose.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,12 @@ services:
--schema-sync-interval 2
# domain should not be changed, and client should use 'domain' value as the provider, otherwise the test will fail

ganache:
image: trufflesuite/ganache:v7.9.2
hardhat:
image: kwildb/hardhat:latest
ports:
- "8545"
networks:
- {{ .Network }}
command:
- --wallet.hdPath
- m/44'/60'/0'
- --wallet.mnemonic
- test test test test test test test test test test test junk
- --chain.chainId
- "5"

networks:
{{ .Network }}:
Expand Down
16 changes: 13 additions & 3 deletions test/integration/eth-deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (d *Deployer) Deploy() error {
return err
}

auth.GasFeeCap = big.NewInt(1e12)
auth.GasTipCap = big.NewInt(1e6) // avoid SuggestGasTipCap
auth.GasLimit = 3_000_000

tokenAddr, _, tokenInst, err := contracts.DeployERC20(auth, d.ethClient)
if err != nil {
return err
Expand All @@ -71,6 +75,10 @@ func (d *Deployer) Deploy() error {
return err
}

auth.GasFeeCap = big.NewInt(1e12)
auth.GasTipCap = big.NewInt(1e6) // avoid SuggestGasTipCap
auth.GasLimit = 3_000_000

escrowAddr, _, escrowInst, err := contracts.DeployEscrow(auth, d.ethClient, tokenAddr)
if err != nil {
return err
Expand Down Expand Up @@ -174,9 +182,11 @@ func (d *Deployer) prepareTxAuth(ctx context.Context, sender *ecdsa.PrivateKey)
}

auth.Nonce = big.NewInt(int64(nonce))
auth.Value = big.NewInt(0) // in wei
auth.GasLimit = uint64(3000000) // in units
auth.GasPrice = gasPrice
auth.Value = big.NewInt(0) // in wei
// auth.GasPrice = gasPrice
auth.GasTipCap = big.NewInt(1e6) // avoid SuggestGasTipCap
auth.GasFeeCap = gasPrice // big.NewInt(1e16)
auth.GasLimit = 3_000_000
return auth, nil
}

Expand Down
29 changes: 13 additions & 16 deletions test/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var logWaitStrategies = map[string]string{
"node4": "finalized block",
"node5": "finalized block",
"kgw": "KGW Server started",
"ganache": "RPC Listening on 0.0.0.0:8545",
"hardhat": "Started HTTP and WebSocket JSON-RPC server",
"pg0": `listening on IPv4 address "0.0.0.0", port 5432`,
"pg1": `listening on IPv4 address "0.0.0.0", port 5432`,
"pg2": `listening on IPv4 address "0.0.0.0", port 5432`,
Expand All @@ -87,8 +87,7 @@ type IntTestConfig struct {
SchemaFile string
DockerComposeFile string
DockerComposeOverrideFile string
GanacheComposeFile string
WithGanache bool
WithETHDevNet bool
ExposedHTTPPorts bool

WaitTimeout time.Duration
Expand Down Expand Up @@ -244,9 +243,9 @@ func WithNumByzantineExpiryNodes(n int) HelperOpt {
}
}

func WithGanache() HelperOpt {
func WithETHDevNet() HelperOpt {
return func(r *IntHelper) {
r.cfg.WithGanache = true
r.cfg.WithETHDevNet = true
}
}

Expand Down Expand Up @@ -291,7 +290,6 @@ func (r *IntHelper) LoadConfig() {
AdminRPC: getEnv("KIT_ADMIN_RPC", "/tmp/admin.socket"),
DockerComposeFile: getEnv("KIT_DOCKER_COMPOSE_FILE", "./docker-compose.yml"),
DockerComposeOverrideFile: getEnv("KIT_DOCKER_COMPOSE_OVERRIDE_FILE", "./docker-compose.override.yml"),
GanacheComposeFile: getEnv("KIT_GANACHE_COMPOSE_FILE", "./ganache-docker-compose.yml"),
}

waitTimeout := getEnv("KIT_WAIT_TIMEOUT", "20s")
Expand Down Expand Up @@ -332,7 +330,6 @@ func (r *IntHelper) generateNodeConfig(homeDir string) {
RPCProvider: r.ethDeposit.UnexposedChainRPC,
ContractAddress: address,
// setting values here since we cannot have the defaults, since
// local ganache is a new network
StartingHeight: 0,
RequiredConfirmations: r.ethDeposit.confirmations, // TODO: remove this from the r.ethDeposit struct. it is not needed
ReconnectionInterval: 30,
Expand Down Expand Up @@ -398,14 +395,14 @@ func fileExists(path string) bool {
return !os.IsNotExist(err)
}

func (r *IntHelper) RunGanache(ctx context.Context) {
r.RunDockerComposeWithServices(ctx, []string{"ganache"})
func (r *IntHelper) RunETHDevNet(ctx context.Context) {
r.RunDockerComposeWithServices(ctx, []string{"hardhat"})
// Get the Escrow address and the ChainRPCURL
ctr, ok := r.containers["ganache"]
require.True(r.t, ok, "failed to get container for service ganache")
ctr, ok := r.containers["hardhat"]
require.True(r.t, ok, "failed to get container for hardhat service")

exposedChainRPC, unexposedChainRPC, err := utils.GanacheWSEndpoints(ctr, ctx)
require.NoError(r.t, err, "failed to get ganache endpoints")
exposedChainRPC, unexposedChainRPC, err := utils.ETHDevNetWSEndpoints(ctr, ctx)
require.NoError(r.t, err, "failed to get hardhat endpoints")

// Deploy contracts
ethDeployer, err := ethdeployer.NewDeployer(exposedChainRPC, r.cfg.CreatorRawPk, 5)
Expand Down Expand Up @@ -523,7 +520,7 @@ func (r *IntHelper) RunDockerComposeWithServices(ctx context.Context, services [
// Following steps are done:
// 1. Create a temporary directory for current test
// 2. Prepare files for docker-compose to run
// 3. Run Ganache ahead if required(for the purpose to populate config for eth-deposit)
// 3. Run ETHDevNet ahead if required(for the purpose to populate config for eth-deposit)
// 4. Generate node configuration files
// 5. Run docker-compose with the given services
func (r *IntHelper) Setup(ctx context.Context, services []string) {
Expand All @@ -543,10 +540,10 @@ func (r *IntHelper) Setup(ctx context.Context, services []string) {

r.prepareDockerCompose(ctx, tmpDir)

if r.cfg.WithGanache {
if r.cfg.WithETHDevNet {
// NOTE: it's more natural and easier if able to configure oracle
// through kwild cli flags
r.RunGanache(ctx)
r.RunETHDevNet(ctx)
}

r.generateNodeConfig(tmpDir)
Expand Down
10 changes: 5 additions & 5 deletions test/integration/kwild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestKwildEthDepositOracleIntegration(t *testing.T) {
integration.WithBlockInterval(time.Second),
integration.WithValidators(tc.numValidators),
integration.WithNonValidators(0),
integration.WithGanache(),
integration.WithETHDevNet(),
integration.WithGas(),
integration.WithEthDepositOracle(true),
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestKwildEthDepositOracleExpiryIntegration(t *testing.T) {
integration.WithValidators(5),
integration.WithNonValidators(0),
integration.WithGas(),
integration.WithGanache(),
integration.WithETHDevNet(),
integration.WithEthDepositOracle(true),
integration.WithNumByzantineExpiryNodes(1), // 1 node listens on a different escrow contract and submits votes for events on the byz contract which never gets approved
integration.WithVoteExpiry(4),
Expand Down Expand Up @@ -417,7 +417,7 @@ func TestKwildEthDepositOracleExpiryRefundIntegration(t *testing.T) {
integration.WithValidators(5),
integration.WithNonValidators(0),
integration.WithGas(),
integration.WithGanache(),
integration.WithETHDevNet(),
integration.WithEthDepositOracle(true),
integration.WithNumByzantineExpiryNodes(2), // 2 nodes listen on different escrow contracts and submits votes for events on the byz contract which never gets approved.
integration.WithVoteExpiry(4),
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestKwildEthDepositOracleValidatorUpdates(t *testing.T) {
integration.WithValidators(6),
integration.WithNonValidators(0),
integration.WithGas(),
integration.WithGanache(),
integration.WithETHDevNet(),
integration.WithEthDepositOracle(true),
integration.WithNumByzantineExpiryNodes(2), // 2 nodes listen on different escrow contracts and submits votes for events on the byz contract which never gets approved.
}
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestKwildEthDepositFundTransfer(t *testing.T) {
integration.WithValidators(4),
integration.WithNonValidators(0),
integration.WithGas(),
integration.WithGanache(),
integration.WithETHDevNet(),
integration.WithEthDepositOracle(true),
}

Expand Down
4 changes: 2 additions & 2 deletions test/utils/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func getEndpoints(ctr *testcontainers.DockerContainer, ctx context.Context,
return
}

func GanacheHTTPEndpoints(ctr *testcontainers.DockerContainer, ctx context.Context) (string, string, error) {
func ETHDevNetHTTPEndpoints(ctr *testcontainers.DockerContainer, ctx context.Context) (string, string, error) {
return getEndpoints(ctr, ctx, "8545", "http")
}

func GanacheWSEndpoints(ctr *testcontainers.DockerContainer, ctx context.Context) (string, string, error) {
func ETHDevNetWSEndpoints(ctr *testcontainers.DockerContainer, ctx context.Context) (string, string, error) {
return getEndpoints(ctr, ctx, "8545", "ws")
}

Expand Down

0 comments on commit 942e909

Please sign in to comment.