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
write/read
  • Loading branch information
Pablo La Greca committed Oct 3, 2024
1 parent 815b2c8 commit 31d3443
Show file tree
Hide file tree
Showing 9 changed files with 1,169 additions and 279 deletions.
102 changes: 102 additions & 0 deletions core/services/relay/evm/bindings/chain_config_factory.go

Large diffs are not rendered by default.

186 changes: 186 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.

7 changes: 4 additions & 3 deletions core/services/relay/evm/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"fmt"
commontestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils"
"math"
"math/big"
"os"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/stretchr/testify/require"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
commontestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils"
clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"

Expand Down Expand Up @@ -149,15 +149,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 31d3443

Please sign in to comment.