Skip to content

Commit 08ed5b6

Browse files
committed
allow passing context to all components' constructors
1 parent 3780857 commit 08ed5b6

File tree

22 files changed

+128
-62
lines changed

22 files changed

+128
-62
lines changed

framework/components/blockchain/anvil.go

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

33
import (
4+
"context"
45
"strings"
56

67
"github.com/smartcontractkit/chainlink-testing-framework/framework"
@@ -31,8 +32,7 @@ func defaultAnvil(in *Input) {
3132
}
3233
}
3334

34-
// newAnvil deploy foundry anvil node
35-
func newAnvil(in *Input) (*Output, error) {
35+
func newAnvil(ctx context.Context, in *Input) (*Output, error) {
3636
if in.Out != nil && in.Out.UseCache {
3737
return in.Out, nil
3838
}
@@ -50,5 +50,5 @@ func newAnvil(in *Input) (*Output, error) {
5050

5151
framework.L.Info().Any("Cmd", strings.Join(entryPoint, " ")).Msg("Creating anvil with command")
5252

53-
return createGenericEvmContainer(in, req, false)
53+
return createGenericEvmContainer(ctx, in, req, false)
5454
}

framework/components/blockchain/anvil_zksync.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package blockchain
22

33
import (
4+
"context"
45
"os"
56
"path/filepath"
67
"strings"
@@ -41,7 +42,7 @@ RUN curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/in
4142
// creating a dockerfile in a temporary directory with the necessary commands to install
4243
// foundry-zksync.
4344
// see: https://foundry-book.zksync.io/getting-started/installation#using-foundry-with-docker
44-
func newAnvilZksync(in *Input) (*Output, error) {
45+
func newAnvilZksync(ctx context.Context, in *Input) (*Output, error) {
4546
defaultAnvilZksync(in)
4647
req := baseRequest(in, WithoutWsEndpoint)
4748

@@ -77,7 +78,7 @@ func newAnvilZksync(in *Input) (*Output, error) {
7778

7879
framework.L.Info().Any("Cmd", strings.Join(req.Entrypoint, " ")).Msg("Creating anvil zkSync with command")
7980

80-
output, err := createGenericEvmContainer(in, req, false)
81+
output, err := createGenericEvmContainer(ctx, in, req, false)
8182
if err != nil {
8283
return nil, err
8384
}

framework/components/blockchain/aptos.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ func defaultAptos(in *Input) {
5050
}
5151
}
5252

53-
func newAptos(in *Input) (*Output, error) {
53+
func newAptos(ctx context.Context, in *Input) (*Output, error) {
5454
defaultAptos(in)
55-
ctx := context.Background()
5655
containerName := framework.DefaultTCName("blockchain-node")
5756

5857
absPath, err := filepath.Abs(in.ContractsDir)

framework/components/blockchain/besu.go

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

3+
import "context"
4+
35
const (
46
DefaultBesuPrivateKey1 = "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"
57
DefaultBesuPrivateKey2 = "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3"
@@ -24,7 +26,7 @@ func defaultBesu(in *Input) {
2426
}
2527
}
2628

27-
func newBesu(in *Input) (*Output, error) {
29+
func newBesu(ctx context.Context, in *Input) (*Output, error) {
2830
defaultBesu(in)
2931
req := baseRequest(in, WithWsEndpoint)
3032

@@ -48,5 +50,5 @@ func newBesu(in *Input) (*Output, error) {
4850
entryPoint := append(defaultCmd, in.DockerCmdParamsOverrides...)
4951
req.Cmd = entryPoint
5052

51-
return createGenericEvmContainer(in, req, true)
53+
return createGenericEvmContainer(ctx, in, req, true)
5254
}

framework/components/blockchain/blockchain.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package blockchain
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/testcontainers/testcontainers-go"
@@ -93,29 +94,34 @@ type Node struct {
9394
InternalHTTPUrl string `toml:"internal_http_url"`
9495
}
9596

96-
// NewBlockchainNetwork this is an abstraction that can spin up various blockchain network simulators
9797
func NewBlockchainNetwork(in *Input) (*Output, error) {
98+
// pass context to input if needed in the future
99+
return NewWithContext(context.Background(), in)
100+
}
101+
102+
// NewBlockchainNetwork this is an abstraction that can spin up various blockchain network simulators
103+
func NewWithContext(ctx context.Context, in *Input) (*Output, error) {
98104
var out *Output
99105
var err error
100106
switch in.Type {
101107
case TypeAnvil:
102-
out, err = newAnvil(in)
108+
out, err = newAnvil(ctx, in)
103109
case TypeGeth:
104-
out, err = newGeth(in)
110+
out, err = newGeth(ctx, in)
105111
case TypeBesu:
106-
out, err = newBesu(in)
112+
out, err = newBesu(ctx, in)
107113
case TypeSolana:
108-
out, err = newSolana(in)
114+
out, err = newSolana(ctx, in)
109115
case TypeAptos:
110-
out, err = newAptos(in)
116+
out, err = newAptos(ctx, in)
111117
case TypeSui:
112-
out, err = newSui(in)
118+
out, err = newSui(ctx, in)
113119
case TypeTron:
114-
out, err = newTron(in)
120+
out, err = newTron(ctx, in)
115121
case TypeAnvilZKSync:
116-
out, err = newAnvilZksync(in)
122+
out, err = newAnvilZksync(ctx, in)
117123
case TypeTon:
118-
out, err = newTon(in)
124+
out, err = newTon(ctx, in)
119125
default:
120126
return nil, fmt.Errorf("blockchain type is not supported or empty, must be 'anvil' or 'geth'")
121127
}

framework/components/blockchain/containers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ func baseRequest(in *Input, useWS ExposeWs) testcontainers.ContainerRequest {
6565
return req
6666
}
6767

68-
func createGenericEvmContainer(in *Input, req testcontainers.ContainerRequest, useWS bool) (*Output, error) {
69-
ctx := context.Background()
68+
func createGenericEvmContainer(ctx context.Context, in *Input, req testcontainers.ContainerRequest, useWS bool) (*Output, error) {
7069
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
7170
ContainerRequest: req,
7271
Started: true,

framework/components/blockchain/geth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package blockchain
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67

@@ -77,7 +78,7 @@ func defaultGeth(in *Input) {
7778
}
7879
}
7980

80-
func newGeth(in *Input) (*Output, error) {
81+
func newGeth(ctx context.Context, in *Input) (*Output, error) {
8182
defaultGeth(in)
8283
req := baseRequest(in, WithoutWsEndpoint)
8384
defaultCmd := []string{
@@ -184,5 +185,5 @@ func newGeth(in *Input) (*Output, error) {
184185
}
185186
req.Cmd = entryPoint
186187

187-
return createGenericEvmContainer(in, req, false)
188+
return createGenericEvmContainer(ctx, in, req, false)
188189
}

framework/components/blockchain/solana.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ func defaultSolana(in *Input) {
4343
}
4444
}
4545

46-
func newSolana(in *Input) (*Output, error) {
46+
func newSolana(ctx context.Context, in *Input) (*Output, error) {
4747
if in.Out != nil && in.Out.UseCache {
4848
return in.Out, nil
4949
}
5050
defaultSolana(in)
51-
ctx := context.Background()
5251

5352
containerName := framework.DefaultTCName("blockchain-node")
5453
// Solana do not allow to set ws port, it just uses --rpc-port=N and sets WS as N+1 automatically

framework/components/blockchain/sui.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ func defaultSui(in *Input) {
9090
}
9191
}
9292

93-
func newSui(in *Input) (*Output, error) {
93+
func newSui(ctx context.Context, in *Input) (*Output, error) {
9494
defaultSui(in)
95-
ctx := context.Background()
9695
containerName := framework.DefaultTCName("blockchain-node")
9796

9897
absPath, err := filepath.Abs(in.ContractsDir)

framework/components/blockchain/ton.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func defaultTon(in *Input) {
4040
}
4141
}
4242

43-
func newTon(in *Input) (*Output, error) {
43+
func newTon(ctx context.Context, in *Input) (*Output, error) {
4444
defaultTon(in)
4545

4646
base, err := strconv.Atoi(in.Port)
@@ -53,8 +53,6 @@ func newTon(in *Input) (*Output, error) {
5353
LiteServer: strconv.Itoa(base + liteServerPortOffset),
5454
}
5555

56-
ctx := context.Background()
57-
5856
network, err := network.New(ctx,
5957
network.WithAttachable(),
6058
network.WithLabels(framework.DefaultTCLabels()),

0 commit comments

Comments
 (0)