Skip to content

Commit

Permalink
[TT-1511] added ability to read ABIs from Gethwrappers (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel authored Aug 28, 2024
1 parent c852ecd commit d08c022
Show file tree
Hide file tree
Showing 33 changed files with 18,383 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .githooks/go-lint
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ find "./" -type f -name 'go.mod' -print0 | while IFS= read -r -d $'\0' file; do

# Run linter and capture exit status
set +e
golangci-lint run
golangci-lint run -v
linting_result=$?
set -e

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/seth-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
if: steps.changes.outputs.src == 'true'
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
- name: Lint
if: steps.changes.outputs.src == 'true'
run: |
nix develop -c make lint
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ issues:
- wasp/examples/*
- seth/examples_wasp/*
- k8s
- seth/contracts
- seth/examples
- seth/examples_wasp
31 changes: 31 additions & 0 deletions docker/test_env/cmd/.private_chains/ethereum_network_2ad80558.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ethereum_version = 'eth2'
consensus_layer = 'prysm'
execution_layer = 'geth'
docker_network_names = ['network-25952094-f1aa-4ee1-8459-f28928cad7c9']
wait_for_finalization = false
generated_data_host_dir = '/var/folders/q4/975jb0kx3bb2x_yy0_7mf2y00000gn/T/metadata1688318665'
val_keys_dir = '/var/folders/q4/975jb0kx3bb2x_yy0_7mf2y00000gn/T/val_keys2002154029'
node_log_level = 'info'

[[containers]]
container_name = 'geth-eth2-v1_14_3-22cb547f'
container_type = 'execution_layer'

[[containers]]
container_name = 'prysm-beacon-chain-6051e27f'
container_type = 'consensus_layer'

[[containers]]
container_name = 'prysm-validator-975ad786'
container_type = 'consensus_validator'

[EthereumChainConfig]
seconds_per_slot = 6
slots_per_epoch = 2
genesis_delay = 15
validator_count = 8
chain_id = 1337
GenesisTimestamp = 1724770017
addresses_to_fund = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']

[EthereumChainConfig.HardForkEpochs]
31 changes: 31 additions & 0 deletions docker/test_env/cmd/.private_chains/ethereum_network_6c196142.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ethereum_version = 'eth2'
consensus_layer = 'prysm'
execution_layer = 'geth'
docker_network_names = ['network-1c36e593-ba16-41b9-a5e9-c1ac0084175c']
wait_for_finalization = false
generated_data_host_dir = '/var/folders/q4/975jb0kx3bb2x_yy0_7mf2y00000gn/T/metadata3375294890'
val_keys_dir = '/var/folders/q4/975jb0kx3bb2x_yy0_7mf2y00000gn/T/val_keys3731567686'
node_log_level = 'info'

[[containers]]
container_name = 'geth-eth2-v1_14_3-d3d721f4'
container_type = 'execution_layer'

[[containers]]
container_name = 'prysm-beacon-chain-f5ae0a0f'
container_type = 'consensus_layer'

[[containers]]
container_name = 'prysm-validator-92dea702'
container_type = 'consensus_validator'

[EthereumChainConfig]
seconds_per_slot = 6
slots_per_epoch = 2
genesis_delay = 15
validator_count = 8
chain_id = 2337
GenesisTimestamp = 1724770169
addresses_to_fund = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']

[EthereumChainConfig.HardForkEpochs]
86 changes: 86 additions & 0 deletions seth/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
run:
concurrency: 4
timeout: 5m
linters:
enable:
# defaults
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
# extra
- exhaustive
- exportloopref
- revive
- goimports
- gosec
- misspell
- errorlint
- contextcheck
linters-settings:
exhaustive:
default-signifies-exhaustive: true
goimports:
local-prefixes: github.com/smartcontractkit/chainlink-testing-framework/seth
gosec:
exclude-generated: true
govet:
# report about shadowed variables
check-shadowing: false
errorlint:
# Allow formatting of errors without %w
errorf: false
revive:
confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: if-return
- name: increment-decrement
# - name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: exported
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
- name: waitgroup-by-value
- name: unconditional-recursion
- name: struct-tag
- name: string-format
- name: string-of-int
- name: range-val-address
- name: range-val-in-closure
- name: modifies-value-receiver
- name: modifies-parameter
- name: identical-branches
- name: get-return
- name: flag-parameter
- name: early-return
- name: defer
- name: constant-logical-expr
- name: confusing-naming
# - name: confusing-results
- name: bool-literal-in-expr
- name: atomic
issues:
exclude-dirs:
- contracts/*
- examples/*
- examples_wasp/*
2 changes: 1 addition & 1 deletion seth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ test_cover:

.PHONY: lint
lint:
golangci-lint --color=always run -v
golangci-lint --color=always run -v -c .golangci.yml
4 changes: 3 additions & 1 deletion seth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,15 @@ client, err := builder.
WithProtections(true, true, seth.MustMakeDuration(2*time.Minute)).
// artifacts folder
WithArtifactsFolder("some_folder").
// folder with gethwrappers for ABI decoding
WithGethWrappersFolders([]string{"./gethwrappers/ccip", "./gethwrappers/keystone"}).
// nonce manager
WithNonceManager(10, 3, 60, 5).
// EIP-1559 and gas estimations
WithEIP1559DynamicFees(true).
WithDynamicGasPrices(120_000_000_000, 44_000_000_000).
WithGasPriceEstimations(false, 10, seth.Priority_Fast).
// gas bumping: retries, max gas price, bumping strategy function
// gas bumping: retries, max gas price, bumping strategy function
WithGasBumping(5, 100_000_000_000, PriorityBasedGasBumpingStrategyFn).
Build()

Expand Down
4 changes: 2 additions & 2 deletions seth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewClientWithConfig(cfg *Config) (*Client, error) {
L.Debug().Msgf("Using tracing level: %s", cfg.TracingLevel)

cfg.setEphemeralAddrs()
cs, err := NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir))
cs, err := NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir), cfg.GethWrappersDirs)
if err != nil {
return nil, errors.Wrap(err, ErrCreateABIStore)
}
Expand Down Expand Up @@ -354,7 +354,7 @@ func NewClientRaw(

if c.Cfg.TracingLevel != TracingLevel_None && c.Tracer == nil {
if c.ContractStore == nil {
cs, err := NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir))
cs, err := NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir), cfg.GethWrappersDirs)
if err != nil {
return nil, errors.Wrap(err, ErrCreateABIStore)
}
Expand Down
7 changes: 7 additions & 0 deletions seth/client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ func (c *ClientBuilder) WithArtifactsFolder(folder string) *ClientBuilder {
return c
}

// WithGethWrappersFolders sets list of folders where the Geth wrappers are stored. Seth will load ABIs from all wrappers it finds in theses folders (including subfolders).
// Default value is an empty string (= loading disabled).
func (c *ClientBuilder) WithGethWrappersFolders(folders []string) *ClientBuilder {
c.config.GethWrappersDirs = folders
return c
}

// WithNonceManager sets the rate limit for key sync, number of retries, timeout and retry delay.
// Default values are 10 calls per second, 3 retires, 60s timeout and 5s retry delay.
func (c *ClientBuilder) WithNonceManager(rateLimitSec int, retries uint, timeout, retryDelay time.Duration) *ClientBuilder {
Expand Down
2 changes: 1 addition & 1 deletion seth/client_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func NewDebugContractSetup() (
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, err
}
cs, err := seth.NewContractStore("./contracts/abi", "./contracts/bin")
cs, err := seth.NewContractStore("./contracts/abi", "./contracts/bin", nil)
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions seth/client_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ func TestTraceContractTracingClientInitialisesTracerIfTracingIsEnabled(t *testin
cfg, err := test_utils.CopyConfig(TestEnv.Client.Cfg)
require.NoError(t, err, "failed to copy config")

as, err := seth.NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir))
as, err := seth.NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir), nil)
require.NoError(t, err, "failed to create contract store")

nm, err := seth.NewNonceManager(cfg, TestEnv.Client.Addresses, TestEnv.Client.PrivateKeys)
Expand Down Expand Up @@ -1567,7 +1567,7 @@ func TestTraceContractTracingSaveToJson(t *testing.T) {
cfg, err := test_utils.CopyConfig(TestEnv.Client.Cfg)
require.NoError(t, err, "failed to copy config")

as, err := seth.NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir))
as, err := seth.NewContractStore(filepath.Join(cfg.ConfigDir, cfg.ABIDir), filepath.Join(cfg.ConfigDir, cfg.BINDir), nil)
require.NoError(t, err, "failed to create contract store")

nm, err := seth.NewNonceManager(cfg, TestEnv.Client.Addresses, TestEnv.Client.PrivateKeys)
Expand Down
1 change: 1 addition & 0 deletions seth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Config struct {
RootKeyFundsBuffer *int64 `toml:"root_key_funds_buffer"`
ABIDir string `toml:"abi_dir"`
BINDir string `toml:"bin_dir"`
GethWrappersDirs []string `toml:"geth_wrappers_dirs"`
ContractMapFile string `toml:"contract_map_file"`
SaveDeployedContractsMap bool `toml:"save_deployed_contracts_map"`
Network *Network `toml:"network"`
Expand Down
2 changes: 2 additions & 0 deletions seth/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func TestConfig_MaximalBuilder(t *testing.T) {
WithProtections(true, true, seth.MustMakeDuration(2*time.Minute)).
// artifacts folder
WithArtifactsFolder("some_folder").
// geth wrappers folders
WithGethWrappersFolders([]string{"./contracts/bind"}).
// nonce manager
WithNonceManager(10, 3, 60, 5).
Build()
Expand Down
Loading

0 comments on commit d08c022

Please sign in to comment.