Skip to content

Commit 5834a01

Browse files
authored
JD dump for fork testing with a new CSA key (#1812)
* JD db dump * changeset
1 parent e109695 commit 5834a01

File tree

10 files changed

+54
-81
lines changed

10 files changed

+54
-81
lines changed

framework/.changeset/v0.7.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- JD with a real DB dump

framework/components/jd/jd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Input struct {
2828
CSAEncryptionKey string `toml:"csa_encryption_key"`
2929
DockerFilePath string `toml:"docker_file"`
3030
DockerContext string `toml:"docker_ctx"`
31+
JDSQLDumpPath string `toml:"jd_sql_dump_path"`
3132
DBInput *postgres.Input `toml:"db"`
3233
Out *Output `toml:"out"`
3334
}
@@ -56,7 +57,7 @@ func defaults(in *Input) {
5657

5758
func defaultJDDB() *postgres.Input {
5859
return &postgres.Input{
59-
Image: "postgres:12",
60+
Image: "postgres:16",
6061
Port: 14000,
6162
Name: "jd-db",
6263
VolumeName: "jd",
@@ -77,6 +78,7 @@ func NewJD(in *Input) (*Output, error) {
7778
if in.DBInput == nil {
7879
in.DBInput = defaultJDDB()
7980
}
81+
in.DBInput.JDSQLDumpPath = in.JDSQLDumpPath
8082
pgOut, err := postgres.NewPostgreSQL(in.DBInput)
8183
if err != nil {
8284
return nil, err

framework/components/postgres/postgres.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
Port = "5432"
2323
ExposedStaticPort = 13000
2424
Database = "chainlink"
25+
JDDatabase = "job-distributor-db"
2526
DBVolumeName = "postgresql_data"
2627
)
2728

@@ -32,6 +33,7 @@ type Input struct {
3233
VolumeName string `toml:"volume_name"`
3334
Databases int `toml:"databases"`
3435
JDDatabase bool `toml:"jd_database"`
36+
JDSQLDumpPath string `toml:"jd_sql_dump_path"`
3537
PullImage bool `toml:"pull_image"`
3638
ContainerResources *framework.ContainerResources `toml:"resources"`
3739
Out *Output `toml:"out"`
@@ -64,10 +66,23 @@ func NewPostgreSQL(in *Input) (*Output, error) {
6466
"CREATE EXTENSION pg_stat_statements;",
6567
)
6668
}
69+
sqlCommands = append(sqlCommands, "ALTER USER chainlink WITH SUPERUSER;")
6770
if in.JDDatabase {
68-
sqlCommands = append(sqlCommands, "CREATE DATABASE jd;")
71+
if in.JDSQLDumpPath != "" {
72+
// if we have a full dump we replace RDS specific commands and apply it creating db and filling the tables
73+
d, err := os.ReadFile(in.JDSQLDumpPath)
74+
if err != nil {
75+
return nil, fmt.Errorf("error reading JD dump file '%s': %v", in.JDSQLDumpPath, err)
76+
}
77+
// transaction_timeout is a custom RDS instruction, we must replace it
78+
sqlMigration := strings.Replace(string(d), "SET transaction_timeout = 0;", "", -1)
79+
sqlCommands = append(sqlCommands, sqlMigration)
80+
sqlCommands = append(sqlCommands, "DELETE FROM public.csa_keypairs where id = 1;")
81+
} else {
82+
// if we don't have a dump we create an empty DB
83+
sqlCommands = append(sqlCommands, fmt.Sprintf("CREATE DATABASE \"%s\";", JDDatabase))
84+
}
6985
}
70-
sqlCommands = append(sqlCommands, "ALTER USER chainlink WITH SUPERUSER;")
7186
initSQL := strings.Join(sqlCommands, "\n")
7287
initFile, err := os.CreateTemp("", "init-*.sql")
7388
if err != nil {
@@ -176,15 +191,15 @@ func NewPostgreSQL(in *Input) (*Output, error) {
176191
Password,
177192
containerName,
178193
Port,
179-
"jd",
194+
JDDatabase,
180195
)
181196
o.JDUrl = fmt.Sprintf(
182197
"postgresql://%s:%s@%s:%d/%s?sslmode=disable",
183198
User,
184199
Password,
185200
host,
186201
portToExpose,
187-
"jd",
202+
JDDatabase,
188203
)
189204
}
190205
return o, nil

framework/examples/myproject/fork_plus_offchain.toml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11

2-
[blockchain_dst]
3-
chain_id = "2337"
4-
# docker_cmd_params = ["--fork-url", "wss://avalanche-fuji-c-chain-rpc.publicnode.com", "--auto-impersonate", "-b", "1"]
5-
docker_cmd_params = ["-b", "1"]
6-
port = "8545"
7-
type = "anvil"
8-
92
[blockchain_src]
10-
chain_id = "3337"
11-
# docker_cmd_params = ["--fork-url", "wss://avalanche-fuji-c-chain-rpc.publicnode.com", "--auto-impersonate", "-b", "1"]
12-
docker_cmd_params = ["-b", "1"]
13-
port = "8555"
3+
chain_id = "1337"
4+
docker_cmd_params = ["--steps-tracing", "--fork-block-number", "25335999", "--fork-url", "https://rpcs.cldev.sh/base/sepolia/archive", "--auto-impersonate"]
5+
# docker_cmd_params = ["-b", "1", "--steps-tracing"]
146
type = "anvil"
157

16-
[contracts_dst]
17-
188
[contracts_src]
199

2010
[[nodesets]]

framework/examples/myproject/fork_plus_offchain_test.go

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ import (
1818

1919
type CfgForkChainsOffChain struct {
2020
ContractsSrc *onchain.Input `toml:"contracts_src" validate:"required"`
21-
ContractsDst *onchain.Input `toml:"contracts_dst" validate:"required"`
2221
BlockchainSrc *blockchain.Input `toml:"blockchain_src" validate:"required"`
23-
BlockchainDst *blockchain.Input `toml:"blockchain_dst" validate:"required"`
2422
// off-chain components
25-
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
23+
NodeSets []*ns.Input `toml:"nodesets" validate:"required"`
2624
}
2725

2826
func TestOffChainAndFork(t *testing.T) {
@@ -33,9 +31,6 @@ func TestOffChainAndFork(t *testing.T) {
3331
bcSrc, err := blockchain.NewBlockchainNetwork(in.BlockchainSrc)
3432
require.NoError(t, err)
3533

36-
bcDst, err := blockchain.NewBlockchainNetwork(in.BlockchainDst)
37-
require.NoError(t, err)
38-
3934
// create configs for 2 EVM networks
4035
srcNetworkCfg, err := clnode.NewNetworkCfg(&clnode.EVMNetworkConfig{
4136
MinIncomingConfirmations: 1,
@@ -48,66 +43,31 @@ func TestOffChainAndFork(t *testing.T) {
4843
},
4944
},
5045
}, bcSrc)
51-
dstNetworkConfig, err := clnode.NewNetworkCfg(&clnode.EVMNetworkConfig{
52-
MinIncomingConfirmations: 1,
53-
MinContractPayment: "0.00001 link",
54-
ChainID: bcSrc.ChainID,
55-
EVMNodes: []*clnode.EVMNode{
56-
{
57-
SendOnly: false,
58-
Order: 100,
59-
},
60-
},
61-
}, bcDst)
62-
// override the configuration
63-
in.NodeSet.NodeSpecs[0].Node.TestConfigOverrides = srcNetworkCfg + dstNetworkConfig
46+
in.NodeSets[0].NodeSpecs[0].Node.TestConfigOverrides = srcNetworkCfg
6447

65-
// create a node set
66-
_, err = ns.NewSharedDBNodeSet(in.NodeSet, bcSrc)
48+
_, err = ns.NewSharedDBNodeSet(in.NodeSets[0], bcSrc)
6749
require.NoError(t, err)
6850

69-
// connect 2 clients
7051
scSrc, err := seth.NewClientBuilder().
7152
WithRpcUrl(bcSrc.Nodes[0].ExternalWSUrl).
7253
WithGasPriceEstimations(true, 0, seth.Priority_Fast).
7354
WithTracing(seth.TracingLevel_All, []string{seth.TraceOutput_Console}).
7455
WithPrivateKeys([]string{blockchain.DefaultAnvilPrivateKey}).
7556
Build()
7657
require.NoError(t, err)
77-
scDst, err := seth.NewClientBuilder().
78-
WithRpcUrl(bcDst.Nodes[0].ExternalWSUrl).
79-
WithGasPriceEstimations(true, 0, seth.Priority_Fast).
80-
WithTracing(seth.TracingLevel_All, []string{seth.TraceOutput_Console}).
81-
WithPrivateKeys([]string{blockchain.DefaultAnvilPrivateKey}).
82-
Build()
83-
require.NoError(t, err)
8458

85-
// deploy 2 example product contracts
86-
// you should replace it with chainlink-deployments
8759
in.ContractsSrc.URL = bcSrc.Nodes[0].ExternalWSUrl
8860
contractsSrc, err := onchain.NewProductOnChainDeployment(scSrc, in.ContractsSrc)
8961
require.NoError(t, err)
90-
in.ContractsDst.URL = bcDst.Nodes[0].ExternalWSUrl
91-
contractsDst, err := onchain.NewProductOnChainDeployment(scDst, in.ContractsDst)
92-
require.NoError(t, err)
9362

9463
t.Run("test some contracts with fork", func(t *testing.T) {
95-
// interact with a source chain
9664
i, err := testToken.NewBurnMintERC677(contractsSrc.Addresses[0], scSrc.Client)
9765
require.NoError(t, err)
9866
balance, err := i.BalanceOf(scSrc.NewCallOpts(), contractsSrc.Addresses[0])
9967
require.NoError(t, err)
10068
fmt.Println(balance)
10169

102-
// interact with a destination chain
103-
i, err = testToken.NewBurnMintERC677(contractsDst.Addresses[0], scDst.Client)
104-
require.NoError(t, err)
105-
balance, err = i.BalanceOf(scDst.NewCallOpts(), contractsDst.Addresses[0])
106-
require.NoError(t, err)
107-
fmt.Println(balance)
108-
10970
// Use anvil methods, see https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/rpc/rpc.go
11071
_ = rpc.New(bcSrc.Nodes[0].ExternalHTTPUrl, nil)
111-
_ = rpc.New(bcDst.Nodes[0].ExternalHTTPUrl, nil)
11272
})
11373
}

framework/examples/myproject_cll/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,16 @@ docker build -t job-distributor:0.9.0 -f e2e/Dockerfile.e2e .
1111

1212
Run the tests locally
1313
```
14-
CTF_CONFIGS=jd.toml go test -v -count 1 -run TestJD
14+
CTF_CONFIGS=jd.toml go test -v -run TestJD
15+
```
16+
17+
## Job Distributor from staging dump
18+
Get `.sql` dump from staging or production service and then run
19+
```
20+
CTF_CONFIGS=jd_dump.toml go test -v run TestJD
21+
```
22+
23+
## Connect to the database
24+
```
25+
PGPASSWORD=thispasswordislongenough psql -h 0.0.0.0 -p 14000 -U chainlink -d job-distributor-db
1526
```
-889 Bytes
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[blockchain]
2+
type = "anvil"
3+
chain_id = "1337"
4+
docker_cmd_params = ["--fork-url", "wss://avalanche-fuji-c-chain-rpc.publicnode.com", "--auto-impersonate", "-b", "1"]
5+
6+
[jd]
7+
jd_sql_dump_path = "db.sql"
8+
image = "job-distributor:0.9.0"

framework/examples/myproject_cll/jd_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,8 @@ func TestJD(t *testing.T) {
2424

2525
jdOut, err := jd.NewJD(in.JD)
2626
require.NoError(t, err)
27-
dc, err := framework.NewDockerClient()
28-
require.NoError(t, err)
29-
// find what to dump, RDS API here instead?
30-
_, err = dc.ExecContainer(jdOut.DBContainerName, []string{"pg_dump", "-U", "chainlink", "-h", "localhost", "-p", "5432", "-d", "chainlink", "-F", "c", "-f", "jd.dump"})
31-
require.NoError(t, err)
32-
33-
// copy your dump
34-
err = dc.CopyFile(jdOut.DBContainerName, "jd.dump", "/")
35-
require.NoError(t, err)
36-
37-
// restore
38-
_, err = dc.ExecContainer(jdOut.DBContainerName, []string{"pg_restore", "-U", "chainlink", "-d", "chainlink", "jd.dump"})
39-
require.NoError(t, err)
4027

41-
t.Run("test changesets with forked network and real JD state", func(t *testing.T) {
28+
t.Run("test changesets with forked network/JD state", func(t *testing.T) {
4229
_ = bcOut
4330
_ = jdOut
4431
})

wasp/examples/simple_rps/main_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"os"
54
"testing"
65
"time"
76

@@ -13,16 +12,16 @@ func TestGun(t *testing.T) {
1312
srv := wasp.NewHTTPMockServer(nil)
1413
srv.Run()
1514

16-
branch := os.Getenv("BRANCH")
17-
commit := os.Getenv("COMMIT")
15+
//branch := os.Getenv("BRANCH")
16+
//commit := os.Getenv("COMMIT")
1817

1918
// define labels for differentiate one run from another
2019
labels := map[string]string{
2120
// check variables in dashboard/dashboard.go
2221
"go_test_name": "generator_healthcheck",
2322
"gen_name": "generator_healthcheck",
24-
"branch": branch,
25-
"commit": commit,
23+
"branch": "test",
24+
"commit": "test",
2625
}
2726

2827
// create generator

0 commit comments

Comments
 (0)