Skip to content

Commit e3d1ddf

Browse files
[wip] chore: enable dumping the container logs of the forked environment
1 parent 41b8c65 commit e3d1ddf

5 files changed

Lines changed: 30 additions & 2 deletions

File tree

chain/evm/provider/ctf_anvil_provider.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ import (
208208
"fmt"
209209
"math/big"
210210
"net/http"
211+
"os"
212+
"slices"
211213
"strconv"
212214
"strings"
213215
"sync"
@@ -217,9 +219,11 @@ import (
217219
"github.com/avast/retry-go/v4"
218220
"github.com/ethereum/go-ethereum/accounts/abi/bind"
219221
"github.com/ethereum/go-ethereum/crypto"
222+
"github.com/rs/zerolog"
220223
chainsel "github.com/smartcontractkit/chain-selectors"
221224
"github.com/smartcontractkit/chainlink-testing-framework/framework"
222225
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
226+
ctfdocker "github.com/smartcontractkit/chainlink-testing-framework/lib/docker"
223227
"github.com/smartcontractkit/freeport"
224228
"github.com/testcontainers/testcontainers-go"
225229

@@ -516,6 +520,14 @@ func (p *CTFAnvilChainProvider) GetNodeHTTPURL() string {
516520
// Returns an error if the container termination fails.
517521
func (p *CTFAnvilChainProvider) Cleanup(ctx context.Context) error {
518522
if p.container != nil {
523+
if shouldSaveCtfContainerLogs() {
524+
zlogger := zerolog.New(os.Stdout)
525+
ctfdocker.WriteAllContainersLogs(zlogger, "logs")
526+
wd, _ := os.Getwd()
527+
zlogger.Info().Msgf("container logs saved to \"%s/logs\"", wd)
528+
}
529+
530+
// if slices.Contains([]string{}, strconv.ToLower(os.GetEnv("CTF_CONTAINER_LOGS")) {
519531
err := p.container.Terminate(ctx)
520532
if err != nil {
521533
return fmt.Errorf("failed to terminate Anvil container: %w", err)
@@ -714,3 +726,8 @@ func (p *CTFAnvilChainProvider) waitForAnvilReady(ctx context.Context, httpURL s
714726
retry.DelayType(retry.FixedDelay),
715727
)
716728
}
729+
730+
func shouldSaveCtfContainerLogs() bool {
731+
trueValues := []string{"1", "true", "on", "enabled"}
732+
return slices.Contains(trueValues, strings.ToLower(os.Getenv("CTF_CONTAINER_LOGS")))
733+
}

engine/cld/environment/anvil.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type RPCs struct {
117117
type ChainConfig struct {
118118
ChainID string // chain id as per EIP-155
119119
HTTPRPCs []RPCs // http rpcs to connect to the chain
120+
Provider *evmprov.CTFAnvilChainProvider
120121
}
121122

122123
// AnvilChainsOutput represents the output of the newAnvilChains function.
@@ -287,6 +288,7 @@ func newAnvilChains(
287288

288289
chainConfigsBySelector[chainSelector] = ChainConfig{
289290
ChainID: chainIDStr,
291+
Provider: provider,
290292
HTTPRPCs: []RPCs{
291293
{
292294
External: provider.GetNodeHTTPURL(),

engine/cld/legacy/cli/mcmsv2/mcms_v2.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,13 @@ func buildExecuteForkCommand(lggr logger.Logger, domain cldf_domain.Domain, prop
619619
if err != nil {
620620
return fmt.Errorf("error creating config: %w", err)
621621
}
622+
defer func() {
623+
for _, chainConfig := range cfg.forkedEnv.ChainConfigs {
624+
if chainConfig.Provider != nil {
625+
chainConfig.Provider.Cleanup(cmd.Context())
626+
}
627+
}
628+
}()
622629

623630
// get the chain URL, chain ID and MCM contract address
624631
url := cfg.forkedEnv.ChainConfigs[cfg.chainSelector].HTTPRPCs[0].External

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ require (
3434
github.com/smartcontractkit/chainlink-protos/job-distributor v0.12.0
3535
github.com/smartcontractkit/chainlink-protos/op-catalog v0.0.4
3636
github.com/smartcontractkit/chainlink-testing-framework/framework v0.10.30
37+
github.com/smartcontractkit/chainlink-testing-framework/lib v1.54.6
3738
github.com/smartcontractkit/chainlink-testing-framework/seth v1.51.2
3839
github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250815105909-75499abc4335
3940
github.com/smartcontractkit/freeport v0.1.2
@@ -226,7 +227,7 @@ require (
226227
github.com/rivo/uniseg v0.4.7 // indirect
227228
github.com/rogpeppe/go-internal v1.13.1 // indirect
228229
github.com/rs/cors v1.11.1 // indirect
229-
github.com/rs/zerolog v1.33.0 // indirect
230+
github.com/rs/zerolog v1.33.0
230231
github.com/russross/blackfriday/v2 v2.1.0 // indirect
231232
github.com/sagikazarmark/locafero v0.11.0 // indirect
232233
github.com/samber/lo v1.49.1 // indirect
@@ -283,7 +284,6 @@ require (
283284
go.opentelemetry.io/otel/sdk/metric v1.37.0 // indirect
284285
go.opentelemetry.io/otel/trace v1.37.0 // indirect
285286
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
286-
go.uber.org/atomic v1.11.0 // indirect
287287
go.uber.org/multierr v1.11.0 // indirect
288288
go.uber.org/ratelimit v0.3.1 // indirect
289289
golang.org/x/net v0.43.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ github.com/smartcontractkit/chainlink-sui v0.0.0-20251013155034-5f85c5f450ab h1:
696696
github.com/smartcontractkit/chainlink-sui v0.0.0-20251013155034-5f85c5f450ab/go.mod h1:VlyZhVw+a93Sk8rVHOIH6tpiXrMzuWLZrjs1eTIExW8=
697697
github.com/smartcontractkit/chainlink-testing-framework/framework v0.10.30 h1:mDxJnEl5jKs3FLHKIjwtCFEP4ihKhFS6yuPDNcC0EDM=
698698
github.com/smartcontractkit/chainlink-testing-framework/framework v0.10.30/go.mod h1:SoCjdzeZHP500QtKAjJ9I6rHD03SkQmRL4dNkOoe6yk=
699+
github.com/smartcontractkit/chainlink-testing-framework/lib v1.54.6 h1:t1db5+sEbmw/26xQVDqyeY448V4RW8xtAl4eNGpd0uw=
700+
github.com/smartcontractkit/chainlink-testing-framework/lib v1.54.6/go.mod h1:dgwtcefGr+0i+C2S6V/Xgntzm7E5CPxXMyi2OnQvnHI=
699701
github.com/smartcontractkit/chainlink-testing-framework/seth v1.51.2 h1:ZJ/8Jx6Be5//TyjPi1pS1uotnmcYq5vVkSyISIymSj8=
700702
github.com/smartcontractkit/chainlink-testing-framework/seth v1.51.2/go.mod h1:kHYJnZUqiPF7/xN5273prV+srrLJkS77GbBXHLKQpx0=
701703
github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250815105909-75499abc4335 h1:7bxYNrPpygn8PUSBiEKn8riMd7CXMi/4bjTy0fHhcrY=

0 commit comments

Comments
 (0)