From 9340608ce05a106f5275ff7ff47856188d172c31 Mon Sep 17 00:00:00 2001 From: Pablo La Greca Date: Wed, 6 Nov 2024 17:30:15 -0300 Subject: [PATCH] fixing linting errors --- .../evm/bindings/chain_config_factory.go | 1 + .../chain_writer_historical_wrapper_test.go | 5 +- core/services/relay/evm/codec/codec_test.go | 4 +- .../evm/evmtesting/bindings_test_adapter.go | 47 ++++++++++--------- .../relay/evm/evmtesting/run_tests.go | 16 +++---- 5 files changed, 40 insertions(+), 33 deletions(-) diff --git a/core/services/relay/evm/bindings/chain_config_factory.go b/core/services/relay/evm/bindings/chain_config_factory.go index 8bd30cf9d5b..4dfaffe80dc 100644 --- a/core/services/relay/evm/bindings/chain_config_factory.go +++ b/core/services/relay/evm/bindings/chain_config_factory.go @@ -2,6 +2,7 @@ package bindings import ( "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" ) diff --git a/core/services/relay/evm/chain_writer_historical_wrapper_test.go b/core/services/relay/evm/chain_writer_historical_wrapper_test.go index 669ec9e7953..233d7bc2e2f 100644 --- a/core/services/relay/evm/chain_writer_historical_wrapper_test.go +++ b/core/services/relay/evm/chain_writer_historical_wrapper_test.go @@ -2,12 +2,13 @@ package evm import ( "context" - "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/bindings" + "math/big" commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" interfacetesttypes "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" - primitives "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" + "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" + "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/bindings" ) // This wrapper is required to enable the ChainReader to access historical data diff --git a/core/services/relay/evm/codec/codec_test.go b/core/services/relay/evm/codec/codec_test.go index d63ed5342c4..2da88abaac1 100644 --- a/core/services/relay/evm/codec/codec_test.go +++ b/core/services/relay/evm/codec/codec_test.go @@ -172,7 +172,9 @@ func TestCodec_EncodeTupleWithLists(t *testing.T) { require.Equal(t, expected, hexutil.Encode(result)[2:]) } -type codecInterfaceTester struct{} +type codecInterfaceTester struct { + TestSelectionSupport +} func (it *codecInterfaceTester) Setup(_ *testing.T) {} diff --git a/core/services/relay/evm/evmtesting/bindings_test_adapter.go b/core/services/relay/evm/evmtesting/bindings_test_adapter.go index 812f1bd9989..5dc7259b7cf 100644 --- a/core/services/relay/evm/evmtesting/bindings_test_adapter.go +++ b/core/services/relay/evm/evmtesting/bindings_test_adapter.go @@ -4,8 +4,14 @@ import ( "context" "errors" "fmt" + "math/big" + "reflect" + "strings" + "testing" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/go-viper/mapstructure/v2" + "github.com/smartcontractkit/chainlink-common/pkg/codec" commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" @@ -14,10 +20,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/bindings" evmcodec "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/codec" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" - "math/big" - "reflect" - "strings" - "testing" ) const contractName = "ChainReaderTester" @@ -25,7 +27,7 @@ const contractName = "ChainReaderTester" // Wraps EVMChainComponentsInterfaceTester to rely on the EVM bindings generated for CR/CW instead of going directly to CR/CW. This way we can reuse all existing tests. Transformation between expected // contract names and read keys will be done here as well as invocation delegation to generated code. func WrapContractReaderTesterWithBindings(t *testing.T, wrapped *EVMChainComponentsInterfaceTester[*testing.T]) interfacetests.ChainComponentsInterfaceTester[*testing.T] { - //Tests not yet supported by EVM bindings. + // Tests not yet supported by EVM bindings. wrapped.DisableTests([]string{ interfacetests.ContractReaderGetLatestValueAsValuesDotValue, interfacetests.ContractReaderGetLatestValueNoArgumentsAndPrimitiveReturnAsValuesDotValue, interfacetests.ContractReaderGetLatestValueNoArgumentsAndSliceReturnAsValueDotValue, interfacetests.ContractReaderGetLatestValueGetsLatestForEvent, interfacetests.ContractReaderGetLatestValueBasedOnConfidenceLevelForEvent, @@ -72,7 +74,7 @@ func newBindingsMapping() bindingsMapping { interfacetests.MethodReturningUint64: "GetDifferentPrimitiveValue", } - bindingsMapping := bindingsMapping{ + bm := bindingsMapping{ contractNameMapping: map[string]string{ interfacetests.AnyContractName: contractName, interfacetests.AnySecondContractName: contractName, @@ -82,10 +84,10 @@ func newBindingsMapping() bindingsMapping { chainWriterProxy: &chainWriterProxy, chainReaderTesters: map[string]*bindings.ChainReaderTester{}, } - contractReaderProxy.bm = &bindingsMapping - chainWriterProxy.bm = &bindingsMapping - bindingsMapping.createDelegates() - return bindingsMapping + contractReaderProxy.bm = &bm + chainWriterProxy.bm = &bm + bm.createDelegates() + return bm } func getChainReaderConfig(wrapped *EVMChainComponentsInterfaceTester[*testing.T]) types.ChainReaderConfig { @@ -195,11 +197,11 @@ func (b bindingContractReaderProxy) Bind(ctx context.Context, boundContracts []c } func (b bindingsMapping) translateContractNames(boundContracts []commontypes.BoundContract) []commontypes.BoundContract { - updatedBindings := []commontypes.BoundContract{} + var updatedBindings []commontypes.BoundContract for _, boundContract := range boundContracts { updatedBindings = append(updatedBindings, commontypes.BoundContract{ - boundContract.Address, - b.translateContractName(boundContract.Name), + Address: boundContract.Address, + Name: b.translateContractName(boundContract.Name), }) } return updatedBindings @@ -235,15 +237,15 @@ func (b bindingChainWriterProxy) SubmitTransaction(ctx context.Context, contract switch method { case interfacetests.MethodSettingStruct: bindingsInput := bindings.AddTestStructInput{} - convertStruct(args, &bindingsInput) + _ = convertStruct(args, &bindingsInput) return chainReaderTesters.AddTestStruct(ctx, bindingsInput, transactionID, toAddress, meta) case interfacetests.MethodSettingUint64: bindingsInput := bindings.SetAlterablePrimitiveValueInput{} - convertStruct(args, &bindingsInput) + _ = convertStruct(args, &bindingsInput) return chainReaderTesters.SetAlterablePrimitiveValue(ctx, bindingsInput, transactionID, toAddress, meta) case interfacetests.MethodTriggeringEvent: bindingsInput := bindings.TriggerEventInput{} - convertStruct(args, &bindingsInput) + _ = convertStruct(args, &bindingsInput) return chainReaderTesters.TriggerEvent(ctx, bindingsInput, transactionID, toAddress, meta) default: return errors.New("No logic implemented for method: " + method) @@ -435,7 +437,7 @@ func (d Delegate) apply(ctx context.Context, readKey string, input any, confiden // Utility function to converted original types from and to bindings expected types. func convertStruct(src any, dst any) error { if reflect.TypeOf(src).Kind() == reflect.Ptr && reflect.TypeOf(dst).Kind() == reflect.Ptr && reflect.TypeOf(src).Elem() == reflect.TypeOf(interfacetests.LatestParams{}) && reflect.TypeOf(dst).Elem() == reflect.TypeOf(bindings.GetElementAtIndexInput{}) { - value := (*src.(*interfacetests.LatestParams)).I + value := src.(*interfacetests.LatestParams).I dst.(*bindings.GetElementAtIndexInput).I = big.NewInt(int64(value)) return nil } @@ -447,12 +449,13 @@ func convertStruct(src any, dst any) error { if err != nil { return err } - if reflect.TypeOf(dst).Elem() == reflect.TypeOf(interfacetests.TestStructWithExtraField{}) { + switch { + case reflect.TypeOf(dst).Elem() == reflect.TypeOf(interfacetests.TestStructWithExtraField{}): destTestStruct := dst.(*interfacetests.TestStructWithExtraField) if destTestStruct != nil { auxTestStruct := &interfacetests.TestStruct{} decoder, _ := createDecoder(auxTestStruct) - decoder.Decode(src) + _ = decoder.Decode(src) destTestStruct.TestStruct = *auxTestStruct sourceTestStruct := src.(bindings.TestStruct) destTestStruct.BigField = sourceTestStruct.BigField @@ -462,7 +465,7 @@ func convertStruct(src any, dst any) error { destTestStruct.NestedDynamicStruct.FixedBytes = sourceTestStruct.NestedDynamicStruct.FixedBytes destTestStruct.ExtraField = interfacetests.AnyExtraValue } - } else if reflect.TypeOf(dst).Elem() == reflect.TypeOf(interfacetests.TestStruct{}) { + case reflect.TypeOf(dst).Elem() == reflect.TypeOf(interfacetests.TestStruct{}): destTestStruct := dst.(*interfacetests.TestStruct) if destTestStruct != nil { sourceTestStruct := src.(bindings.TestStruct) @@ -472,7 +475,7 @@ func convertStruct(src any, dst any) error { destTestStruct.NestedDynamicStruct.Inner.I = int(sourceTestStruct.NestedDynamicStruct.Inner.IntVal) destTestStruct.NestedDynamicStruct.FixedBytes = sourceTestStruct.NestedDynamicStruct.FixedBytes } - } else if reflect.TypeOf(src) == reflect.TypeOf(interfacetests.TestStruct{}) && reflect.TypeOf(dst) == reflect.TypeOf(&bindings.AddTestStructInput{}) { + case reflect.TypeOf(src) == reflect.TypeOf(interfacetests.TestStruct{}) && reflect.TypeOf(dst) == reflect.TypeOf(&bindings.AddTestStructInput{}): destTestStruct := dst.(*bindings.AddTestStructInput) if destTestStruct != nil { sourceTestStruct := src.(interfacetests.TestStruct) @@ -482,7 +485,7 @@ func convertStruct(src any, dst any) error { destTestStruct.NestedDynamicStruct.Inner.IntVal = int64(sourceTestStruct.NestedDynamicStruct.Inner.I) destTestStruct.NestedDynamicStruct.FixedBytes = sourceTestStruct.NestedDynamicStruct.FixedBytes } - } else if reflect.TypeOf(src) == reflect.TypeOf(interfacetests.TestStruct{}) && reflect.TypeOf(dst) == reflect.TypeOf(&bindings.ReturnSeenInput{}) { + case reflect.TypeOf(src) == reflect.TypeOf(interfacetests.TestStruct{}) && reflect.TypeOf(dst) == reflect.TypeOf(&bindings.ReturnSeenInput{}): destTestStruct := dst.(*bindings.ReturnSeenInput) if destTestStruct != nil { sourceTestStruct := src.(interfacetests.TestStruct) diff --git a/core/services/relay/evm/evmtesting/run_tests.go b/core/services/relay/evm/evmtesting/run_tests.go index 43882ef93ac..5f3cdbb2fd7 100644 --- a/core/services/relay/evm/evmtesting/run_tests.go +++ b/core/services/relay/evm/evmtesting/run_tests.go @@ -295,14 +295,14 @@ func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfac copy(val5[:], append(empty12Bytes[:], 5)) raw := []byte{9, 8} - var buf []byte - buf = binary.BigEndian.AppendUint32(buf, val1) - buf = binary.BigEndian.AppendUint32(buf, val2) - buf = binary.BigEndian.AppendUint32(buf, val3) - buf = binary.BigEndian.AppendUint64(buf, val4) - dataWordOnChainValueToQuery := buf[:] - - resExpected := append(buf, common.LeftPadBytes(val5[:], 32)...) + var resExpected []byte + resExpected = binary.BigEndian.AppendUint32(resExpected, val1) + resExpected = binary.BigEndian.AppendUint32(resExpected, val2) + resExpected = binary.BigEndian.AppendUint32(resExpected, val3) + resExpected = binary.BigEndian.AppendUint64(resExpected, val4) + dataWordOnChainValueToQuery := resExpected + + resExpected = append(resExpected, common.LeftPadBytes(val5[:], 32)...) resExpected = append(resExpected, common.LeftPadBytes(val6[:], 32)...) resExpected = append(resExpected, common.LeftPadBytes(val7[:], 32)...) resExpected = append(resExpected, raw...)