### Start ChaosMesh Playground Environment Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/chaos/debug-k8s.md Installs DevBox and starts the ChaosMesh playground environment. This is the initial setup step. ```bash cd infra/chaosmesh-playground devbox run up ``` -------------------------------- ### Install and Run DevBox Environment Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/infra/chaosmesh-playground/README.md Installs DevBox and starts the local Kubernetes and ChaosMesh environment. ```bash devbox run up ``` -------------------------------- ### Install with Values File Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/charts/geth-reorg/README.md Install the Ethereum chart using a custom values.yaml file. ```bash helm install kubernetes-ethereum-chart --name ethereum -f values.yaml ``` -------------------------------- ### Install MockServer using Helm Chart URL Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/charts/mockserver/README.md Installs MockServer into the 'mockserver' namespace using the official Helm chart from a URL. This is the recommended method for a quick setup. ```bash helm upgrade --install --namespace mockserver mockserver http://www.mock-server.com/mockserver-5.11.1.tgz ``` -------------------------------- ### Install Ethereum Chart Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/charts/geth-reorg/README.md Clone the repository and install the Ethereum chart using Helm. ```bash git clone git@github.com:jpoon/kubernetes-ethereum-chart.git helm install --name ethereum kubernetes-ethereum-chart ``` -------------------------------- ### Install gotestloghelper CLI Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/gotestloghelper/README.md Install the gotestloghelper CLI tool using the Go command-line interface. Ensure Go is installed on your system. ```sh go install github.com/smartcontractkit/chainlink-testing-framework/tools/gotestloghelper@latest ``` -------------------------------- ### Enter Nix Shell Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib.md Starts a Nix shell, providing a reliable and consistent development environment. This is an alternative to manually installing dependencies. ```shell make nix_shell ``` -------------------------------- ### Setup, Test, and Teardown for Layout API Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/fork_storage.md Execute the setup script, run the layout API tests, and then run the teardown script for the evm_storage framework. ```bash cd framework/evm_storage ./setup.sh go test -v -run TestLayoutAPI ./teardown.sh ``` -------------------------------- ### Download and Install Capability Binary Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/nodeset_capabilities.md Download and install the 'kvstore' capability binary. Ensure GOPRIVATE is set correctly for private repositories. ```bash export GOPRIVATE=github.com/smartcontractkit/capabilities go get github.com/smartcontractkit/capabilities/kvstore && go install github.com/smartcontractkit/capabilities/kvstore ``` -------------------------------- ### Installing Go Task Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/mocking.md Install the Go Task utility, which is helpful for managing build and run commands for fake services. ```bash brew install go-task ``` -------------------------------- ### Setup Wasp Environment with Nix Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/wasp.md Installs Wasp dependencies using Nix. Ensure Nix is installed before running this command. ```bash nix develop ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/monorepo-tools.md Installs pre-commit hooks using the Just command. ```bash just install ``` -------------------------------- ### Install MDBook and Plugins Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/README.md Installs the mdbook tool and several useful plugins for enhancing documentation. Ensure you have Rust and Cargo installed. ```bash cargo install mdbook && \ cargo install mdbook-alerts && \ cargo install mdbook-cmdrun && cargo install mdbook-mermaid ``` -------------------------------- ### Start Postgres DB Instance Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/docker/chainlink_ecosystem.md Starts a new Postgres DB instance required by the Job Distributor. Configure the network, database name, and image version. ```go pg, err := test_env.NewPostgresDb( []string{network.Name}, test_env.WithPostgresDbName("jd-db"), test_env.WithPostgresImageVersion("14.1")) if err != nil { panic(err) } err = pg.StartContainer() if err != nil { panic(err) } ``` -------------------------------- ### TOML Configuration Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/test_configuration_overrides.md Example of a TOML file for custom configuration, demonstrating how to set values for custom fields and use validation constraints. ```toml # My custom config does X [MyCustomConfig] # Can be a number a = 1 # Can be Y or Z b = "Z" ``` -------------------------------- ### Example Usage of Release Checker Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/ghlatestreleasechecker/README.md An example demonstrating how to call the script with a specific repository and a 30-day threshold. This helps verify if the latest release is recent. ```bash go run main.go 'owner/repo' 30 ``` -------------------------------- ### Install and Run Just Commands Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/pods/README.md Install pre-commit hooks and run available actions like linting and testing using the 'just' command runner. ```bash just install just ``` -------------------------------- ### Start a Basic Ethereum Network Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/docker/blockchain_nodes.md Use this snippet to quickly start a default Ethereum 1.0 network by specifying only the execution layer client. If no version is specified, Ethereum 1.0 (pre-Merge) will be used. ```go builder := NewEthereumNetworkBuilder() cfg, err := builder. WithExecutionLayer(types.ExecutionLayer_Nethermind). Build() if err != nil { panic(err) } net, rpcs, err := cfg.Start() if err != nil { panic(err) } ``` -------------------------------- ### Install Forge Standard Library Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/evm_storage/forge/lib/forge-std/README.md Use the forge install command to add the forge-std library to your project. ```bash forge install foundry-rs/forge-std ``` -------------------------------- ### Start Local Geth Network Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/seth.md Start a local Geth network for running tests. This command synchronizes the network. ```sh make GethSync ``` -------------------------------- ### Start Full Observability Stack Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/observability/observability_stack.md Starts the full observability stack, which includes additional services like Cadvisor, Tempo, Pyroscope, and PostgreSQL exporters. ```bash ctf obs up -f ``` -------------------------------- ### Install Dependencies Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib.md Installs necessary dependencies for the framework, including Node.js, Helm, and Yarn. This command should be run before setting up the development environment. ```shell make install_deps ``` -------------------------------- ### Start Job Distributor Instance Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/docker/chainlink_ecosystem.md Starts a new instance of the Job Distributor. Requires specifying the image, version, and the internal URL of the Postgres DB. ```go jd := New([]string{network.Name}, //replace with actual image WithImage("localhost:5001/jd"), WithVersion("latest"), WithDBURL(pg.InternalURL.String()), ) err = jd.StartContainer() if err != nil { panic(err) } ``` -------------------------------- ### Run Standalone Example Environment Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib.md Runs a standalone example environment for the k8s package. This is useful for testing and development purposes. ```shell go run k8s/examples/simple/env.go ``` -------------------------------- ### Aptos Smoke Test Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/blockchains/aptos.md A Go example demonstrating a smoke test for the Aptos blockchain. It loads configuration, initializes the network, executes a container command, and makes an API request. ```golang package examples import ( "github.com/go-resty/resty/v2" "github.com/smartcontractkit/chainlink-testing-framework/framework" "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" "github.com/stretchr/testify/require" testing "testing" ) type CfgAptos struct { BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` } func TestAptosSmoke(t *testing.T) { in, err := framework.Load[CfgAptos](t) require.NoError(t, err) bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) require.NoError(t, err) // execute any additional commands, to deploy contracts or set up // network is already funded, here are the keys _ = blockchain.DefaultAptosAccount _ = blockchain.DefaultAptosPrivateKey _, err = framework.ExecContainer(bc.ContainerName, []string{"ls", "-lah"}) require.NoError(t, err) t.Run("test something", func(t *testing.T) { // use internal URL to connect Chainlink nodes _ = bc.Nodes[0].InternalHTTPUrl // use host URL to interact _ = bc.Nodes[0].ExternalHTTPUrl r := resty.New().SetBaseURL(bc.Nodes[0].ExternalHTTPUrl).EnableTrace() _, err := r.R().Get("/v1/transactions") require.NoError(t, err) }) } ``` -------------------------------- ### Loki Basic Auth Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Loki Basic Authentication token environment variable. ```bash E2E_TEST_LOKI_BASIC_AUTH=token ``` -------------------------------- ### Wallet Key Secret Example (Single and Multiple) Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Examples for setting wallet keys for a network. Supports single keys or multiple keys using indexed environment variables. ```bash E2E_TEST_ARBITRUM_SEPOLIA_WALLET_KEY=wallet_key ``` ```bash E2E_TEST_ARBITRUM_SEPOLIA_WALLET_KEY_1=wallet_key_1, E2E_TEST_ARBITRUM_SEPOLIA_WALLET_KEY_2=wallet_key_2 ``` -------------------------------- ### Start Local Blockscout Instance Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/observability/blockscout.md Deploys a local Blockscout instance using the chainlink-testing-framework CLI. Access it at http://localhost. ```bash ctf bs up ``` -------------------------------- ### Simplified Seth Configuration Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/seth.md Use DefaultConfig for a quick setup with reasonable defaults. This is useful when you don't need to customize every parameter. ```golang cfg := seth.DefaultConfig("ws://localhost:8546", []string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}) client, err := seth.NewClientWithConfig(cfg) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Install MockServer using Local Helm Chart Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/charts/mockserver/README.md Installs MockServer into the 'mockserver' namespace using a locally cloned Helm chart repository. Use this if you have the chart source code available. ```bash helm upgrade --install --namespace mockserver mockserver helm/mockserver ``` -------------------------------- ### Start a Private Test Network Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib.md Use this command to start a simulated private Ethereum network with default Geth and Prysm clients. The network configuration will be saved to a JSON file. ```shell go run docker/test_env/cmd/main.go start-test-env private-chain ``` -------------------------------- ### Start an Ethereum 2.0 (PoS) Network Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/docker/blockchain_nodes.md Configure and start an Ethereum 2.0 network by explicitly setting the Ethereum version to Eth2 and specifying the desired execution layer client. Note that booting Ethereum 2.0 networks can take longer due to additional containers. ```go builder := NewEthereumNetworkBuilder() cfg, err := builder. WithEthereumVersion(config_types.EthereumVersion_Eth2). WithExecutionLayer(config_types.ExecutionLayer_Geth). Build() if err != nil { panic(err) } net, rpcs, err := cfg.Start() if err != nil { panic(err) } ``` -------------------------------- ### Start Observability Stack Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/observability-victoria/observability_stack_victoria.md Starts the local observability stack including VictoriaMetrics. Use this command to deploy the stack for local testing. ```bash ctf obs up -vm ``` -------------------------------- ### Test List Generator Example Command Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/testlistgenerator/README.md An example of how to run the test list generator script with specific parameters for an OCR product test. ```bash go run main.go -t "emv-test" -o "test_list.json" -p "ocr" -r "TestOCR.*" -f "./smoke/ocr_test.go" -e "besu" -d "hyperledger/besu:21.0.0,hyperledger/besu:22.0.0" -n "ubuntu-latest" ``` -------------------------------- ### Example Usage of Workflow Result Parser Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/workflowresultparser/README.md An example command demonstrating how to run the script with specific values for token, repository, workflow run ID, job name regex, and an output file. ```bash go run main.go --githubToken ghp_exampleToken --githubRepo owner/repo --workflowRunID 123456789 --jobNameRegex "Test-.*" --outputFile results.json ``` -------------------------------- ### Install Geth Non-Root Helm Chart Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/charts/geth-non-root/Readme.md Use this command to install the Geth Helm chart, enabling ingress and configuring network policies. Ensure all environment variables are set before execution. ```bash export RELEASE_NAME="your-release-name" export NAMESPACE="your-namespace" export INGRESS_BASE_DOMAIN="your-ingress-base-domain" export INGRESS_CERT_ARN="your-ingress-certificate" export INGRESS_CIDRS="allowed-cidrs" helm install "${RELEASE_NAME}" . -f ./values.yaml \ --set ingress.annotation_certificate_arn="${INGRESS_CERT_ARN}" \ --set "ingress.hosts[0].host"="${NAMESPACE}-geth-http.${INGRESS_BASE_DOMAIN}" \ --set "ingress.hosts[1].host"="${NAMESPACE}-geth-ws.${INGRESS_BASE_DOMAIN}" \ --set "ingress.annotation_group_name"="${NAMESPACE}" \ --set "ingress.enabled"=true \ --set "networkPolicyDefault.ingress.allowCustomCidrs"=true \ --set "networkPolicyDefault.ingress.customCidrs"="${INGRESS_CIDRS}" # to override default chain id uncomment the following line # --set "geth.networkId"="2337" ``` -------------------------------- ### Implement Setup Method for WSVirtualUser Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/wasp/stateful_test.md Establishes a WebSocket connection to the target server. Handles connection errors and logs them. Closes the connection on error. ```go func (m *WSVirtualUser) Setup(l *wasp.Generator) error { var err error m.conn, _, err = websocket.Dial(context.Background(), m.target, &websocket.DialOptions{}) if err != nil { l.Log.Error().Err(err).Msg("failed to connect from vu") _ = m.conn.Close(websocket.StatusInternalError, "") return err } return nil } ``` -------------------------------- ### Solana Smoke Test Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/blockchains/solana.md Go code demonstrating how to initialize a Solana blockchain network and interact with a node to fetch the latest slot. ```golang package examples import ( "context" "fmt" "github.com/blocto/solana-go-sdk/client" "github.com/smartcontractkit/chainlink-testing-framework/framework" "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" "github.com/stretchr/testify/require" testing ) type CfgSolana struct { BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` } func TestSolanaSmoke(t *testing.T) { in, err := framework.Load[CfgSolana](t) require.NoError(t, err) bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) require.NoError(t, err) t.Run("test something", func(t *testing.T) { // use internal URL to connect chainlink nodes _ = bc.Nodes[0].InternalHTTPUrl // use host URL to deploy contracts c := client.NewClient(bc.Nodes[0].ExternalHTTPUrl) latestSlot, err := c.GetSlotWithConfig(context.Background(), client.GetSlotConfig{Commitment: "processed"}) require.NoError(t, err) fmt.Printf("Latest slot: %v\n", latestSlot) }) } ``` -------------------------------- ### Set Up Testing Environment with Coverage Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/k8s/TUTORIAL.md Example Go code to set up a testing environment using `chainlink-testing-framework`. It adds `goc` and `http_dummy` charts, runs the environment, saves coverage, and clears coverage for potential re-runs. ```go package main import ( "time" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" goc "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/cdk8s/goc" dummy "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/cdk8s/http_dummy" ) func main() { envConfig := &environment.Config{} addHardcodedLabelsToEnv(envConfig) e := environment.New(envConfig). AddChart(goc.New()). AddChart(dummy.New()) if err := e.Run(); err != nil { panic(err) } // run your test logic here time.Sleep(1 * time.Minute) if err := e.SaveCoverage(); err != nil { panic(err) } // clear the coverage, rerun the tests again if needed if err := e.ClearCoverage(); err != nil { panic(err) } } ``` -------------------------------- ### TRON Smoke Test Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/blockchains/tron.md A Go example demonstrating how to initialize and use the TRON blockchain client for basic smoke tests. It shows how to load configuration, create the client, and access node URLs. ```golang package examples import ( "github.com/smartcontractkit/chainlink-testing-framework/framework" "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" "github.com/stretchr/testify/require" testing "testing" ) type CfgTron struct { BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` } func TestTRONSmoke(t *testing.T) { in, err := framework.Load[CfgTron](t) require.NoError(t, err) bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) require.NoError(t, err) // all private keys are funded _ = blockchain.TRONAccounts.PrivateKeys[0] t.Run("test something", func(t *testing.T) { // use internal URL to connect Chainlink nodes _ = bc.Nodes[0].InternalHTTPUrl // use host URL to interact _ = bc.Nodes[0].ExternalHTTPUrl // use bc.Nodes[0].ExternalHTTPUrl + "/wallet" to access full node // use bc.Nodes[0].ExternalHTTPUrl + "/walletsolidity" to access Solidity node }) } ``` -------------------------------- ### Start Simulated Backend Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/seth.md Initializes a simulated Ethereum backend with pre-funded accounts and sets up a background goroutine to commit blocks at regular intervals. This is useful for rapid in-memory testing. ```go var startBackend := func(fundedAddresses []common.Address) (*simulated.Backend, context.CancelFunc) { toFund := make(map[common.Address]types.Account) for _, address := range fundedAddresses { toFund[address] = types.Account{ Balance: big.NewInt(1000000000000000000), // 1 Ether } } backend := simulated.NewBackend(toFund) ctx, cancelFn := context.WithCancel(context.Background()) // 100ms block time ticker := time.NewTicker(100 * time.Millisecond) go func() { for { select { case <-ticker.C: backend.Commit() case <-ctx.Done(): backend.Close() return } } }() return backend, cancelFn } // 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 is the default dev account backend, cancelFn := startBackend( []common.Address{common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")}, ) defer func() { cancelFn() }() client, err := builder. WithNetworkName("simulated"). WithEthClient(backend.Client()). WithPrivateKeys([]string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}). Build() require.NoError(t, err, "failed to build client") _ = client ``` -------------------------------- ### Get TRON Account via HTTP API Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/blockchains/tron.md Example of retrieving TRON account information using the TRON HTTP API. This requires a running TRON Solidity node accessible at the specified address. ```curl curl -X POST http://127.0.0.1:9090/walletsolidity/getaccount -d '{"address": "41E552F6487585C2B58BC2C9BB4492BC1F17132CD0"}' ``` -------------------------------- ### Import and Setup for stdStorage Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/evm_storage/forge/lib/forge-std/README.md Imports the necessary Test contract and sets up the stdStorage instance. This is boilerplate for using stdStorage in tests. ```solidity import "forge-std/Test.sol"; contract TestContract is Test { using stdStorage for StdStorage; Storage test; function setUp() public { test = new Storage(); } // ... other test functions } ``` -------------------------------- ### Update Container Stop, Remove, Create, Start Methods Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/docker-to-moby-migration-guide.md These container management methods now accept specific Options structs. ```go // After _, err = cli.ContainerStop(ctx, name, client.ContainerStopOptions{}) _, err = cli.ContainerRemove(ctx, name, client.ContainerRemoveOptions{RemoveVolumes: false}) createResp, err := cli.ContainerCreate(ctx, client.ContainerCreateOptions{ Config: inspected.Container.Config, HostConfig: inspected.Container.HostConfig, NetworkingConfig: networkingConfig, Name: name, }) _, err = cli.ContainerStart(ctx, createResp.ID, client.ContainerStartOptions{}) ``` -------------------------------- ### Install Chainlink Besu/Prysm Chart Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/charts/besu-prysm/README.md Command to install the chainlink-testing-framework Helm chart using the install script. It highlights the dynamic generation of `currentUnixTimestamp`. ```bash ./install.sh ``` -------------------------------- ### Building and Running Fake Services Locally Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/mocking.md Use Go Task to build your fake service and then run it locally for development. Replace placeholders with your product name and tag. ```bash task build -- ${product-name}-${tag} # ex. myproduct-1.0 task run ``` -------------------------------- ### Query Loki Logs with Go Client Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib.md Example demonstrating how to initialize and use the LokiClient in Go to query logs. Requires setting up authentication and defining query parameters. Ensure the Loki API URL and tenant ID are correctly configured. ```go auth := LokiBasicAuth{ Username: os.Getenv("LOKI_LOGIN"), Password: os.Getenv("LOKI_PASSWORD"), } queryParams := LokiQueryParams{ Query: `{namespace="test"} |= "test"`, StartTime: time.Now().AddDate(0, 0, -1), EndTime: time.Now(), Limit: 100, } lokiClient := NewLokiClient("https://loki.api.url", "my-tenant", auth, queryParams) logEntries, err := lokiClient.QueryLogs(context.Background()) ``` -------------------------------- ### Pyroscope Key Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Pyroscope API Key environment variable. ```bash E2E_TEST_PYROSCOPE_KEY=key ``` -------------------------------- ### Initialize MockServer Client Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/client/mockserver.md Demonstrates three ways to initialize the MockServer client: using an environment, a URL, or a custom configuration. Initialization with an environment is most common, but custom configurations allow for specific headers. ```go var myk8sEnv *environment.Environment // ... create k8s environment k8sMockserver := ConnectMockServer(myk8sEnv) mockServerUrl := "http://my.mockserver.instance.io" myMockServer := ConnectMockServerURL(mockServerUrl) customConfig := &MockserverConfig{ LocalURL: mockServerUrl, ClusterURL: mockServerUrl, Headers: map[string]string{"x-secret-auth-header": "such-a-necessary-auth-header"}, } myCustomMockServerClient := NewMockserverClient(customConfig) ``` -------------------------------- ### Loki Endpoint Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Loki endpoint URL environment variable. ```bash E2E_TEST_LOKI_ENDPOINT=url ``` -------------------------------- ### Chainlink Image Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Chainlink Docker image environment variable. ```bash E2E_TEST_CHAINLINK_IMAGE=qa_ecr_image_url ``` -------------------------------- ### Configure Environment with Labels Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/k8s/TUTORIAL.md Sets up the environment configuration with namespace, workload, and pod labels. Ensures that all required `chain.link/*` labels are present for validation. ```go envConfig := &environment.Config{ Labels: nsLabels, WorkloadLabels: workloadPodLabels, PodLabels: workloadPodLabels, NamespacePrefix: "new-environment", } ``` -------------------------------- ### Pyroscope Server URL Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Pyroscope Server URL environment variable. ```bash E2E_TEST_PYROSCOPE_SERVER_URL=url ``` -------------------------------- ### Grafana Bearer Token Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Grafana Bearer Token environment variable. ```bash E2E_TEST_GRAFANA_BEARER_TOKEN=token ``` -------------------------------- ### Loki Bearer Token Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Loki Bearer Token environment variable. ```bash E2E_TEST_LOKI_BEARER_TOKEN=token ``` -------------------------------- ### Loki Tenant ID Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Loki Tenant ID environment variable. ```bash E2E_TEST_LOKI_TENANT_ID=tenant_id ``` -------------------------------- ### Initialize Sentinel Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/sentinel.md Sets up a new Sentinel instance with a logger. Ensure to close the Sentinel instance when done using defer. ```go package main import ( "github.com/rs/zerolog" "os" "github.com/smartcontractkit/chainlink-testing-framework/sentinel" ) func main() { // Initialize logger logger := zerolog.New(os.Stdout).With().Timestamp().Logger() // Initialize Sentinel sentinelCoordinator := sentinel.NewSentinel(sentinel.SentinelConfig{ Logger: &logger, }) defer sentinelCoordinator.Close() } ``` -------------------------------- ### Initialize Local S3 from Configuration (Go) Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/storage/s3.md Load S3 configuration from a file and initialize the S3 provider using the framework's loading mechanism. Requires the 's3provider' and 'framework' packages. ```golang package my_test import ( "fmt" "os" "testing" "github.com/smartcontractkit/chainlink-testing-framework/framework/components/s3provider" "github.com/smartcontractkit/chainlink-testing-framework/framework" "github.com/stretchr/testify/require" ) type Config struct { S3Config *s3provider.Input `toml:"local_s3" validate:"required"` } func TestLocalS3(t *testing.T) { in, err := framework.Load[Config](t) require.NoError(t, err) output, err := NewMinioFactory().NewFrom(in) require.NoError(t, err) t.log(fmt.Printf("%#v", output)) } ``` -------------------------------- ### Chainlink Upgrade Image Secret Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example for setting the Chainlink upgrade Docker image environment variable. ```bash E2E_TEST_CHAINLINK_UPGRADE_IMAGE=qa_ecr_image_url ``` -------------------------------- ### Create and Run a Simple Kubernetes Environment Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/k8s/TUTORIAL.md Defines and deploys a basic Kubernetes environment using the Chainlink testing framework. It includes adding hardcoded labels and deploying Ethereum and Chainlink services via Helm. ```go package main import ( "fmt" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/chainlink" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/ethereum" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/mockserver" ) func addHardcodedLabelsToEnv(env *environment.Config) { env.Labels = []string{"chain.link/product=myProduct", "chain.link/team=my-team", "chain.link/cost-center=test-tooling-load-test"} env.WorkloadLabels = map[string]string{"chain.link/product": "myProduct", "chain.link/team": "my-team", "chain.link/cost-center": "test-tooling-load-test"} env.PodLabels = map[string]string{"chain.link/product": "myProduct", "chain.link/team": "my-team", "chain.link/cost-center": "test-tooling-load-test"} } func main() { env := &environment.Config{ NamespacePrefix: "new-environment", KeepConnection: false, RemoveOnInterrupt: false, } addHardcodedLabelsToEnv(env) err := environment.New(env). AddHelm(ethereum.New(nil)). AddHelm(chainlink.New(0, nil)). Run() if err != nil { panic(err) } } ``` -------------------------------- ### Initialize and Use Public Github Client Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/client/github.md Demonstrates how to initialize a Github client without a token to access public repositories and fetch the latest releases and tags. Handles potential errors during the API calls. ```go publicRepoClient := NewGithubClient(WITHOUT_TOKEN) // "smartcontractkit", "chainlink" latestCLReleases, err := publicRepoClient.ListLatestCLCoreReleases(10) if err != nil { panic(err) } // "smartcontractkit", "chainlink" latestCLTags, err := publicRepoClient.ListLatestCLCoreTags(10) if err != nil { panic(err) } ``` -------------------------------- ### Start Local Anvil Network Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/seth.md Start a local Anvil network for running tests. This command synchronizes the network. ```sh make AnvilSync ``` -------------------------------- ### Start Anvil Local Blockchain Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/evm_storage/README.md Starts a local Anvil blockchain instance. This is often a prerequisite for other EVM interactions. ```bash anvil & ``` -------------------------------- ### Start Default Observability Stack Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/observability/observability_stack.md Starts the default observability stack including Prometheus, Loki, OTEL-collector, and Grafana. ```bash ctf obs up ``` -------------------------------- ### Install ghsecrets Tool Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Install the `ghsecrets` tool using Go. Ensure `asdf reshim` is run if using `asdf`. ```bash go install github.com/smartcontractkit/chainlink-testing-framework/tools/ghsecrets@latest ``` -------------------------------- ### Parallel Load Generation Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/wasp/how-to/parallelise_load.md Demonstrates how to define and run multiple, independently scheduled load generators (RPS and VU) in parallel using goroutines and synchronization primitives. ```go func TestParallelLoad(t *testing.T) { labels := map[string]string{ "branch": "parallel_load", "commit": "parallel_load", } // Define RPS schedule rpsSchedule := wasp.Combine( // wasp.Steps(from, increase, steps, duration) wasp.Steps(1, 1, 9, 10*time.Second), // Start with 1 RPS, increment by 1 RPS in 9 steps over 10 seconds // wasp.Plain(count, duration) wasp.Plain(9, 50*time.Second), // Hold 9 RPS for 50 seconds ) // Define VU' schedule vuSchedule := wasp.Combine( // wasp.Steps(from, increase, steps, duration) wasp.Steps(2, 1, 8, 16*time.Second), // Start with 2 VUs, increment by 1 VU in 8 steps over 16 seconds // wasp.Plain(count, duration) wasp.Plain(10, 30*time.Second), // Hold 10 VUs for 30 seconds ) // Define VU'' schedule vu2Schedule := wasp.Combine( // wasp.Steps(from, increase, steps, duration) wasp.Steps(3, 1, 6, 14*time.Second), // Start with 3 VUs, increment by 1 VU in 6 steps over 14 seconds // wasp.Plain(count, duration) wasp.Plain(9, 20*time.Second), // Hold 9 VUs for 20 seconds ) // Create generators rpsGen, err := wasp.NewGenerator(&wasp.Config{ LoadType: wasp.RPS, Schedule: rpsSchedule, GenName: "Kappa", Labels: labels, Gun: NewExampleHTTPGun(srv.URL()), LokiConfig: wasp.NewEnvLokiConfig(), }) require.NoError(t, err) vuGen, err := wasp.NewGenerator(&wasp.Config{ LoadType: wasp.VU, Schedule: vuSchedule, GenName: "Lambda", Labels: labels, VU: NewExampleScenario(srv.URL()), LokiConfig: wasp.NewEnvLokiConfig(), }) require.NoError(t, err) vu2Gen, err := wasp.NewGenerator(&wasp.Config{ LoadType: wasp.VU, Schedule: vu2Schedule, GenName: "Mu", Labels: labels, VU: NewExampleScenario(srv.URL()), // Use the same VirtualUser implementation for simplicity LokiConfig: wasp.NewEnvLokiConfig(), }) require.NoError(t, err) wg := sync.WaitGroup{} // Run RPS load in a separate goroutine go func() { wg.Add(1) rpsGen.Run(true) wg.Done() }() // Wait for RPS load to stabilize time.Sleep(10 * time.Second) // Run VU' load in a separate goroutine go func() { wg.Add(1) vuGen.Run(true) wg.Done() }() // Wait for VU' load to stabilize time.Sleep(16 * time.Second) // Run VU'' load vu2Gen.Run(true) // Wait for all goroutines to complete wg.Wait() // Check for load generation errors require.Equal(t, 0, len(rpsGen.Errors()), "RPS generator errors") require.Equal(t, 0, len(vuGen.Errors()), "VU generator errors") require.Equal(t, 0, len(vu2Gen.Errors()), "VU'' generator errors") } ``` -------------------------------- ### Create New Loki Client Instance Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/client/loki.md Instantiate a new Loki client. Requires Loki URL, tenant ID, and query parameters. Basic authentication is optional. ```go lokiUrl := "http://loki-host.io" tenantId := "promtail" basicAuth := LokiBasicAuth{ Login: "admin", Password: "oh-so-secret", } queryParams := LokiQueryParams{ Query: "quantile_over_time(0.5, {name='my awesome app'} | json| unwrap duration [10s]) by name", StartTime: time.Now().Add(1 * time.Hour), EndTime: time.Now(), Limit: 1000, } lokiClient := client.NewLokiClient(lokiUrl, tenantId, basicAuth, queryParams) ``` ```go basicAuth := LokiBasicAuth{} ``` -------------------------------- ### Install GitHub CLI Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/ghsecrets/README.md Install the GitHub CLI, which is required for setting secrets in GitHub. Use brew for macOS or apt-get for Debian/Ubuntu. ```sh brew install gh ``` ```sh sudo apt-get install gh ``` -------------------------------- ### Creating a New Seth Client with Configuration Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/seth.md Initializes a new Seth client instance using a pre-configured Seth configuration object. This is the final step after loading and modifying the configuration, including adding private keys. ```golang seth, err := seth.NewClientWithConfig(cfg) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Sample TOML Config with Separate RPC/Wallet Keys Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example TOML configuration defining selected networks, EVM network details, RPC endpoints, and wallet keys separately. ```toml selected_networks = ["arbitrum_goerli", "optimism_goerli", "new_network"] [EVMNetworks.new_network] evm_name = "new_test_network" evm_chain_id = 100009 evm_simulated = true evm_chainlink_transaction_limit = 5000 evm_minimum_confirmations = 1 evm_gas_estimation_buffer = 10000 client_implementation = "Ethereum" evm_supports_eip1559 = true evm_default_gas_limit = 6000000 [ForkConfigs.new_network] url = "ws://localhost:8546" block_number = 100 [RpcHttpUrls] arbitrum_goerli = ["https://devnet-2.mt/ABC/rpc/"] new_network = ["http://localhost:8545"] [RpcWsUrls] arbitrum_goerli = ["wss://devnet-2.mt/ABC/ws/"] new_network = ["ws://localhost:8546"] [WalletKeys] arbitrum_goerli = ["1810868fc221b9f50b5b3e0186d8a5f343f892e51ce12a9e818f936ec0b651ed"] optimism_goerli = ["1810868fc221b9f50b5b3e0186d8a5f343f892e51ce12a9e818f936ec0b651ed"] new_network = ["ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"] ``` -------------------------------- ### Default Test Secrets File Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/config/config.md Example of a local '~/.testsecrets' dotenv file. Set only the secrets required for your specific tests. ```bash E2E_TEST_CHAINLINK_IMAGE=qa_ecr_image_url E2E_TEST_CHAINLINK_UPGRADE_IMAGE=qa_ecr_image_url E2E_TEST_ARBITRUM_SEPOLIA_WALLET_KEY=wallet_key ``` -------------------------------- ### Environment Setup with CDK8s and Helm Charts Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/k8s/TUTORIAL.md Configures and initializes a Kubernetes environment, adding a CDK8s deployment part along with Ethereum and Chainlink Helm charts. This snippet demonstrates how to instantiate and add various components to the testing environment. ```go package main import ( "time" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" "github.com/smartcontractkit/chainlink-testing-framework/k8s/examples/deployment_part_cdk8s" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/chainlink" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/ethereum" ) func main() { env := &environment.Config{ NamespacePrefix: "adding-new-deployment-part", TTL: 3 * time.Hour, KeepConnection: true, RemoveOnInterrupt: true, } addHardcodedLabelsToEnv(env) e := environment.New(env). AddChart(deployment_part_cdk8s.New(&deployment_part_cdk8s.Props{})). AddHelm(ethereum.New(nil)). AddHelm(chainlink.New(0, map[string]any{ "replicas": 2, })) if err := e.Run(); err != nil { panic(err) } e.Shutdown() } ``` -------------------------------- ### Running the Test with Configuration Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/first_test.md Command to execute the Go test, specifying the configuration file to be used. ```bash CTF_CONFIGS=smoke.toml go test -v -run TestMe ``` -------------------------------- ### Example Usage of ASCII Table Generator Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/asciitable/README.md An example command to run the script with specific JSON file, section, named key, and output file. ```bash go run main.go --jsonfile data.json --section "Some section" --namedKey "keyName" --outputFile results.txt ``` -------------------------------- ### Allow Direnv to Start Nix Shell Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib.md Allows direnv to automatically start the Nix shell when entering the project directory, simplifying environment management. ```shell direnv allow ``` -------------------------------- ### Create Base Environment Configuration Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/lib/k8s_new/environments.md Sets up the base configuration for a Kubernetes testing environment, including Time-To-Live (TTL) for the namespace, a namespace prefix for uniqueness, and settings to prevent pod eviction. ```go baseEnvironmentConfig := &environment.Config{ TTL: time.Hour * 2, NamespacePrefix: "my-namespace-prefix", Test: t, PreventPodEviction: true, Labels: nsLabels, WorkloadLabels: workloadPodLabels, PodLabels: workloadPodLabels, } ``` -------------------------------- ### ECR Image Fetcher Usage Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/ecrimagefetcher/README.md Demonstrates how to run the ECR Image Fetcher script with a repository name, grep string, count, and semantic version constraints. ```bash go run main.go [] ``` ```bash go run main.go 'my-repo' '^v[0-9]+\.[0-9]+\.[0-9]+$' 5 '>=1.0.0, <2.0.0' ``` -------------------------------- ### TOML Configuration Example Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/framework/components/configuration.md An example of how to define blockchain network configuration in a TOML file. This format is used to override or provide default values for the Input struct. ```toml [blockchain_a] chain_id = "1337" image = "ghcr.io/foundry-rs/foundry:stable" port = "8500" type = "anvil" docker_cmd_params = ["-b", "1"] ``` -------------------------------- ### Start Wasp Load Testing Environment Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/wasp.md Starts the necessary services for Wasp load testing, including Grafana and Loki. Ensure GRAFANA_TOKEN is set before running. ```bash make start ``` -------------------------------- ### Initialize Sentinel Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/libs/sentinel.md Creates a new Sentinel instance with the specified configuration. ```go NewSentinel(config SentinelConfig) *Sentinel ``` -------------------------------- ### Tagging and Pushing Go Modules Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/book/src/releasing_modules.md Demonstrates the commands to create and push version tags for Go modules. Use this when releasing new versions of your modules. ```bash git tag $pkg/$subpkg/v1.1.0 && git push --tags git tag $pkg/$subpkg/v1.1.1 && git push --tags git tag $pkg/$subpkg/v2.0.0 && git push --tags ``` -------------------------------- ### Test List Generator Example Command with Optional Flags Source: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/testlistgenerator/README.md Example command demonstrating the use of optional chain IDs and networks flags for generating test lists. ```bash go run main.go -t "emv-test" -o "test_list.json" -p "ocr" -r "TestOCR.*" -f "./smoke/ocr_test.go" -e "besu" -d "hyperledger/besu:21.0.0,hyperledger/besu:22.0.0" -n "ubuntu-latest" -c 1337,2337 -w "mainnet,ropsten" ```