diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 19be4b670b3..43b8408d2ee 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -217,14 +217,14 @@ func NewRelayer(ctx context.Context, lggr logger.Logger, chain legacyevm.Chain, capabilitiesRegistry: opts.CapabilitiesRegistry, } + wCfg := chain.Config().EVM().Workflow() // Initialize write target capability if configuration is defined - if chain.Config().EVM().Workflow().ForwarderAddress() != nil { - if chain.Config().EVM().Workflow().GasLimitDefault() == nil { + if wCfg.ForwarderAddress() != nil && wCfg.FromAddress() != nil { + if wCfg.GasLimitDefault() == nil { return nil, fmt.Errorf("unable to instantiate write target as default gas limit is not set") } - capability, err := NewWriteTarget(ctx, relayer, chain, *chain.Config().EVM().Workflow().GasLimitDefault(), - lggr) + capability, err := NewWriteTarget(ctx, relayer, chain, *wCfg.GasLimitDefault(), lggr) if err != nil { return nil, fmt.Errorf("failed to initialize write target: %w", err) } diff --git a/core/services/relay/evm/write_target_test.go b/core/services/relay/evm/write_target_test.go index 245fd974783..ce169554768 100644 --- a/core/services/relay/evm/write_target_test.go +++ b/core/services/relay/evm/write_target_test.go @@ -9,16 +9,16 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "github.com/smartcontractkit/chainlink-common/pkg/capabilities" "github.com/smartcontractkit/chainlink-common/pkg/values" - "github.com/smartcontractkit/chainlink/v2/common/headtracker/mocks" - "github.com/smartcontractkit/chainlink/v2/core/capabilities/targets" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" - "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" - "github.com/smartcontractkit/chainlink-common/pkg/capabilities" + "github.com/smartcontractkit/chainlink/v2/common/headtracker/mocks" evmcapabilities "github.com/smartcontractkit/chainlink/v2/core/capabilities" + "github.com/smartcontractkit/chainlink/v2/core/capabilities/targets" evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" gasmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks" pollermocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks" @@ -26,17 +26,16 @@ import ( txmmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" evmmocks "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm/mocks" - relayevm "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" - - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/forwarder" + "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" + "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" + "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" + relayevm "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" ) var forwardABI = types.MustGetABI(forwarder.KeystoneForwarderMetaData.ABI) @@ -142,12 +141,16 @@ func TestEvmWrite(t *testing.T) { keyStore := cltest.NewKeyStore(t, db) lggr := logger.TestLogger(t) + cRegistry := evmcapabilities.NewRegistry(lggr) relayer, err := relayevm.NewRelayer(testutils.Context(t), lggr, chain, relayevm.RelayerOpts{ DS: db, CSAETHKeystore: keyStore, - CapabilitiesRegistry: evmcapabilities.NewRegistry(lggr), + CapabilitiesRegistry: cRegistry, }) require.NoError(t, err) + registeredCapabilities, err := cRegistry.List(testutils.Context(t)) + require.NoError(t, err) + require.Len(t, registeredCapabilities, 1) // WriteTarget should be added to the registry reportID := [2]byte{0x00, 0x01} reportMetadata := targets.ReportV1Metadata{ @@ -252,4 +255,31 @@ func TestEvmWrite(t *testing.T) { _, err = capability.Execute(ctx, req) require.Error(t, err) }) + + t.Run("Relayer fails to start WriteTarget capability on missing config", func(t *testing.T) { + ctx := testutils.Context(t) + testChain := evmmocks.NewChain(t) + testCfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { + c.EVM[0].Workflow.FromAddress = nil + + forwarderA := testutils.NewAddress() + forwarderAddr, err2 := types.NewEIP55Address(forwarderA.Hex()) + require.NoError(t, err2) + c.EVM[0].Workflow.ForwarderAddress = &forwarderAddr + }) + testChain.On("Config").Return(evmtest.NewChainScopedConfig(t, testCfg)) + capabilityRegistry := evmcapabilities.NewRegistry(lggr) + + _, err := relayevm.NewRelayer(ctx, lggr, testChain, relayevm.RelayerOpts{ + DS: db, + CSAETHKeystore: keyStore, + CapabilitiesRegistry: capabilityRegistry, + }) + require.NoError(t, err) + + l, err := capabilityRegistry.List(ctx) + require.NoError(t, err) + + assert.Empty(t, l) + }) }