Skip to content

Commit

Permalink
Generate abi, bin & wrapper for chainreader test with gethwrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Dec 23, 2023
1 parent 0d8d3b7 commit 51f06a6
Show file tree
Hide file tree
Showing 11 changed files with 549 additions and 597 deletions.
2 changes: 1 addition & 1 deletion contracts/scripts/native_solc_compile_all
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ python3 -m pip install --require-hashes -r $SCRIPTPATH/requirements.txt
# 6 and 7 are legacy contracts, for each other product we have a native_solc_compile_all_$product script
# These scripts can be run individually, or all together with this script.
# To add new CL products, simply write a native_solc_compile_all_$product script and add it to the list below.
for product in 6 7 automation events_mock feeds functions llo-feeds logpoller operatorforwarder shared transmission vrf
for product in 6 7 automation events_mock feeds functions llo-feeds logpoller operatorforwarder shared transmission vrf chainreader
do
$SCRIPTPATH/native_solc_compile_all_$product
done
32 changes: 32 additions & 0 deletions contracts/scripts/native_solc_compile_all_chainreader
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e

echo " ┌──────────────────────────────────────────────┐"
echo " │ Compiling ChainReader contracts... │"
echo " └──────────────────────────────────────────────┘"

SOLC_VERSION="0.8.19"
OPTIMIZE_RUNS=1000000


SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
python3 -m pip install --require-hashes -r "$SCRIPTPATH"/requirements.txt
solc-select install $SOLC_VERSION
solc-select use $SOLC_VERSION
export SOLC_VERSION=$SOLC_VERSION

ROOT="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; cd ../../ && pwd -P )"

compileContract () {
local contract
contract=$(basename "$1" ".sol")

solc --overwrite --optimize --optimize-runs $OPTIMIZE_RUNS --metadata-hash none \
-o "$ROOT"/contracts/solc/v$SOLC_VERSION/"$contract" \
--abi --bin --allow-paths "$ROOT"/contracts/src/v0.8\
"$ROOT"/contracts/src/v0.8/"$1"
}


compileContract tests/ChainReaderTestContract.sol

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion core/gethwrappers/go_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ package gethwrappers
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/MockAggregatorProxy/MockAggregatorProxy.abi ../../contracts/solc/v0.8.6/MockAggregatorProxy/MockAggregatorProxy.bin MockAggregatorProxy mock_aggregator_proxy

// Log tester
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.abi ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.bin LogEmitter log_emitter

// ChainReader test contract
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.19/ChainReaderTestContract/LatestValueHolder.abi ../../contracts/solc/v0.8.19/ChainReaderTestContract/LatestValueHolder.bin LatestValueHolder chain_reader_example

// Chainlink Functions
//go:generate go generate ./functions
Expand Down
30 changes: 14 additions & 16 deletions core/services/relay/evm/chain_reader_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package evm_test

//go:generate ./testfiles/chainlink_reader_test_setup.sh

import (
"crypto/ecdsa"
"math"
Expand All @@ -27,11 +25,11 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm/mocks"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/chain_reader_example"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/testfiles"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
)

Expand All @@ -49,7 +47,7 @@ type chainReaderInterfaceTester struct {
auth *bind.TransactOpts
sim *backends.SimulatedBackend
pk *ecdsa.PrivateKey
evmTest *testfiles.Testfiles
evmTest *chain_reader_example.LatestValueHolder
cr evm.ChainReaderService
}

Expand All @@ -75,7 +73,7 @@ func (it *chainReaderInterfaceTester) Setup(t *testing.T) {
it.chainConfig = types.ChainReaderConfig{
ChainContractReaders: map[string]types.ChainContractReader{
AnyContractName: {
ContractABI: testfiles.TestfilesMetaData.ABI,
ContractABI: chain_reader_example.LatestValueHolderMetaData.ABI,
ChainReaderDefinitions: map[string]types.ChainReaderDefinition{
MethodTakingLatestParamsReturningTestStruct: {
ChainSpecificName: "GetElementAtIndex",
Expand Down Expand Up @@ -111,7 +109,7 @@ func (it *chainReaderInterfaceTester) Setup(t *testing.T) {
},
},
AnySecondContractName: {
ContractABI: testfiles.TestfilesMetaData.ABI,
ContractABI: chain_reader_example.LatestValueHolderMetaData.ABI,
ChainReaderDefinitions: map[string]types.ChainReaderDefinition{
MethodReturningUint64: {
ChainSpecificName: "GetDifferentPrimitiveValue",
Expand Down Expand Up @@ -154,11 +152,11 @@ func (it *chainReaderInterfaceTester) GetChainReader(t *testing.T) clcommontypes
}

func (it *chainReaderInterfaceTester) SetLatestValue(t *testing.T, testStruct *TestStruct) {
it.sendTxWithTestStruct(t, testStruct, (*testfiles.TestfilesTransactor).AddTestStruct)
it.sendTxWithTestStruct(t, testStruct, (*chain_reader_example.LatestValueHolderTransactor).AddTestStruct)
}

func (it *chainReaderInterfaceTester) TriggerEvent(t *testing.T, testStruct *TestStruct) {
it.sendTxWithTestStruct(t, testStruct, (*testfiles.TestfilesTransactor).TriggerEvent)
it.sendTxWithTestStruct(t, testStruct, (*chain_reader_example.LatestValueHolderTransactor).TriggerEvent)
}

func (it *chainReaderInterfaceTester) GetBindings(t *testing.T) []clcommontypes.BoundContract {
Expand All @@ -168,11 +166,11 @@ func (it *chainReaderInterfaceTester) GetBindings(t *testing.T) []clcommontypes.
}
}

type testStructFn = func(*testfiles.TestfilesTransactor, *bind.TransactOpts, int32, string, uint8, [32]uint8, common.Address, []common.Address, *big.Int, testfiles.MidLevelTestStruct) (*evmtypes.Transaction, error)
type testStructFn = func(*chain_reader_example.LatestValueHolderTransactor, *bind.TransactOpts, int32, string, uint8, [32]uint8, common.Address, []common.Address, *big.Int, chain_reader_example.MidLevelTestStruct) (*evmtypes.Transaction, error)

func (it *chainReaderInterfaceTester) sendTxWithTestStruct(t *testing.T, testStruct *TestStruct, fn testStructFn) {
tx, err := fn(
&it.evmTest.TestfilesTransactor,
&it.evmTest.LatestValueHolderTransactor,
it.auth,
testStruct.Field,
testStruct.DifferentField,
Expand Down Expand Up @@ -232,7 +230,7 @@ func (it *chainReaderInterfaceTester) deployNewContract(t *testing.T) string {
// Not sure if there's a better way to get it.
it.auth.GasLimit = 10552800

address, tx, ts, err := testfiles.DeployTestfiles(it.auth, it.sim)
address, tx, ts, err := chain_reader_example.DeployLatestValueHolder(it.auth, it.sim)

require.NoError(t, err)
it.sim.Commit()
Expand Down Expand Up @@ -288,8 +286,8 @@ func getOracleIDs(first TestStruct) [32]byte {
return oracleIDs
}

func toInternalType(testStruct TestStruct) testfiles.TestStruct {
return testfiles.TestStruct{
func toInternalType(testStruct TestStruct) chain_reader_example.TestStruct {
return chain_reader_example.TestStruct{
Field: testStruct.Field,
DifferentField: testStruct.DifferentField,
OracleId: byte(testStruct.OracleID),
Expand All @@ -301,10 +299,10 @@ func toInternalType(testStruct TestStruct) testfiles.TestStruct {
}
}

func midToInternalType(m MidLevelTestStruct) testfiles.MidLevelTestStruct {
return testfiles.MidLevelTestStruct{
func midToInternalType(m MidLevelTestStruct) chain_reader_example.MidLevelTestStruct {
return chain_reader_example.MidLevelTestStruct{
FixedBytes: m.FixedBytes,
Inner: testfiles.InnerTestStruct{
Inner: chain_reader_example.InnerTestStruct{
I: int64(m.Inner.I),
S: m.Inner.S,
},
Expand Down
8 changes: 4 additions & 4 deletions core/services/relay/evm/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
. "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with .

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/chain_reader_example"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/testfiles"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
)

Expand Down Expand Up @@ -109,11 +109,11 @@ func encodeFieldsOnSliceOrArray(t *testing.T, request *EncodeRequest) []byte {

switch request.TestOn {
case TestItemArray1Type:
args[0] = [1]testfiles.TestStruct{toInternalType(request.TestStructs[0])}
args[0] = [1]chain_reader_example.TestStruct{toInternalType(request.TestStructs[0])}
case TestItemArray2Type:
args[0] = [2]testfiles.TestStruct{toInternalType(request.TestStructs[0]), toInternalType(request.TestStructs[1])}
args[0] = [2]chain_reader_example.TestStruct{toInternalType(request.TestStructs[0]), toInternalType(request.TestStructs[1])}
default:
tmp := make([]testfiles.TestStruct, len(request.TestStructs))
tmp := make([]chain_reader_example.TestStruct, len(request.TestStructs))
for i, ts := range request.TestStructs {
tmp[i] = toInternalType(ts)
}
Expand Down

This file was deleted.

Loading

0 comments on commit 51f06a6

Please sign in to comment.