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 Nov 11, 2024
1 parent 422e385 commit 1b60d1e
Show file tree
Hide file tree
Showing 7 changed files with 1,221 additions and 298 deletions.
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 1b60d1e

Please sign in to comment.