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

CTFv2 PoC test #14865

Open
wants to merge 55 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
36031ed
init, wip
skudasov Oct 17, 2024
5420691
fix go mod
skudasov Oct 17, 2024
fc73619
fix go mod again
skudasov Oct 17, 2024
038b11e
update
skudasov Oct 17, 2024
b7a94b5
fix go mod
skudasov Oct 17, 2024
05b2233
ready to test
skudasov Oct 17, 2024
ab0baf3
update deps
skudasov Oct 17, 2024
0a13f5e
update
skudasov Oct 18, 2024
7d8ffb3
update README
skudasov Oct 18, 2024
dce9c56
fix
skudasov Oct 18, 2024
d6cc825
fix readme
skudasov Oct 18, 2024
9be9a8a
try mockserver in CI
skudasov Oct 21, 2024
dc8fe4d
try reach the localhost mock in CI
skudasov Oct 21, 2024
cc4e526
check it can work both locally and in CI without code modification
skudasov Oct 21, 2024
e0465e6
check again
skudasov Oct 21, 2024
c75d06e
use the same Go version
skudasov Oct 21, 2024
c143938
example of CL client connection
skudasov Oct 21, 2024
85d9973
connect all the clients
skudasov Oct 21, 2024
3111ad8
example with contracts
skudasov Oct 21, 2024
d1ca470
finalize
skudasov Oct 22, 2024
cf1ea62
readmes
skudasov Oct 22, 2024
95c9562
ignore caching, update
skudasov Oct 22, 2024
2674e22
change CI workflow name
skudasov Oct 22, 2024
8e8597a
re-trigger
skudasov Oct 22, 2024
8fd3436
fix readme
skudasov Oct 22, 2024
547f054
switch to v0.1.0
skudasov Oct 23, 2024
7639522
fix go mod
skudasov Oct 23, 2024
d2581b2
use strict config version
skudasov Oct 23, 2024
430f573
update go mod
skudasov Oct 23, 2024
2ddc36c
add Sepolia example
skudasov Oct 23, 2024
81c972f
simplify configuration
skudasov Oct 24, 2024
5a82459
copy capabilities into container
skudasov Oct 24, 2024
f28c64a
expose p2p ports, add Fuji example
skudasov Oct 24, 2024
87beabc
fund nodes
skudasov Oct 24, 2024
29d8b77
use shared PG nodeset
skudasov Oct 25, 2024
db528ae
static node names
skudasov Oct 25, 2024
cde6a27
capabilities perms
skudasov Oct 25, 2024
91aa2a4
capabilities perms again
skudasov Oct 25, 2024
f5a1a79
unified config for one or more node overrides
skudasov Oct 28, 2024
b1145e3
comment config
skudasov Oct 28, 2024
7503510
docker rebuild from config
skudasov Oct 29, 2024
3cd15e1
simplify, explicit rebuild using config, no flags
skudasov Oct 29, 2024
ee5b3e3
name tmp image if no name provided
skudasov Oct 29, 2024
b7f65bb
update
skudasov Oct 30, 2024
1c378ba
add Blockscout for anvil
skudasov Nov 1, 2024
53efba3
Merge branch 'develop' into ctf-v2-tests
skudasov Nov 1, 2024
9e274b9
update the framework
skudasov Nov 3, 2024
94d683d
update
skudasov Nov 6, 2024
a0dba25
demo chaos, reboot
skudasov Nov 6, 2024
9645790
auth
skudasov Nov 6, 2024
4abe9c5
bump CTF tag
skudasov Nov 6, 2024
90f4944
show fast config reload
skudasov Nov 7, 2024
1acf976
show fast config reload, take2
skudasov Nov 7, 2024
c4c4597
debug slow port allocation
skudasov Nov 7, 2024
4c48749
update ctf
skudasov Nov 7, 2024
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: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ credentials.env
gcr_creds.env

go.work
go.work.sum
go.work.sum

e2e/
47 changes: 47 additions & 0 deletions .github/workflows/e2e.yml
Copy link
Collaborator

@pavel-raykov pavel-raykov Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a bunch of *test* workflows. Is it clear how, for example, e2e.yml is different from integration-tests.yml?

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Run E2E tests (CTFv2)

on:
push:

jobs:
test:
runs-on: ubuntu-latest
env:
CTF_CONFIGS: smoke.toml
CTF_LOG_LEVEL: info
CTF_LOKI_STREAM: "false"
PRIVATE_KEY: ${{ secrets.CTF_SIMULATED_KEY_1 }}
permissions:
id-token: write
contents: read
steps:
- name: Check out code
uses: actions/checkout@v3

Check warning on line 19 in .github/workflows/e2e.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. Action is using node16 (node-version / warning)
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ secrets.PUBLIC_AWS_ECR_ROLE }}
aws-region: us-east-1
- name: Authenticate to ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
with:
registry-type: public
- name: Set up Go
uses: actions/setup-go@v4

Check warning on line 31 in .github/workflows/e2e.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. Action is using node16 (node-version / warning)
with:
go-version: 1.22.8
- name: Cache Go modules
uses: actions/cache@v3

Check warning on line 35 in .github/workflows/e2e.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. Action is using node16 (node-version / warning)
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: go-modules-${{ hashFiles('**/go.sum') }}-${{ runner.os }}
restore-keys: |
go-modules-${{ hashFiles('**/go.sum') }}-${{ runner.os }}
- name: Install dependencies
run: go mod download
- name: Run tests
working-directory: e2e/capabilities
run: go test -v -run TestDON
35 changes: 35 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

.envrc
promtail-config.yml

# CL node
**/.envrc

# Local observability stack
**/compose
**/compose/*
**/blockscout
**/blockscout/*
**/*cache.toml
9 changes: 9 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Chainlink End-to-end Tests
This directory hold `Chainlink` end-to-end tests using `Chainlink Testing Framework v2`

"End-to-end" refers to deploying all products using production images while managing the environment's composition. We test the assembled system as a **black box**, using TOML configuration inputs, URLs of deployed services, or contract addresses.

<!-- TOC -->
* [Example tests](./capabilities/smoke_test.go)
* [Framework docs](https://github.com/smartcontractkit/chainlink-testing-framework/tree/main/framework/README.md)
<!-- TOC -->
87 changes: 87 additions & 0 deletions e2e/capabilities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
## Examples
This directory shows some examples on how to assemble different `Chainlink` services, connect and test them

You can use [direnv](https://direnv.net/) or raw `.envrc` files to set up common vars
```
export CTF_LOG_LEVEL=info
export CTF_LOKI_STREAM=true
export LOKI_TENANT_ID=promtail
export LOKI_URL=http://host.docker.internal:3030/loki/api/v1/push
export TESTCONTAINERS_RYUK_DISABLED=true
export RESTY_DEBUG=false
```
You can read more in [docs](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/README.md)

### CLI
```
go get github.com/smartcontractkit/chainlink-testing-framework/framework/cmd && go install github.com/smartcontractkit/chainlink-testing-framework/framework/cmd && mv ~/go/bin/cmd ~/go/bin/ctf
```

### Local observability stack
```
ctf obs up
```

### Local Blockscout stack
```
ctf bs up
```
Reboot it when you re-run the environment (it can't always handle re-orgs or index the same block numbers if you reboot your network)
```
ctf bs r
```

### DON + Anvil example
Add env vars to your `.envrc` and run
```
export CTF_CONFIGS=smoke.toml
export PRIVATE_KEY="ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"

go test -v -run TestDON
```

### DON + Avalanche Fuji example
Add env vars to your `.envrc` and run
```
export CTF_CONFIGS=smoke.toml,smoke-fuji.toml
export PRIVATE_KEY="..."

go test -v -run TestDON
```

### Using local image and rebuilding it
You can quickly rebuild a local image:
```
[nodeset.node_specs.node]
docker_file = "../../core/chainlink.Dockerfile"
docker_ctx = "../.."
```
Image will be published as `localhost:5050/ctftmp:latest` and used by the framework.

If you don't have a local registry the framework will spin it up for you (`registry:2` docker container).

You can provide either `image` or `docker_file`, `docker_ctx` fields to switch between local build and an existing image.

### Overriding configs
You can override any configuration by providing more `TOML` files
```
export CTF_CONFIGS=smoke.toml,smoke-another-network.toml
```
Changes will be applied right to left

## Default CLNode credentials
UI login/password:
```
[email protected]
fj293fbBnlQ!f9vNs
```

### Caching
You can re-use already deployed environment and contracts like this
1. Run your test once
2. Change the configuration to cache
```
export CTF_CONFIGS=smoke-cache.toml
```
3. Develop your test on cached or external environment, you can override `.out` fields in cached config to connect to any other environment, staging ,etc
4. You can control caching of each component by changing `use_cache = true|false`
2,038 changes: 2,038 additions & 0 deletions e2e/capabilities/components/gethwrappers/burn_mint_erc677.go
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file (and other large files) copied from somewhere?

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions e2e/capabilities/components/onchain/deployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package onchain

import (
"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/chainlink-testing-framework/seth"
bmerc "github.com/smartcontractkit/chainlink/e2e/capabilities/components/gethwrappers"
"math/big"
"os"
"time"
)

type Input struct {
URL string `toml:"url"`
Out *Output `toml:"out"`
}

type Output struct {
UseCache bool `toml:"use_cache"`
Addresses []common.Address `toml:"addresses"`
}

func NewProductOnChainDeployment(in *Input) (*Output, error) {
if in.Out != nil && in.Out.UseCache {
return in.Out, nil
}

// deploy your contracts here, example

t := seth.Duration{D: 2 * time.Minute}

c, err := seth.NewClientBuilder().
WithRpcUrl(in.URL).
WithProtections(true, false, &t).
WithGasPriceEstimations(true, 0, seth.Priority_Fast).
WithTracing(seth.TracingLevel_All, []string{seth.TraceOutput_Console}).
WithPrivateKeys([]string{os.Getenv("PRIVATE_KEY")}).
Build()
if err != nil {
return nil, err
}

contractABI, err := bmerc.BurnMintERC677MetaData.GetAbi()
if err != nil {
return nil, err
}

dd, err := c.DeployContract(c.NewTXOpts(),
"TestToken",
*contractABI,
common.FromHex(bmerc.BurnMintERC677MetaData.Bin),
"TestToken",
"TestToken",
uint8(18),
big.NewInt(1000),
)
if err != nil {
return nil, err
}

//addr, tx, _, err := bmerc.DeployBurnMintERC677(
// c.NewTXOpts(),
// c.Client,
// "TestToken",
// "TestToken",
// 18,
// big.NewInt(100),
//)
//_, err = bind.WaitMined(context.Background(), c.Client, tx)
//if err != nil {
// return nil, err
//}

out := &Output{
UseCache: true,
// save all the addresses to output, so it can be cached
Addresses: []common.Address{dd.Address},
}
in.Out = out
return out, nil
}
78 changes: 78 additions & 0 deletions e2e/capabilities/components/onchain/fund.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package onchain

import (
"context"
"crypto/ecdsa"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
"github.com/smartcontractkit/chainlink-testing-framework/seth"
"math/big"
)

func SendETH(client *ethclient.Client, privateKeyHex string, toAddress string, amount *big.Float) error {
privateKey, err := crypto.HexToECDSA(privateKeyHex)
if err != nil {
return fmt.Errorf("failed to parse private key: %v", err)
}
wei := new(big.Int)
amountWei := new(big.Float).Mul(amount, big.NewFloat(1e18))
amountWei.Int(wei)

publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return fmt.Errorf("error casting public key to ECDSA")
}
fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)

nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
if err != nil {
return fmt.Errorf("failed to fetch nonce: %v", err)
}

gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
return fmt.Errorf("failed to fetch gas price: %v", err)
}
gasLimit := uint64(21000) // Standard gas limit for ETH transfer

tx := types.NewTransaction(nonce, common.HexToAddress(toAddress), wei, gasLimit, gasPrice, nil)

chainID, err := client.NetworkID(context.Background())
if err != nil {
return fmt.Errorf("failed to fetch chain ID: %v", err)
}
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
if err != nil {
return fmt.Errorf("failed to sign transaction: %v", err)
}

err = client.SendTransaction(context.Background(), signedTx)
if err != nil {
return fmt.Errorf("failed to send transaction: %v", err)
}
framework.L.Info().Msgf("Transaction sent: %s", signedTx.Hash().Hex())
return nil
}

func FundNodes(sc *seth.Client, nodes []*clclient.ChainlinkClient, pkey string, ethAmount float64) error {
if ethAmount == 0 {
return errors.New("funds_eth is 0, set some value in config, ex.: funds_eth = 30.0")
}
for _, cl := range nodes {
ek, err := cl.ReadPrimaryETHKey()
if err != nil {
return err
}
if err := SendETH(sc.Client, pkey, ek.Attributes.Address, big.NewFloat(ethAmount)); err != nil {
return fmt.Errorf("failed to fund CL node %s: %w", ek.Attributes.Address, err)
}
}
return nil
}
12 changes: 12 additions & 0 deletions e2e/capabilities/smoke-fuji.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[blockchain_a]

[blockchain_a.out]
chain_id = "43113"
use_cache = true

[[blockchain_a.out.nodes]]
docker_internal_http_url = "https://ava-testnet.public.blastapi.io/ext/bc/C/rpc"
docker_internal_ws_url = "wss://avalanche-fuji-c-chain-rpc.publicnode.com"
http_url = "https://ava-testnet.public.blastapi.io/ext/bc/C/rpc"
ws_url = "wss://avalanche-fuji-c-chain-rpc.publicnode.com"
30 changes: 30 additions & 0 deletions e2e/capabilities/smoke.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
funds_eth = 30.0

[blockchain_a]
chain_id = "31337"
image = "f4hrenh9it/foundry:latest"
port = "8545"
type = "anvil"

[contracts]

[data_provider]
port = 9111

[nodeset]
nodes = 5
override_mode = "all"

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
# path to your binaries
# capabilities = ["./ctf", "./ctf2"]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
# docker_file = "../../core/chainlink.Dockerfile"
# docker_ctx = "../.."
pull_image = true
Loading
Loading