Skip to content

Commit

Permalink
BCFR-967 - EVM Chain bindings for CR/CW - Basic support for method
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo La Greca authored and pablolagreca committed Oct 30, 2024
1 parent 235c85c commit 58f153e
Show file tree
Hide file tree
Showing 17 changed files with 1,232 additions and 293 deletions.
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-automation v0.8.1
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241025132045-cfad02139595
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241030174834-c2c9a94ab04f

Check failure on line 27 in core/scripts/go.mod

View workflow job for this annotation

GitHub Actions / Validate go.mod dependencies

[./core/scripts/go.mod] dependency github.com/smartcontractkit/chainlink-common@v0.3.1-0.20241030174834-c2c9a94ab04f not on default branch (main). Version(commit): c2c9a94ab04f Tree: https://github.com/smartcontractkit/chainlink-common/tree/c2c9a94ab04f Commit: https://github.com/smartcontractkit/chainlink-common/commit/c2c9a94ab04f
github.com/smartcontractkit/chainlink/deployment v0.0.0-00010101000000-000000000000
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,8 @@ github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgB
github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241029124258-09d605658a80 h1:BdqTkM2KObIaD2vevGM5MVJz+3pZl3wNF8h68Gh5iys=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241029124258-09d605658a80/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241025132045-cfad02139595 h1:H6i0LEvXB0se/63E3jE9N0/7TugOYLpK4e6TT6a0omc=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241025132045-cfad02139595/go.mod h1:TQ9/KKXZ9vr8QAlUquqGpSvDCpR+DtABKPXZY4CiRns=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241030174834-c2c9a94ab04f h1:xzEYM1e6Jvu2IHLkVgJeKNmxvz0R+CHQwrRM/lqmMRM=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241030174834-c2c9a94ab04f/go.mod h1:TQ9/KKXZ9vr8QAlUquqGpSvDCpR+DtABKPXZY4CiRns=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f h1:BwrIaQIx5Iy6eT+DfLhFfK2XqjxRm74mVdlX8gbu4dw=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f/go.mod h1:wHtwSR3F1CQSJJZDQKuqaqFYnvkT+kMyget7dl8Clvo=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241018134907-a00ba3729b5e h1:JiETqdNM0bktAUGMc62COwXIaw3rR3M77Me6bBLG0Fg=
Expand Down
107 changes: 107 additions & 0 deletions core/services/relay/evm/bindings/chain_config_factory.go

Large diffs are not rendered by default.

201 changes: 201 additions & 0 deletions core/services/relay/evm/bindings/chain_reader_tester.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions core/services/relay/evm/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@ func TestContractReaderEventsInitValidation(t *testing.T) {
}
}

//go:generate evm-chain-bindings -contracts contracts/src/v0.8/shared/test/helpers -output core/services/relay/evm/bindings
func TestChainComponents(t *testing.T) {
t.Parallel()
it := &EVMChainComponentsInterfaceTester[*testing.T]{Helper: &helper{}}

it.Helper.Init(t)
it.Init(t)

// add new subtests here so that it can be run on real chains too
RunChainComponentsEvmTests(t, it)
RunChainComponentsInLoopEvmTests[*testing.T](t, commontestutils.WrapContractReaderTesterForLoop(it))
RunChainComponentsInLoopEvmTests(t, WrapContractReaderTesterWithBindings(t, it))
}

type helper struct {
Expand Down
21 changes: 19 additions & 2 deletions core/services/relay/evm/chain_writer_historical_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evm

import (
"context"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/bindings"
"math/big"

commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
Expand All @@ -22,18 +23,34 @@ func NewChainWriterHistoricalWrapper(cw commontypes.ChainWriter, cwh *ClientWith
}

func (cwhw *ChainWriterHistoricalWrapper) SubmitTransaction(ctx context.Context, contractName, method string, args any, transactionID string, toAddress string, meta *commontypes.TxMeta, value *big.Int) error {
if primArgs, ok := args.(interfacetesttypes.PrimitiveArgs); ok {
alterablePrimitiveCall, newValue := cwhw.getPrimitiveValueIfPossible(args)
if alterablePrimitiveCall {
callArgs := interfacetesttypes.ExpectedGetLatestValueArgs{
ContractName: contractName,
ReadName: "GetAlterablePrimitiveValue",
ConfidenceLevel: primitives.Unconfirmed,
Params: nil,
ReturnVal: nil,
}
err := cwhw.cwh.SetUintLatestValue(ctx, primArgs.Value, callArgs)
err := cwhw.cwh.SetUintLatestValue(ctx, newValue, callArgs)
if err != nil {
return err
}
}
return cwhw.ChainWriter.SubmitTransaction(ctx, contractName, method, args, transactionID, toAddress, meta, value)
}

func (cwhw *ChainWriterHistoricalWrapper) getPrimitiveValueIfPossible(args any) (bool, uint64) {
primitiveArgs, alterablePrimitiveCall := args.(interfacetesttypes.PrimitiveArgs)
var newValue uint64
var alterablePrimitiveValue bindings.SetAlterablePrimitiveValueInput
if alterablePrimitiveCall {
newValue = primitiveArgs.Value
} else {
alterablePrimitiveValue, alterablePrimitiveCall = args.(bindings.SetAlterablePrimitiveValueInput)
if alterablePrimitiveCall {
newValue = alterablePrimitiveValue.Value
}
}
return alterablePrimitiveCall, newValue
}
Loading

0 comments on commit 58f153e

Please sign in to comment.