-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
skudasov
wants to merge
55
commits into
develop
Choose a base branch
from
ctf-v2-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
CTFv2 PoC test #14865
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
36031ed
init, wip
skudasov 5420691
fix go mod
skudasov fc73619
fix go mod again
skudasov 038b11e
update
skudasov b7a94b5
fix go mod
skudasov 05b2233
ready to test
skudasov ab0baf3
update deps
skudasov 0a13f5e
update
skudasov 7d8ffb3
update README
skudasov dce9c56
fix
skudasov d6cc825
fix readme
skudasov 9be9a8a
try mockserver in CI
skudasov dc8fe4d
try reach the localhost mock in CI
skudasov cc4e526
check it can work both locally and in CI without code modification
skudasov e0465e6
check again
skudasov c75d06e
use the same Go version
skudasov c143938
example of CL client connection
skudasov 85d9973
connect all the clients
skudasov 3111ad8
example with contracts
skudasov d1ca470
finalize
skudasov cf1ea62
readmes
skudasov 95c9562
ignore caching, update
skudasov 2674e22
change CI workflow name
skudasov 8e8597a
re-trigger
skudasov 8fd3436
fix readme
skudasov 547f054
switch to v0.1.0
skudasov 7639522
fix go mod
skudasov d2581b2
use strict config version
skudasov 430f573
update go mod
skudasov 2ddc36c
add Sepolia example
skudasov 81c972f
simplify configuration
skudasov 5a82459
copy capabilities into container
skudasov f28c64a
expose p2p ports, add Fuji example
skudasov 87beabc
fund nodes
skudasov 29d8b77
use shared PG nodeset
skudasov db528ae
static node names
skudasov cde6a27
capabilities perms
skudasov 91aa2a4
capabilities perms again
skudasov f5a1a79
unified config for one or more node overrides
skudasov b1145e3
comment config
skudasov 7503510
docker rebuild from config
skudasov 3cd15e1
simplify, explicit rebuild using config, no flags
skudasov ee5b3e3
name tmp image if no name provided
skudasov b7f65bb
update
skudasov 1c378ba
add Blockscout for anvil
skudasov 53efba3
Merge branch 'develop' into ctf-v2-tests
skudasov 9e274b9
update the framework
skudasov 94d683d
update
skudasov a0dba25
demo chaos, reboot
skudasov 9645790
auth
skudasov 4abe9c5
bump CTF tag
skudasov 90f4944
show fast config reload
skudasov 1acf976
show fast config reload, take2
skudasov c4c4597
debug slow port allocation
skudasov 4c48749
update ctf
skudasov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,6 @@ credentials.env | |
gcr_creds.env | ||
|
||
go.work | ||
go.work.sum | ||
go.work.sum | ||
|
||
e2e/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
- 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 | ||
with: | ||
go-version: 1.22.8 | ||
- name: Cache Go modules | ||
uses: actions/cache@v3 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
2,038
e2e/capabilities/components/gethwrappers/burn_mint_erc677.go
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?