Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions framework/examples/myproject/fork_plus_offchain.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

[blockchain_src]
chain_id = "1337"
docker_cmd_params = ["--steps-tracing", "--fork-block-number", "25335999", "--fork-url", "https://rpcs.cldev.sh/base/sepolia/archive", "--auto-impersonate"]
# docker_cmd_params = ["-b", "1", "--steps-tracing"]
port = "8545"
docker_cmd_params = ["-b", "1"]
type = "anvil"

[blockchain_dst]
chain_id = "2337"
port = "8555"
docker_cmd_params = ["-b", "1"]
type = "anvil"

[contracts_src]
Expand Down
19 changes: 18 additions & 1 deletion framework/examples/myproject/fork_plus_offchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type CfgForkChainsOffChain struct {
ContractsSrc *onchain.Input `toml:"contracts_src" validate:"required"`
BlockchainSrc *blockchain.Input `toml:"blockchain_src" validate:"required"`
BlockchainDst *blockchain.Input `toml:"blockchain_dst" validate:"required"`
// off-chain components
NodeSets []*ns.Input `toml:"nodesets" validate:"required"`
}
Expand All @@ -31,19 +32,35 @@ func TestOffChainAndFork(t *testing.T) {
bcSrc, err := blockchain.NewBlockchainNetwork(in.BlockchainSrc)
require.NoError(t, err)

bcDst, err := blockchain.NewBlockchainNetwork(in.BlockchainDst)
require.NoError(t, err)

// create configs for 2 EVM networks
srcNetworkCfg, err := clnode.NewNetworkCfg(&clnode.EVMNetworkConfig{
MinIncomingConfirmations: 1,
MinContractPayment: "0.00001 link",
ChainID: bcSrc.ChainID,
EVMNodes: []*clnode.EVMNode{
{
Name: "one",
SendOnly: false,
Order: 100,
},
},
}, bcSrc)
in.NodeSets[0].NodeSpecs[0].Node.TestConfigOverrides = srcNetworkCfg
dstNetworkCfg, err := clnode.NewNetworkCfg(&clnode.EVMNetworkConfig{
MinIncomingConfirmations: 1,
MinContractPayment: "0.00001 link",
ChainID: bcDst.ChainID,
EVMNodes: []*clnode.EVMNode{
{
Name: "two",
SendOnly: false,
Order: 100,
},
},
}, bcDst)
in.NodeSets[0].NodeSpecs[0].Node.TestConfigOverrides = srcNetworkCfg + dstNetworkCfg

_, err = ns.NewSharedDBNodeSet(in.NodeSets[0], bcSrc)
require.NoError(t, err)
Expand Down
68 changes: 0 additions & 68 deletions lib/blockchain/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"go.uber.org/atomic"
"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/environment"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/conversions"
)

Expand Down Expand Up @@ -1395,25 +1394,6 @@ func NewEVMClientFromNetwork(networkSettings EVMNetwork, logger zerolog.Logger)
return wrappedClient, nil
}

// NewEVMClient returns a multi-node EVM client connected to the specified network
// Note: This should mostly be deprecated in favor of ConnectEVMClient. This is really only used when needing to connect
// to simulated networks
func NewEVMClient(networkSettings EVMNetwork, env *environment.Environment, logger zerolog.Logger) (EVMClient, error) {
if env == nil {
return nil, fmt.Errorf("environment nil, use ConnectEVMClient or provide a non-nil environment")
}

if networkSettings.Simulated {
if _, ok := env.URLs[networkSettings.Name]; !ok {
return nil, fmt.Errorf("network %s not found in environment", networkSettings.Name)
}
networkSettings.URLs = env.URLs[networkSettings.Name]
networkSettings.HTTPURLs = env.URLs[networkSettings.Name+"_http"]
}

return ConnectEVMClient(networkSettings, logger)
}

// ConnectEVMClient returns a multi-node EVM client connected to a specified network, using only URLs.
// Should mostly be used for inside K8s, non-simulated tests.
func ConnectEVMClient(networkSettings EVMNetwork, logger zerolog.Logger) (EVMClient, error) {
Expand Down Expand Up @@ -1485,54 +1465,6 @@ func ConnectEVMClient(networkSettings EVMNetwork, logger zerolog.Logger) (EVMCli
return wrappedClient, nil
}

// ConcurrentEVMClient returns a multi-node EVM client connected to a specified network
// It is used for concurrent interactions from different threads with the same network and from same owner
// account. This ensures that correct nonce value is fetched when an instance of EVMClient is initiated using this method.
// This is mainly useful for simulated networks as we don't use global nonce manager for them.
func ConcurrentEVMClient(networkSettings EVMNetwork, env *environment.Environment, existing EVMClient, logger zerolog.Logger) (EVMClient, error) {
// if not simulated use the NewEVMClient
if !networkSettings.Simulated {
return ConnectEVMClient(networkSettings, logger)
}
ecl := &EthereumMultinodeClient{}
if env != nil {
if _, ok := env.URLs[existing.GetNetworkConfig().Name]; !ok {
return nil, fmt.Errorf("network %s not found in environment", existing.GetNetworkConfig().Name)
}
networkSettings.URLs = env.URLs[existing.GetNetworkConfig().Name]
}
for idx, networkURL := range networkSettings.URLs {
networkSettings.URL = networkURL
ec, err := newEVMClient(networkSettings, logger)
if err != nil {
logger.Info().
Err(err).
Str("URL Suffix", networkURL[len(networkURL)-6:]).
Msg("failed to create new EVM client")
continue
}
// a call to BalanceAt (can be any on chain call) to ensure the client is connected
_, err = ec.BalanceAt(context.Background(), ec.GetDefaultWallet().address)
if err == nil {
ec.SyncNonce(existing)
ec.SetID(idx)
ecl.Clients = append(ecl.Clients, ec)
break
}
}
if len(ecl.Clients) == 0 {
return nil, fmt.Errorf("failed to create new EVM client")
}
ecl.DefaultClient = ecl.Clients[0]
wrappedClient := wrapMultiClient(networkSettings, ecl)
ecl.SetWallets(existing.GetWallets())
if err := ecl.SetDefaultWalletByAddress(existing.GetDefaultWallet().address); err != nil {
return nil, err
}
// no need to fund the account as it is already funded in the existing client
return wrappedClient, nil
}

// SetDefaultWalletByAddress sets default wallet by address if it exists, else returns error
func (e *EthereumMultinodeClient) SetDefaultWalletByAddress(address common.Address) error {
return e.DefaultClient.SetDefaultWalletByAddress(address)
Expand Down
Loading
Loading