From b58b76ecdc8c68a3235d313c986eab736ffb9dcb Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 15 Oct 2024 08:04:12 -0500 Subject: [PATCH] pkg/chainlink: add Context to TxManager.Enqueue (#544) --- relayer/pkg/chainlink/ocr2/contract_transmitter.go | 2 +- relayer/pkg/chainlink/txm/txm.go | 6 +++--- relayer/pkg/chainlink/txm/txm_test.go | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/relayer/pkg/chainlink/ocr2/contract_transmitter.go b/relayer/pkg/chainlink/ocr2/contract_transmitter.go index 89cfd4bad..ef2b61c7b 100644 --- a/relayer/pkg/chainlink/ocr2/contract_transmitter.go +++ b/relayer/pkg/chainlink/ocr2/contract_transmitter.go @@ -95,7 +95,7 @@ func (c *contractTransmitter) Transmit( return err } - err = c.txm.Enqueue(c.accountAddress, c.senderAddress, starknetrpc.FunctionCall{ + err = c.txm.Enqueue(ctx, c.accountAddress, c.senderAddress, starknetrpc.FunctionCall{ ContractAddress: c.contractAddress, EntryPointSelector: starknetutils.GetSelectorFromNameFelt("transmit"), Calldata: calldata, diff --git a/relayer/pkg/chainlink/txm/txm.go b/relayer/pkg/chainlink/txm/txm.go index 2469cadc1..30ca5e29f 100644 --- a/relayer/pkg/chainlink/txm/txm.go +++ b/relayer/pkg/chainlink/txm/txm.go @@ -27,7 +27,7 @@ const ( ) type TxManager interface { - Enqueue(accountAddress *felt.Felt, publicKey *felt.Felt, txFn starknetrpc.FunctionCall) error + Enqueue(ctx context.Context, accountAddress *felt.Felt, publicKey *felt.Felt, txFn starknetrpc.FunctionCall) error InflightCount() (int, int) } @@ -483,12 +483,12 @@ func (txm *starktxm) HealthReport() map[string]error { return map[string]error{txm.Name(): txm.Healthy()} } -func (txm *starktxm) Enqueue(accountAddress, publicKey *felt.Felt, tx starknetrpc.FunctionCall) error { +func (txm *starktxm) Enqueue(ctx context.Context, accountAddress, publicKey *felt.Felt, tx starknetrpc.FunctionCall) error { // validate key exists for sender // use the embedded Loopp Keystore to do this; the spec and design // encourage passing nil data to the loop.Keystore.Sign as way to test // existence of a key - if _, err := txm.ks.Loopp().Sign(context.Background(), publicKey.String(), nil); err != nil { + if _, err := txm.ks.Loopp().Sign(ctx, publicKey.String(), nil); err != nil { return fmt.Errorf("enqueue: failed to sign: %+w", err) } diff --git a/relayer/pkg/chainlink/txm/txm_test.go b/relayer/pkg/chainlink/txm/txm_test.go index 74d27fc53..460843cb8 100644 --- a/relayer/pkg/chainlink/txm/txm_test.go +++ b/relayer/pkg/chainlink/txm/txm_test.go @@ -20,11 +20,13 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/loop" adapters "github.com/smartcontractkit/chainlink-common/pkg/loop/adapters/starknet" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/txm/mocks" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet" ) func TestIntegration_Txm(t *testing.T) { + ctx := tests.Context(t) n := 2 // number of txs per key // url := SetupLocalStarknetNode(t) url := "http://127.0.0.1:5050" @@ -100,7 +102,7 @@ func TestIntegration_Txm(t *testing.T) { selector := starknetutils.GetSelectorFromNameFelt("totalSupply") for i := 0; i < n; i++ { - require.NoError(t, txm.Enqueue(accountAddress, publicKey, starknetrpc.FunctionCall{ + require.NoError(t, txm.Enqueue(ctx, accountAddress, publicKey, starknetrpc.FunctionCall{ ContractAddress: contractAddress, // send to ETH token contract EntryPointSelector: selector, }))