Skip to content

Commit

Permalink
Added readme and testnet support
Browse files Browse the repository at this point in the history
  • Loading branch information
smickovskid committed Feb 28, 2024
1 parent eefe189 commit 2fb4e96
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/integration-tests-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ jobs:
version="${{ env.CHAINLINK_VERSION }}"
[Network]
selected_networks=["SIMULATED"]
[Common]
internal_docker_repo = "${{ env.INTERNAL_DOCKER_REPO }}"
stateful_db = false
EOF
# shellcheck disable=SC2002
BASE64_CONFIG_OVERRIDE=$(cat config.toml | base64 -w 0)
Expand Down
46 changes: 18 additions & 28 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
# Local e2e testing
## Integration tests - HOWTO

Make sure to have `psql` installed locally. We use it to create a new database for each node.
### Prerequisites
1. `cd contracts && scarb --profile release build`
2. `yarn install`
3. `yarn build`

Create a new network for containers (only needs to be done once). A custom network allows containers to DNS resolve each other using container names.
#### TOML preparation
The integration tests are using TOML as the configuration input. The logic and parsing is located under [Test config](./testconfig)

```
docker network create chainlink
```
By default, the tests will be running with the default config set in [default.toml](./testconfig/default.toml). This configuration is set to run on devnet with local docker.

Build a custom core image with starknet relayer bumped to some commit.
Fields in the default toml can be overriden by creating an `overrides.toml`file. Any values specified here take precedence and will be overwritten if they overlap with `default.toml`.

```
cd ../core
go get github.com/smartcontractkit/chainlink-starknet/relayer@<MY COMMIT HERE>
docker build . -t smartcontract/chainlink:starknet -f ./core/chainlink.Dockerfile
```
##### Testnet runs
In order to run the tests on Testnet, additional variables need to be specified in the TOML, these would also be pointed out if `network = "testnet"` is set. The additional variables are:

Compile contracts and gauntlet:
- `l2_rpc_url` - L2 RPC url
- `account` - Account address on L2
- `private_key` - Private key for L2 account

```
yarn build
cd contracts
scarb --profile release build
```
##### Running in k8s

Run the tests!
Set `inside_k8 = true` under `[Common]`.

```
cd integration-tests
go test -count 1 -v -timeout 30m --run OCRBasic ./smoke
```
#### Run tests

Use `something.down.sh` scripts to teardown everything afterwards if the tests don't properly clean up.

# Old docs

For more information, see the [Chainlink Starknet Documentation | Integration Tests](../docs/integration-tests).
`cd integration-tests && go test --timeout=2h -v -count=1 -json ./smoke`
4 changes: 3 additions & 1 deletion integration-tests/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ func (c *Common) Default(t *testing.T, namespacePrefix string) (*Common, error)
"db": map[string]any{
"image": map[string]any{
"version": "15.5",
}},
},
"stateful": c.TestConfig.Common.Stateful,
},
}, c.TestConfig.ChainlinkImage, overrideFn)
c.Env = environment.New(c.TestEnvDetails.K8Config).
AddHelm(devnet.New(nil)).
Expand Down
7 changes: 4 additions & 3 deletions integration-tests/common/gauntlet_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

var (
ethAddressGoerli = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
nAccount string
ethAddressSepolia = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
strkAddressSepolia = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
nAccount string
)

func (m *OCRv2TestState) fundNodes() ([]string, error) {
Expand All @@ -36,7 +37,7 @@ func (m *OCRv2TestState) fundNodes() ([]string, error) {
for _, key := range nAccounts {
// We are not deploying in parallel here due to testnet limitations (429 too many requests)
l.Debug().Msg(fmt.Sprintf("Funding node with address: %s", key))
_, err = m.Clients.GauntletClient.TransferToken(ethAddressGoerli, key, "100000000000000000") // Transferring 1 ETH to each node
_, err = m.Clients.GauntletClient.TransferToken(strkAddressSepolia, key, "100000000000000000") // Transferring 1 ETH to each node
if err != nil {
return nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (m *OCRv2TestState) DeployCluster() {
}
// Setting RPC details
m.Common.RPCDetails.RPCL2External = m.Common.Env.URLs["starknet-dev"][0]
if *m.Common.TestConfig.Common.Network == "testnet" {
m.Common.RPCDetails.RPCL2External = *m.Common.TestConfig.Common.L2RPCUrl
m.Common.RPCDetails.RPCL2Internal = *m.Common.TestConfig.Common.L2RPCUrl
}
m.Common.RPCDetails.MockServerEndpoint = m.Common.Env.URLs["qa_mock_adapter_internal"][0]
m.Common.RPCDetails.MockServerUrl = "five"

Expand All @@ -152,6 +156,11 @@ func (m *OCRv2TestState) DeployCluster() {
m.Common.RPCDetails.RPCL2External = stark.ExternalHttpUrl
m.Common.RPCDetails.RPCL2Internal = stark.InternalHttpUrl

if *m.Common.TestConfig.Common.Network == "testnet" {
m.Common.RPCDetails.RPCL2External = *m.Common.TestConfig.Common.L2RPCUrl
m.Common.RPCDetails.RPCL2Internal = *m.Common.TestConfig.Common.L2RPCUrl
}

// Creating docker containers
b, err := test_env.NewCLTestEnvBuilder().
WithNonEVM().
Expand Down Expand Up @@ -205,6 +214,9 @@ func (m *OCRv2TestState) DeployCluster() {
account := accounts[0]
m.Account.Account = account.Address
m.Account.PrivateKey = account.PrivateKey
} else {
m.Account.Account = *m.TestConfig.TestConfig.Common.Account
m.Account.PrivateKey = *m.TestConfig.TestConfig.Common.PrivateKey
}
}

Expand Down
6 changes: 5 additions & 1 deletion integration-tests/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"maps"
"os"
"testing"
)

Expand Down Expand Up @@ -40,7 +41,10 @@ func TestOCRBasic(t *testing.T) {
if err != nil {
t.Fatal(err)
}

err = os.Setenv("CHAINLINK_ENV_USER", *config.Common.User)
require.NoError(t, err, "Could not set CHAINLINK_ENV_USER")
err = os.Setenv("INTERNAL_DOCKER_REPO", *config.Common.InternalDockerRepo)
require.NoError(t, err, "Could not set INTERNAL_DOCKER_REPO")
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
Expand Down
11 changes: 8 additions & 3 deletions integration-tests/testconfig/default.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# This is the default configuration so OCR2 tests can run without issues
[ChainlinkImage]
image="public.ecr.aws/chainlink/chainlink"
version="2.9.0"

[Logging]
test_log_collect=false
Expand All @@ -9,18 +12,20 @@ log_producer_timeout="10s"
log_producer_retry_limit=10

[Network]
selected_networks=["SIMULATED"] # Not needed for Starknet but mandatory from CTF
selected_networks=["SIMULATED"] # Not needed for Starknet but mandatory from CTF (do not change)

[Network.RpcHttpUrls]
simulated = ["http://127.0.0.1"] # Not needed for Starknet but mandatory from CTF
simulated = ["http://127.0.0.1"] # Not needed for Starknet but mandatory from CTF (do not change)

[Network.RpcWsUrls]
simulated = ["wss://127.0.0.1"] # Not needed for Starknet but mandatory from CTF
simulated = ["wss://127.0.0.1"] # Not needed for Starknet but mandatory from CTF (do not change)

[Common]
internal_docker_repo = "public.ecr.aws/chainlink"
inside_k8 = false
network = "localnet"
user = "satoshi"
stateful_db = false

[OCR2]
node_count = 6
Expand Down
28 changes: 24 additions & 4 deletions integration-tests/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ func (c *TestConfig) AsBase64() (string, error) {
}

type Common struct {
Network *string `toml:"network"`
InsideK8s *bool `toml:"inside_k8"`
User *string `toml:"user"`
L2RPCUrl *string `toml:"l2_rpc_url"`
Network *string `toml:"network"`
InsideK8s *bool `toml:"inside_k8"`
User *string `toml:"user"`
L2RPCUrl *string `toml:"l2_rpc_url"`
PrivateKey *string `toml:"private_key"`
Account *string `toml:"account"`
Stateful *bool `toml:"stateful_db"`
InternalDockerRepo *string `toml:"internal_docker_repo"`
}

func (c *Common) Validate() error {
Expand All @@ -133,14 +137,30 @@ func (c *Common) Validate() error {
return fmt.Errorf("inside_k8 must be set")
}

if c.InternalDockerRepo == nil {
return fmt.Errorf("internal_docker_repo must be set")
}

if c.User == nil {
return fmt.Errorf("user must be set")
}

if c.Stateful == nil {
return fmt.Errorf("stateful_db state for db must be set")
}

if c.L2RPCUrl == nil && *c.Network == "testnet" {
return fmt.Errorf("l2_rpc_url must be set")
}

if c.Account == nil && *c.Network == "testnet" {
return fmt.Errorf("account must be set")
}

if c.PrivateKey == nil && *c.Network == "testnet" {
return fmt.Errorf("private_key must be set")
}

return nil
}

Expand Down

0 comments on commit 2fb4e96

Please sign in to comment.