Skip to content

Commit 623f48b

Browse files
authored
[CRE-491] Move self-contained folders to chainlink-evm (#265)
1 parent 185ce85 commit 623f48b

26 files changed

+4162
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.24.7
77
require (
88
github.com/ethereum/go-ethereum v1.16.2
99
github.com/fxamacker/cbor/v2 v2.7.0
10+
github.com/go-viper/mapstructure/v2 v2.4.0
1011
github.com/google/uuid v1.6.0
1112
github.com/gorilla/websocket v1.5.3
1213
github.com/jackc/pgconn v1.14.3
@@ -92,7 +93,6 @@ require (
9293
github.com/go-playground/locales v0.14.1 // indirect
9394
github.com/go-playground/universal-translator v0.18.1 // indirect
9495
github.com/go-playground/validator/v10 v10.26.0 // indirect
95-
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
9696
github.com/goccy/go-json v0.10.5 // indirect
9797
github.com/gofrs/flock v0.12.1 // indirect
9898
github.com/gogo/protobuf v1.3.2 // indirect

pkg/.mockery.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ dir: "{{ .InterfaceDir }}/mocks"
22
mockname: "{{ .InterfaceName }}"
33
outpkg: mocks
44
filename: "{{ .InterfaceName | snakecase }}.go"
5+
fail-on-missing: true
56
packages:
67
github.com/smartcontractkit/chainlink-framework/chains/heads:
78
config:
@@ -25,7 +26,6 @@ packages:
2526
Workflow:
2627
github.com/smartcontractkit/chainlink-evm/pkg/gas:
2728
interfaces:
28-
Config:
2929
EvmFeeEstimator:
3030
feeEstimatorClient:
3131
config:
@@ -43,10 +43,6 @@ packages:
4343
github.com/smartcontractkit/chainlink-evm/pkg/monitor:
4444
interfaces:
4545
BalanceMonitor:
46-
47-
github.com/smartcontractkit/chainlink-evm/pkg/writetarget:
48-
interfaces:
49-
ProductSpecificProcessor:
5046
github.com/smartcontractkit/chainlink-framework/multinode:
5147
config:
5248
dir: client/clienttest
@@ -63,6 +59,11 @@ packages:
6359
Client:
6460
TxStore:
6561
AttemptBuilder:
62+
github.com/smartcontractkit/chainlink-framework/chains/txmgr:
63+
config:
64+
dir: txmgr/mocks
65+
interfaces:
66+
TxManager:
6667
github.com/smartcontractkit/chainlink-framework/chains/txmgr/types:
6768
config:
6869
dir: txmgr/mocks
@@ -85,4 +86,3 @@ packages:
8586
filename: "mock_{{ .InterfaceName | snakecase }}_test.go"
8687
interfaces:
8788
Emitter:
88-

pkg/bindings/chain_config_factory.go

Lines changed: 108 additions & 0 deletions
Large diffs are not rendered by default.

pkg/bindings/chain_reader_tester.go

Lines changed: 202 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codec/byte_string_modifier.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package codec
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/ethereum/go-ethereum/common"
8+
9+
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
10+
)
11+
12+
// EVMAddressModifier implements the AddressModifier interface for Ethereum addresses.
13+
// It handles encoding and decoding Ethereum addresses with EIP-55 checksums and hex encoding.
14+
type EVMAddressModifier struct{}
15+
16+
func (e EVMAddressModifier) EncodeAddress(bytes []byte) (string, error) {
17+
if len(bytes) != e.Length() {
18+
return "", fmt.Errorf("%w: got length %d, expected 20 for bytes %x", commontypes.ErrInvalidType, len(bytes), bytes)
19+
}
20+
21+
return common.BytesToAddress(bytes).Hex(), nil
22+
}
23+
24+
// DecodeAddress takes an EIP-55 encoded Ethereum address (e.g., "0x...") and decodes it to a 20-byte array.
25+
func (e EVMAddressModifier) DecodeAddress(str string) ([]byte, error) {
26+
str = strings.TrimPrefix(str, "0x")
27+
if len(str) != 40 {
28+
return nil, fmt.Errorf("%w: got length %d, expected 40 for address %s", commontypes.ErrInvalidType, len(str), str)
29+
}
30+
31+
address := common.HexToAddress(str)
32+
if address == (common.Address{}) {
33+
return nil, fmt.Errorf("%w: address is zero", commontypes.ErrInvalidType)
34+
}
35+
36+
return address.Bytes(), nil
37+
}
38+
39+
// Length returns the expected length of an Ethereum address in bytes (20 bytes).
40+
func (e EVMAddressModifier) Length() int {
41+
return common.AddressLength
42+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package codec_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
10+
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
11+
"github.com/smartcontractkit/chainlink-evm/pkg/codec"
12+
)
13+
14+
func TestEVMAddressModifier(t *testing.T) {
15+
modifier := codec.EVMAddressModifier{}
16+
validAddressStr := "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4"
17+
validAddressBytes := common.HexToAddress(validAddressStr).Bytes()
18+
invalidLengthAddressStr := "0xabcdef1234567890abcdef"
19+
20+
t.Run("EncodeAddress encodes valid Ethereum address bytes", func(t *testing.T) {
21+
encoded, err := modifier.EncodeAddress(validAddressBytes)
22+
require.NoError(t, err)
23+
assert.Equal(t, validAddressStr, encoded)
24+
})
25+
26+
t.Run("EncodeAddress returns error for invalid byte length", func(t *testing.T) {
27+
invalidBytes := []byte(invalidLengthAddressStr)
28+
_, err := modifier.EncodeAddress(invalidBytes)
29+
require.Error(t, err)
30+
assert.Contains(t, err.Error(), commontypes.ErrInvalidType)
31+
})
32+
33+
t.Run("DecodeAddress decodes valid Ethereum address", func(t *testing.T) {
34+
decodedBytes, err := modifier.DecodeAddress(validAddressStr)
35+
require.NoError(t, err)
36+
assert.Equal(t, validAddressBytes, decodedBytes)
37+
})
38+
39+
t.Run("DecodeAddress returns error for invalid address length", func(t *testing.T) {
40+
_, err := modifier.DecodeAddress(invalidLengthAddressStr)
41+
require.Error(t, err)
42+
assert.Contains(t, err.Error(), commontypes.ErrInvalidType)
43+
})
44+
45+
t.Run("DecodeAddress returns error for zero-value address", func(t *testing.T) {
46+
_, err := modifier.DecodeAddress(common.Address{}.Hex())
47+
require.Error(t, err)
48+
assert.Contains(t, err.Error(), commontypes.ErrInvalidType)
49+
})
50+
51+
t.Run("Length returns 20 for Ethereum addresses", func(t *testing.T) {
52+
assert.Equal(t, common.AddressLength, modifier.Length())
53+
})
54+
}

0 commit comments

Comments
 (0)