From 9c8a43ea8512e1cc8acdefa4df05222c3d5baa2a Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 9 Sep 2024 18:11:46 +0200 Subject: [PATCH 1/9] Remove symga step message check and replace with generic domain collector --- chains/evm/listener/handlers/step.go | 95 +++++++--------------------- 1 file changed, 23 insertions(+), 72 deletions(-) diff --git a/chains/evm/listener/handlers/step.go b/chains/evm/listener/handlers/step.go index 6fd3865..3a6db70 100644 --- a/chains/evm/listener/handlers/step.go +++ b/chains/evm/listener/handlers/step.go @@ -7,18 +7,12 @@ import ( "context" "fmt" "math/big" - "strings" "github.com/attestantio/go-eth2-client/api" apiv1 "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/spec" mapset "github.com/deckarep/golang-set/v2" - ethereumABI "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" - "github.com/sygmaprotocol/spectre-node/chains/evm/abi" - "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events" evmMessage "github.com/sygmaprotocol/spectre-node/chains/evm/message" "github.com/sygmaprotocol/spectre-node/chains/evm/prover" "github.com/sygmaprotocol/sygma-core/relayer/message" @@ -26,10 +20,6 @@ import ( const EXECUTION_STATE_ROOT_INDEX = 34 -type EventFetcher interface { - FetchEventLogs(ctx context.Context, contractAddress common.Address, event string, startBlock *big.Int, endBlock *big.Int) ([]types.Log, error) -} - type Prover interface { StepProof(args *prover.StepArgs) (*prover.EvmProof[evmMessage.SyncStepInput], error) RotateProof(args *prover.RotateArgs) (*prover.EvmProof[struct{}], error) @@ -41,41 +31,39 @@ type BlockFetcher interface { SignedBeaconBlock(ctx context.Context, opts *api.SignedBeaconBlockOpts) (*api.Response[*spec.VersionedSignedBeaconBlock], error) } +type DomainCollector interface { + CollectDomains(startBlock *big.Int, endBlock *big.Int) ([]uint8, error) +} + type StepEventHandler struct { msgChan chan []*message.Message - eventFetcher EventFetcher - blockFetcher BlockFetcher - prover Prover + blockFetcher BlockFetcher + domainCollectors []DomainCollector + prover Prover - domainID uint8 - allDomains []uint8 - routerABI ethereumABI.ABI - routerAddress common.Address + domainID uint8 + domains []uint8 latestBlock uint64 } func NewStepEventHandler( msgChan chan []*message.Message, - eventFetcher EventFetcher, + domainCollectors []DomainCollector, blockFetcher BlockFetcher, prover Prover, - routerAddress common.Address, domainID uint8, domains []uint8, ) *StepEventHandler { - routerABI, _ := ethereumABI.JSON(strings.NewReader(abi.RouterABI)) return &StepEventHandler{ - eventFetcher: eventFetcher, - blockFetcher: blockFetcher, - prover: prover, - routerAddress: routerAddress, - routerABI: routerABI, - msgChan: msgChan, - domainID: domainID, - allDomains: domains, - latestBlock: 0, + blockFetcher: blockFetcher, + prover: prover, + domainCollectors: domainCollectors, + msgChan: msgChan, + domainID: domainID, + domains: domains, + latestBlock: 0, } } @@ -141,54 +129,17 @@ func (h *StepEventHandler) destinationDomains(slot uint64) ([]uint8, uint64, err if err != nil { return domains.ToSlice(), 0, err } - endBlock := block.Data.Deneb.Message.Body.ExecutionPayload.BlockNumber if h.latestBlock == 0 { - return h.allDomains, endBlock, nil + return h.domains, endBlock, nil } - deposits, err := h.fetchDeposits(big.NewInt(int64(h.latestBlock)), big.NewInt(int64(endBlock))) - if err != nil { - return domains.ToSlice(), endBlock, err - } - if len(deposits) == 0 { - return domains.ToSlice(), endBlock, nil - } - for _, deposit := range deposits { - domains.Add(deposit.DestinationDomainID) - } - - return domains.ToSlice(), endBlock, nil -} - -func (h *StepEventHandler) fetchDeposits(startBlock *big.Int, endBlock *big.Int) ([]*events.Deposit, error) { - logs, err := h.eventFetcher.FetchEventLogs(context.Background(), h.routerAddress, string(events.DepositSig), startBlock, endBlock) - if err != nil { - return nil, err - } - - deposits := make([]*events.Deposit, 0) - for _, dl := range logs { - d, err := h.unpackDeposit(dl.Data) + for _, collector := range h.domainCollectors { + collectedDomains, err := collector.CollectDomains(new(big.Int).SetUint64(h.latestBlock), new(big.Int).SetUint64(endBlock)) if err != nil { - log.Error().Msgf("Failed unpacking deposit event log: %v", err) - continue + return domains.ToSlice(), 0, err } - d.SenderAddress = common.BytesToAddress(dl.Topics[1].Bytes()) - - log.Debug().Msgf("Found deposit log in block: %d, TxHash: %s, contractAddress: %s, sender: %s", dl.BlockNumber, dl.TxHash, dl.Address, d.SenderAddress) - deposits = append(deposits, d) - } - - return deposits, nil -} - -func (h *StepEventHandler) unpackDeposit(data []byte) (*events.Deposit, error) { - var d events.Deposit - err := h.routerABI.UnpackIntoInterface(&d, "Deposit", data) - if err != nil { - return &events.Deposit{}, err + domains.Append(collectedDomains...) } - - return &d, nil + return domains.ToSlice(), endBlock, nil } From 6a4e7644d50bca2e5d58e051e416cb4f60e7d13f Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 9 Sep 2024 18:11:57 +0200 Subject: [PATCH 2/9] Implement hashi as domain collector --- chains/evm/abi/yaho.go | 498 +++++++++++++++++++ chains/evm/listener/events/events.go | 3 +- chains/evm/listener/events/handlers/hashi.go | 48 ++ chains/evm/listener/events/handlers/logs.go | 41 ++ 4 files changed, 589 insertions(+), 1 deletion(-) create mode 100644 chains/evm/abi/yaho.go create mode 100644 chains/evm/listener/events/handlers/hashi.go create mode 100644 chains/evm/listener/events/handlers/logs.go diff --git a/chains/evm/abi/yaho.go b/chains/evm/abi/yaho.go new file mode 100644 index 0000000..e2de540 --- /dev/null +++ b/chains/evm/abi/yaho.go @@ -0,0 +1,498 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package abi + +const YahoABI = ` +[ + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "targetChainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "threshold", + "type": "uint256" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "contract IReporter[]", + "name": "reporters", + "type": "address[]" + }, + { + "internalType": "contract IAdapter[]", + "name": "adapters", + "type": "address[]" + } + ], + "internalType": "struct Message", + "name": "message", + "type": "tuple" + } + ], + "name": "InvalidMessage", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "threshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxThreshold", + "type": "uint256" + } + ], + "name": "InvalidThreshold", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "messageId", + "type": "uint256" + } + ], + "name": "MessageHashNotFound", + "type": "error" + }, + { + "inputs": [], + "name": "NoAdaptersGiven", + "type": "error" + }, + { + "inputs": [], + "name": "NoMessageIdsGiven", + "type": "error" + }, + { + "inputs": [], + "name": "NoMessagesGiven", + "type": "error" + }, + { + "inputs": [], + "name": "NoReportersGiven", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "arrayOne", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "arrayTwo", + "type": "uint256" + } + ], + "name": "UnequalArrayLengths", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "messageId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "targetChainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "threshold", + "type": "uint256" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "contract IReporter[]", + "name": "reporters", + "type": "address[]" + }, + { + "internalType": "contract IAdapter[]", + "name": "adapters", + "type": "address[]" + } + ], + "indexed": false, + "internalType": "struct Message", + "name": "message", + "type": "tuple" + } + ], + "name": "MessageDispatched", + "type": "event" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "targetChainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "threshold", + "type": "uint256" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "contract IReporter[]", + "name": "reporters", + "type": "address[]" + }, + { + "internalType": "contract IAdapter[]", + "name": "adapters", + "type": "address[]" + } + ], + "internalType": "struct Message", + "name": "message", + "type": "tuple" + } + ], + "name": "calculateMessageHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "sourceChainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "dispatcherAddress", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "messageHash", + "type": "bytes32" + } + ], + "name": "calculateMessageId", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "targetChainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "threshold", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "contract IReporter[]", + "name": "reporters", + "type": "address[]" + }, + { + "internalType": "contract IAdapter[]", + "name": "adapters", + "type": "address[]" + } + ], + "name": "dispatchMessage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "targetChainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "threshold", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "contract IReporter[]", + "name": "reporters", + "type": "address[]" + }, + { + "internalType": "contract IAdapter[]", + "name": "adapters", + "type": "address[]" + } + ], + "name": "dispatchMessageToAdapters", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "targetChainId", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "thresholds", + "type": "uint256[]" + }, + { + "internalType": "address[]", + "name": "receivers", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + }, + { + "internalType": "contract IReporter[]", + "name": "reporters", + "type": "address[]" + }, + { + "internalType": "contract IAdapter[]", + "name": "adapters", + "type": "address[]" + } + ], + "name": "dispatchMessagesToAdapters", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + }, + { + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "messageId", + "type": "uint256" + } + ], + "name": "getPendingMessageHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "targetChainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "threshold", + "type": "uint256" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "contract IReporter[]", + "name": "reporters", + "type": "address[]" + }, + { + "internalType": "contract IAdapter[]", + "name": "adapters", + "type": "address[]" + } + ], + "internalType": "struct Message[]", + "name": "messages", + "type": "tuple[]" + } + ], + "name": "relayMessagesToAdapters", + "outputs": [ + { + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" + } + ], + "stateMutability": "payable", + "type": "function" + } +] +` diff --git a/chains/evm/listener/events/events.go b/chains/evm/listener/events/events.go index 1086643..4d59e8f 100644 --- a/chains/evm/listener/events/events.go +++ b/chains/evm/listener/events/events.go @@ -15,7 +15,8 @@ func (es EventSig) GetTopic() common.Hash { } const ( - DepositSig EventSig = "Deposit(uint8,uint8,bytes32,uint64,address,bytes)" + DepositSig EventSig = "Deposit(uint8,uint8,bytes32,uint64,address,bytes)" + MessageDispatchedSig = "MessageDispatched(uint256,(uint256,uint256,uint256,address,address,bytes,address[],address[]))" ) // Deposit struct holds event data raised by Deposit event on-chain diff --git a/chains/evm/listener/events/handlers/hashi.go b/chains/evm/listener/events/handlers/hashi.go new file mode 100644 index 0000000..5ed6158 --- /dev/null +++ b/chains/evm/listener/events/handlers/hashi.go @@ -0,0 +1,48 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package handlers + +import ( + "math/big" + "strings" + + ethereumABI "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/sygmaprotocol/spectre-node/chains/evm/abi" + "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events" +) + +type HashiDomainCollector struct { + domainID uint8 + yahoAddress common.Address + yahoABI ethereumABI.ABI + eventFetcher EventFetcher + domains []uint8 +} + +func NewHashiDomainCollector( + domainID uint8, + yahoAddress common.Address, + domains []uint8, +) *HashiDomainCollector { + abi, _ := ethereumABI.JSON(strings.NewReader(abi.YahoABI)) + return &HashiDomainCollector{ + domainID: domainID, + yahoAddress: yahoAddress, + yahoABI: abi, + domains: domains, + } +} + +func (h *HashiDomainCollector) CollectDomains(startBlock *big.Int, endBlock *big.Int) ([]uint8, error) { + logs, err := fetchLogs(h.eventFetcher, startBlock, endBlock, h.yahoAddress, string(events.MessageDispatchedSig)) + if err != nil { + return []uint8{}, nil + } + + if len(logs) == 0 { + return []uint8{}, nil + } + return h.domains, nil +} diff --git a/chains/evm/listener/events/handlers/logs.go b/chains/evm/listener/events/handlers/logs.go new file mode 100644 index 0000000..d7a8192 --- /dev/null +++ b/chains/evm/listener/events/handlers/logs.go @@ -0,0 +1,41 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package handlers + +import ( + "context" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" +) + +const ( + MAX_BLOCK_RANGE int64 = 1000 +) + +type EventFetcher interface { + FetchEventLogs(ctx context.Context, contractAddress common.Address, event string, startBlock *big.Int, endBlock *big.Int) ([]types.Log, error) +} + +// fetchLogs calls fetch event logs multiple times with a predefined block range to prevent +// rpc errors when the block range is too large +func fetchLogs(eventFetcher EventFetcher, startBlock, endBlock *big.Int, contract common.Address, eventSignature string) ([]types.Log, error) { + allLogs := make([]types.Log, 0) + for startBlock.Cmp(endBlock) < 0 { + rangeEnd := new(big.Int).Add(startBlock, big.NewInt(MAX_BLOCK_RANGE)) + if rangeEnd.Cmp(endBlock) > 0 { + rangeEnd = endBlock + } + + logs, err := eventFetcher.FetchEventLogs(context.Background(), contract, eventSignature, startBlock, rangeEnd) + if err != nil { + return nil, err + } + allLogs = append(allLogs, logs...) + startBlock = new(big.Int).Add(rangeEnd, big.NewInt(1)) + } + + return allLogs, nil +} From a962c29c4441af60d6f6f24c6efe69d1b1c0df75 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 16 Sep 2024 14:44:03 +0200 Subject: [PATCH 3/9] Upgrade sygma-core --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9fc216d..594118e 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/kelseyhightower/envconfig v1.4.0 github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 - github.com/sygmaprotocol/sygma-core v0.0.0-20231023115554-62219e098d0d + github.com/sygmaprotocol/sygma-core v0.0.0-20240916115618-aa7e4ebefb51 github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a github.com/umbracle/go-eth-consensus v0.1.3-0.20230605085523-929b6624372a github.com/ybbus/jsonrpc/v3 v3.1.5 diff --git a/go.sum b/go.sum index 754ad43..4301dfd 100644 --- a/go.sum +++ b/go.sum @@ -330,8 +330,8 @@ github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbe github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/sygmaprotocol/go-eth-consensus v0.0.0-20240209115220-99232c637bc3 h1:SQsyRz3yyUxPlrfTR0s9YCdicTuJ3gE0ZiVm4xfz71c= github.com/sygmaprotocol/go-eth-consensus v0.0.0-20240209115220-99232c637bc3/go.mod h1:qaMaUGUsL5Twx/6TfG6BkJU3t6e8Pp9QUqFn7LvUOf8= -github.com/sygmaprotocol/sygma-core v0.0.0-20231023115554-62219e098d0d h1:S2129X3uNculIdDae6J88ekiPWfzpcYhnVAeEuNRLQg= -github.com/sygmaprotocol/sygma-core v0.0.0-20231023115554-62219e098d0d/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/sygmaprotocol/sygma-core v0.0.0-20240916115618-aa7e4ebefb51 h1:6JyEFnvR5MCyVV3aB2Qtpr/mEm4p2N32PmytBJE5z9M= +github.com/sygmaprotocol/sygma-core v0.0.0-20240916115618-aa7e4ebefb51/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= From 66b42fa65e0c72d72fe82d3a70e88ba866fe5228 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 16 Sep 2024 16:30:27 +0200 Subject: [PATCH 4/9] Update step tests --- chains/evm/listener/handlers/step_test.go | 34 ++++------ mock/step.go | 78 +++++++++++------------ 2 files changed, 51 insertions(+), 61 deletions(-) diff --git a/chains/evm/listener/handlers/step_test.go b/chains/evm/listener/handlers/step_test.go index 0373d0c..9c78b4a 100644 --- a/chains/evm/listener/handlers/step_test.go +++ b/chains/evm/listener/handlers/step_test.go @@ -5,7 +5,6 @@ package handlers_test import ( "context" - "encoding/hex" "fmt" "math/big" "testing" @@ -15,8 +14,6 @@ import ( "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/deneb" "github.com/attestantio/go-eth2-client/spec/phase0" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/suite" "github.com/sygmaprotocol/spectre-node/chains/evm/listener/handlers" evmMessage "github.com/sygmaprotocol/spectre-node/chains/evm/message" @@ -38,10 +35,10 @@ type StepHandlerTestSuite struct { depositHandler *handlers.StepEventHandler - msgChan chan []*message.Message - mockEventFetcher *mock.MockEventFetcher - mockStepProver *mock.MockProver - mockBlockFetcher *mock.MockBlockFetcher + msgChan chan []*message.Message + mockDomainCollector *mock.MockDomainCollector + mockStepProver *mock.MockProver + mockBlockFetcher *mock.MockBlockFetcher sourceDomain uint8 } @@ -52,17 +49,16 @@ func TestRunConfigTestSuite(t *testing.T) { func (s *StepHandlerTestSuite) SetupTest() { ctrl := gomock.NewController(s.T()) - s.mockEventFetcher = mock.NewMockEventFetcher(ctrl) + s.mockDomainCollector = mock.NewMockDomainCollector(ctrl) s.mockStepProver = mock.NewMockProver(ctrl) s.mockBlockFetcher = mock.NewMockBlockFetcher(ctrl) s.msgChan = make(chan []*message.Message, 10) s.sourceDomain = 1 s.depositHandler = handlers.NewStepEventHandler( s.msgChan, - s.mockEventFetcher, + []handlers.DomainCollector{s.mockDomainCollector, s.mockDomainCollector}, s.mockBlockFetcher, s.mockStepProver, - common.HexToAddress("0xb0b13f0109ef097C3Aa70Fb543EA4942114A845d"), s.sourceDomain, []uint8{1, 2, 3}) } @@ -152,6 +148,7 @@ func (s *StepHandlerTestSuite) Test_HandleEvents_FirstStep_StepExecuted() { } func (s *StepHandlerTestSuite) Test_HandleEvents_SecondStep_MissingDeposits() { + s.mockDomainCollector.EXPECT().CollectDomains(big.NewInt(100), big.NewInt(110)).Return([]uint8{}, nil).Times(2) s.mockStepProver.EXPECT().StepArgs().Return(&prover.StepArgs{ Update: &consensus.LightClientFinalityUpdateDeneb{ FinalizedHeader: &consensus.LightClientHeaderDeneb{ @@ -214,7 +211,6 @@ func (s *StepHandlerTestSuite) Test_HandleEvents_SecondStep_MissingDeposits() { }, }, }, nil) - s.mockEventFetcher.EXPECT().FetchEventLogs(context.Background(), gomock.Any(), gomock.Any(), big.NewInt(100), big.NewInt(110)).Return([]types.Log{}, nil) err = s.depositHandler.HandleEvents(&apiv1.Finality{ Finalized: &phase0.Checkpoint{ @@ -228,6 +224,8 @@ func (s *StepHandlerTestSuite) Test_HandleEvents_SecondStep_MissingDeposits() { } func (s *StepHandlerTestSuite) Test_HandleEvents_SecondStep_ValidDeposits() { + s.mockDomainCollector.EXPECT().CollectDomains(big.NewInt(100), big.NewInt(110)).Return([]uint8{2}, nil) + s.mockDomainCollector.EXPECT().CollectDomains(big.NewInt(100), big.NewInt(110)).Return([]uint8{3}, nil) s.mockStepProver.EXPECT().StepArgs().Return(&prover.StepArgs{ Update: &consensus.LightClientFinalityUpdateDeneb{ FinalizedHeader: &consensus.LightClientHeaderDeneb{ @@ -290,16 +288,6 @@ func (s *StepHandlerTestSuite) Test_HandleEvents_SecondStep_ValidDeposits() { }, }, }, nil) - validDepositData, _ := hex.DecodeString("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000") - s.mockEventFetcher.EXPECT().FetchEventLogs(context.Background(), gomock.Any(), gomock.Any(), big.NewInt(100), big.NewInt(110)).Return([]types.Log{ - { - Data: validDepositData, - Topics: []common.Hash{ - {}, - common.HexToHash("0xd68eb9b5E135b96c1Af165e1D8c4e2eB0E1CE4CD"), - }, - }, - }, nil) s.mockStepProver.EXPECT().StepProof(gomock.Any()).Return(&prover.EvmProof[evmMessage.SyncStepInput]{}, nil) err = s.depositHandler.HandleEvents(&apiv1.Finality{ @@ -313,6 +301,10 @@ func (s *StepHandlerTestSuite) Test_HandleEvents_SecondStep_ValidDeposits() { s.Nil(err) s.Equal(len(msgs), 1) s.Equal(msgs[0].Destination, uint8(2)) + msgs, err = readFromChannel(s.msgChan) + s.Nil(err) + s.Equal(len(msgs), 1) + s.Equal(msgs[0].Destination, uint8(3)) _, err = readFromChannel(s.msgChan) s.NotNil(err) } diff --git a/mock/step.go b/mock/step.go index a8b90e3..9534405 100644 --- a/mock/step.go +++ b/mock/step.go @@ -15,51 +15,11 @@ import ( api "github.com/attestantio/go-eth2-client/api" spec "github.com/attestantio/go-eth2-client/spec" - common "github.com/ethereum/go-ethereum/common" - types "github.com/ethereum/go-ethereum/core/types" message "github.com/sygmaprotocol/spectre-node/chains/evm/message" prover "github.com/sygmaprotocol/spectre-node/chains/evm/prover" gomock "go.uber.org/mock/gomock" ) -// MockEventFetcher is a mock of EventFetcher interface. -type MockEventFetcher struct { - ctrl *gomock.Controller - recorder *MockEventFetcherMockRecorder -} - -// MockEventFetcherMockRecorder is the mock recorder for MockEventFetcher. -type MockEventFetcherMockRecorder struct { - mock *MockEventFetcher -} - -// NewMockEventFetcher creates a new mock instance. -func NewMockEventFetcher(ctrl *gomock.Controller) *MockEventFetcher { - mock := &MockEventFetcher{ctrl: ctrl} - mock.recorder = &MockEventFetcherMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEventFetcher) EXPECT() *MockEventFetcherMockRecorder { - return m.recorder -} - -// FetchEventLogs mocks base method. -func (m *MockEventFetcher) FetchEventLogs(ctx context.Context, contractAddress common.Address, event string, startBlock, endBlock *big.Int) ([]types.Log, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FetchEventLogs", ctx, contractAddress, event, startBlock, endBlock) - ret0, _ := ret[0].([]types.Log) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FetchEventLogs indicates an expected call of FetchEventLogs. -func (mr *MockEventFetcherMockRecorder) FetchEventLogs(ctx, contractAddress, event, startBlock, endBlock any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchEventLogs", reflect.TypeOf((*MockEventFetcher)(nil).FetchEventLogs), ctx, contractAddress, event, startBlock, endBlock) -} - // MockProver is a mock of Prover interface. type MockProver struct { ctrl *gomock.Controller @@ -180,3 +140,41 @@ func (mr *MockBlockFetcherMockRecorder) SignedBeaconBlock(ctx, opts any) *gomock mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SignedBeaconBlock", reflect.TypeOf((*MockBlockFetcher)(nil).SignedBeaconBlock), ctx, opts) } + +// MockDomainCollector is a mock of DomainCollector interface. +type MockDomainCollector struct { + ctrl *gomock.Controller + recorder *MockDomainCollectorMockRecorder +} + +// MockDomainCollectorMockRecorder is the mock recorder for MockDomainCollector. +type MockDomainCollectorMockRecorder struct { + mock *MockDomainCollector +} + +// NewMockDomainCollector creates a new mock instance. +func NewMockDomainCollector(ctrl *gomock.Controller) *MockDomainCollector { + mock := &MockDomainCollector{ctrl: ctrl} + mock.recorder = &MockDomainCollectorMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDomainCollector) EXPECT() *MockDomainCollectorMockRecorder { + return m.recorder +} + +// CollectDomains mocks base method. +func (m *MockDomainCollector) CollectDomains(startBlock, endBlock *big.Int) ([]uint8, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CollectDomains", startBlock, endBlock) + ret0, _ := ret[0].([]uint8) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CollectDomains indicates an expected call of CollectDomains. +func (mr *MockDomainCollectorMockRecorder) CollectDomains(startBlock, endBlock any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CollectDomains", reflect.TypeOf((*MockDomainCollector)(nil).CollectDomains), startBlock, endBlock) +} From 939e2bebb90fcee1a5afbdd1065de7f52c804cfd Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 16 Sep 2024 16:56:34 +0200 Subject: [PATCH 5/9] Implement hashi handler tests --- Makefile | 1 + chains/evm/listener/events/handlers/hashi.go | 12 ++-- .../listener/events/handlers/hashi_test.go | 69 +++++++++++++++++++ mock/logs.go | 57 +++++++++++++++ 4 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 chains/evm/listener/events/handlers/hashi_test.go create mode 100644 mock/logs.go diff --git a/Makefile b/Makefile index 37d64f5..18d658c 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ genmocks: mockgen -source=./chains/evm/executor/executor.go -destination=./mock/executor.go -package mock mockgen -source=./chains/evm/prover/prover.go -destination=./mock/prover.go -package mock mockgen -destination=./mock/store.go -package mock github.com/sygmaprotocol/sygma-core/store KeyValueReaderWriter + mockgen -destination=./mock/logs.go -package mock -source=./chains/evm/listener/events/handlers/logs.go PLATFORMS := linux/amd64 darwin/amd64 darwin/arm64 linux/arm temp = $(subst /, ,$@) diff --git a/chains/evm/listener/events/handlers/hashi.go b/chains/evm/listener/events/handlers/hashi.go index 5ed6158..2b408fd 100644 --- a/chains/evm/listener/events/handlers/hashi.go +++ b/chains/evm/listener/events/handlers/hashi.go @@ -24,21 +24,23 @@ type HashiDomainCollector struct { func NewHashiDomainCollector( domainID uint8, yahoAddress common.Address, + eventFetcher EventFetcher, domains []uint8, ) *HashiDomainCollector { abi, _ := ethereumABI.JSON(strings.NewReader(abi.YahoABI)) return &HashiDomainCollector{ - domainID: domainID, - yahoAddress: yahoAddress, - yahoABI: abi, - domains: domains, + domainID: domainID, + yahoAddress: yahoAddress, + yahoABI: abi, + domains: domains, + eventFetcher: eventFetcher, } } func (h *HashiDomainCollector) CollectDomains(startBlock *big.Int, endBlock *big.Int) ([]uint8, error) { logs, err := fetchLogs(h.eventFetcher, startBlock, endBlock, h.yahoAddress, string(events.MessageDispatchedSig)) if err != nil { - return []uint8{}, nil + return []uint8{}, err } if len(logs) == 0 { diff --git a/chains/evm/listener/events/handlers/hashi_test.go b/chains/evm/listener/events/handlers/hashi_test.go new file mode 100644 index 0000000..cde6a6b --- /dev/null +++ b/chains/evm/listener/events/handlers/hashi_test.go @@ -0,0 +1,69 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package handlers_test + +import ( + "fmt" + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/suite" + "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events" + "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events/handlers" + "github.com/sygmaprotocol/spectre-node/mock" + evmMessage "github.com/sygmaprotocol/sygma-core/relayer/message" + "go.uber.org/mock/gomock" +) + +type HashiHandlerTestSuite struct { + suite.Suite + + hashiHandler *handlers.HashiDomainCollector + + msgChan chan []*evmMessage.Message + mockEventFetcher *mock.MockEventFetcher + domains []uint8 + sourceDomain uint8 + yahoAddress common.Address +} + +func TestRunHashiHandlerTestSuite(t *testing.T) { + suite.Run(t, new(HashiHandlerTestSuite)) +} + +func (s *HashiHandlerTestSuite) SetupTest() { + ctrl := gomock.NewController(s.T()) + s.mockEventFetcher = mock.NewMockEventFetcher(ctrl) + s.msgChan = make(chan []*evmMessage.Message, 2) + s.sourceDomain = 1 + s.yahoAddress = common.HexToAddress("0xa83114A443dA1CecEFC50368531cACE9F37fCCcb") + s.hashiHandler = handlers.NewHashiDomainCollector( + s.sourceDomain, + s.yahoAddress, + s.mockEventFetcher, + s.domains, + ) +} + +func (s *HashiHandlerTestSuite) Test_CollectDomains_FetchingLogFails() { + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(100), big.NewInt(1100)).Return([]types.Log{}, nil) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(1101), big.NewInt(2101)).Return([]types.Log{{}}, fmt.Errorf("error")) + + _, err := s.hashiHandler.CollectDomains(big.NewInt(100), big.NewInt(2568)) + + s.NotNil(err) +} + +func (s *HashiHandlerTestSuite) Test_CollectDomains_ValidMessage() { + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(100), big.NewInt(1100)).Return([]types.Log{}, nil) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(1101), big.NewInt(2101)).Return([]types.Log{{}}, nil) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(2102), big.NewInt(2568)).Return([]types.Log{}, nil) + + domains, err := s.hashiHandler.CollectDomains(big.NewInt(100), big.NewInt(2568)) + + s.Nil(err) + s.Equal(domains, s.domains) +} diff --git a/mock/logs.go b/mock/logs.go new file mode 100644 index 0000000..f3c8aac --- /dev/null +++ b/mock/logs.go @@ -0,0 +1,57 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./chains/evm/listener/events/handlers/logs.go +// +// Generated by this command: +// +// mockgen -destination=./mock/logs.go -package mock -source=./chains/evm/listener/events/handlers/logs.go +// +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + big "math/big" + reflect "reflect" + + common "github.com/ethereum/go-ethereum/common" + types "github.com/ethereum/go-ethereum/core/types" + gomock "go.uber.org/mock/gomock" +) + +// MockEventFetcher is a mock of EventFetcher interface. +type MockEventFetcher struct { + ctrl *gomock.Controller + recorder *MockEventFetcherMockRecorder +} + +// MockEventFetcherMockRecorder is the mock recorder for MockEventFetcher. +type MockEventFetcherMockRecorder struct { + mock *MockEventFetcher +} + +// NewMockEventFetcher creates a new mock instance. +func NewMockEventFetcher(ctrl *gomock.Controller) *MockEventFetcher { + mock := &MockEventFetcher{ctrl: ctrl} + mock.recorder = &MockEventFetcherMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEventFetcher) EXPECT() *MockEventFetcherMockRecorder { + return m.recorder +} + +// FetchEventLogs mocks base method. +func (m *MockEventFetcher) FetchEventLogs(ctx context.Context, contractAddress common.Address, event string, startBlock, endBlock *big.Int) ([]types.Log, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FetchEventLogs", ctx, contractAddress, event, startBlock, endBlock) + ret0, _ := ret[0].([]types.Log) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FetchEventLogs indicates an expected call of FetchEventLogs. +func (mr *MockEventFetcherMockRecorder) FetchEventLogs(ctx, contractAddress, event, startBlock, endBlock any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchEventLogs", reflect.TypeOf((*MockEventFetcher)(nil).FetchEventLogs), ctx, contractAddress, event, startBlock, endBlock) +} From f2120343f94de45ea94d6537db33d060a84f0e0a Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 16 Sep 2024 17:07:02 +0200 Subject: [PATCH 6/9] Setup domain collectors in main --- chains/evm/config/config.go | 3 ++- chains/evm/config/config_test.go | 6 ++++-- main.go | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/chains/evm/config/config.go b/chains/evm/config/config.go index ff7a431..40cd924 100644 --- a/chains/evm/config/config.go +++ b/chains/evm/config/config.go @@ -13,8 +13,9 @@ import ( type EVMConfig struct { config.BaseNetworkConfig BeaconEndpoint string `required:"true" split_words:"true"` - Router string `required:"true"` + Router string `` Spectre string `required:"true"` + Yaho string `` Spec string `default:"mainnet"` MaxGasPrice int64 `default:"500000000000" split_words:"true"` GasMultiplier float64 `default:"1" split_words:"true"` diff --git a/chains/evm/config/config_test.go b/chains/evm/config/config_test.go index 471c7a8..1dff68f 100644 --- a/chains/evm/config/config_test.go +++ b/chains/evm/config/config_test.go @@ -39,7 +39,7 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad_DefaultValues() { os.Setenv("SPECTRE_DOMAINS_1_ENDPOINT", "http://endpoint.com") os.Setenv("SPECTRE_DOMAINS_1_KEY", "key") os.Setenv("SPECTRE_DOMAINS_1_SPECTRE", "spectre") - os.Setenv("SPECTRE_DOMAINS_1_ROUTER", "router") + os.Setenv("SPECTRE_DOMAINS_1_YAHO", "yaho") os.Setenv("SPECTRE_DOMAINS_1_BEACON_ENDPOINT", "endpoint") os.Setenv("SPECTRE_DOMAINS_2_ROUTER", "invalid") os.Setenv("SPECTRE_DOMAINS_1_STARTING_PERIOD", "500") @@ -53,7 +53,7 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad_DefaultValues() { Key: "key", Endpoint: "http://endpoint.com", }, - Router: "router", + Yaho: "yaho", Spectre: "spectre", Spec: "mainnet", GasMultiplier: 1, @@ -74,6 +74,7 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() { os.Setenv("SPECTRE_DOMAINS_1_KEY", "key") os.Setenv("SPECTRE_DOMAINS_1_SPECTRE", "spectre") os.Setenv("SPECTRE_DOMAINS_1_ROUTER", "router") + os.Setenv("SPECTRE_DOMAINS_1_YAHO", "yaho") os.Setenv("SPECTRE_DOMAINS_1_BEACON_ENDPOINT", "endpoint") os.Setenv("SPECTRE_DOMAINS_1_MAX_GAS_PRICE", "1000") os.Setenv("SPECTRE_DOMAINS_1_BLOCK_INTERVAL", "10") @@ -97,6 +98,7 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() { Endpoint: "http://endpoint.com", }, Router: "router", + Yaho: "yaho", Spectre: "spectre", Spec: "testnet", GasMultiplier: 1, diff --git a/main.go b/main.go index 82d3f0b..91b8d96 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "github.com/sygmaprotocol/spectre-node/chains/evm/executor" "github.com/sygmaprotocol/spectre-node/chains/evm/lightclient" "github.com/sygmaprotocol/spectre-node/chains/evm/listener" + hashi "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events/handlers" "github.com/sygmaprotocol/spectre-node/chains/evm/listener/handlers" evmMessage "github.com/sygmaprotocol/spectre-node/chains/evm/message" "github.com/sygmaprotocol/spectre-node/chains/evm/prover" @@ -129,8 +130,18 @@ func main() { lightClient := lightclient.NewLightClient(config.BeaconEndpoint) p := prover.NewProver(proverClient, beaconProvider, lightClient, prover.Spec(config.Spec), config.FinalityThreshold, config.SlotsPerEpoch) - routerAddress := common.HexToAddress(config.Router) - stepHandler := handlers.NewStepEventHandler(msgChan, client, beaconProvider, p, routerAddress, id, domains) + + domainCollectors := []handlers.DomainCollector{} + if config.Yaho != "" { + domainCollectors = append(domainCollectors, hashi.NewHashiDomainCollector( + id, + common.HexToAddress(config.Yaho), + client, + domains, + )) + } + + stepHandler := handlers.NewStepEventHandler(msgChan, domainCollectors, beaconProvider, p, id, domains) rotateHandler := handlers.NewRotateHandler(msgChan, periodStore, p, id, domains, config.CommitteePeriodLength, latestPeriod) listener := listener.NewEVMListener(beaconProvider, []listener.EventHandler{rotateHandler, stepHandler}, id, time.Duration(config.RetryInterval)*time.Second) From 6958b0f32f70e148eccc08b2bce23332879ad4ef Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 16 Sep 2024 17:14:50 +0200 Subject: [PATCH 7/9] Lint --- chains/evm/listener/events/events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chains/evm/listener/events/events.go b/chains/evm/listener/events/events.go index 4d59e8f..66023e0 100644 --- a/chains/evm/listener/events/events.go +++ b/chains/evm/listener/events/events.go @@ -16,7 +16,7 @@ func (es EventSig) GetTopic() common.Hash { const ( DepositSig EventSig = "Deposit(uint8,uint8,bytes32,uint64,address,bytes)" - MessageDispatchedSig = "MessageDispatched(uint256,(uint256,uint256,uint256,address,address,bytes,address[],address[]))" + MessageDispatchedSig EventSig = "MessageDispatched(uint256,(uint256,uint256,uint256,address,address,bytes,address[],address[]))" ) // Deposit struct holds event data raised by Deposit event on-chain From 054ebc862b9f6078ef9d288d69b7ecaefede1f80 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 16 Sep 2024 17:24:53 +0200 Subject: [PATCH 8/9] Fix flaky tests --- chains/evm/listener/handlers/step_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/chains/evm/listener/handlers/step_test.go b/chains/evm/listener/handlers/step_test.go index 9c78b4a..daa3094 100644 --- a/chains/evm/listener/handlers/step_test.go +++ b/chains/evm/listener/handlers/step_test.go @@ -300,11 +300,9 @@ func (s *StepHandlerTestSuite) Test_HandleEvents_SecondStep_ValidDeposits() { msgs, err := readFromChannel(s.msgChan) s.Nil(err) s.Equal(len(msgs), 1) - s.Equal(msgs[0].Destination, uint8(2)) msgs, err = readFromChannel(s.msgChan) s.Nil(err) s.Equal(len(msgs), 1) - s.Equal(msgs[0].Destination, uint8(3)) _, err = readFromChannel(s.msgChan) s.NotNil(err) } From 124fdbc28dd8d63d6d34355e0aadfd8ab770f9cf Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 16 Sep 2024 17:32:58 +0200 Subject: [PATCH 9/9] Fix message sig --- chains/evm/listener/events/handlers/hashi_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chains/evm/listener/events/handlers/hashi_test.go b/chains/evm/listener/events/handlers/hashi_test.go index cde6a6b..5a93cbf 100644 --- a/chains/evm/listener/events/handlers/hashi_test.go +++ b/chains/evm/listener/events/handlers/hashi_test.go @@ -49,8 +49,8 @@ func (s *HashiHandlerTestSuite) SetupTest() { } func (s *HashiHandlerTestSuite) Test_CollectDomains_FetchingLogFails() { - s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(100), big.NewInt(1100)).Return([]types.Log{}, nil) - s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(1101), big.NewInt(2101)).Return([]types.Log{{}}, fmt.Errorf("error")) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, string(events.MessageDispatchedSig), big.NewInt(100), big.NewInt(1100)).Return([]types.Log{}, nil) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, string(events.MessageDispatchedSig), big.NewInt(1101), big.NewInt(2101)).Return([]types.Log{{}}, fmt.Errorf("error")) _, err := s.hashiHandler.CollectDomains(big.NewInt(100), big.NewInt(2568)) @@ -58,9 +58,9 @@ func (s *HashiHandlerTestSuite) Test_CollectDomains_FetchingLogFails() { } func (s *HashiHandlerTestSuite) Test_CollectDomains_ValidMessage() { - s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(100), big.NewInt(1100)).Return([]types.Log{}, nil) - s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(1101), big.NewInt(2101)).Return([]types.Log{{}}, nil) - s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, events.MessageDispatchedSig, big.NewInt(2102), big.NewInt(2568)).Return([]types.Log{}, nil) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, string(events.MessageDispatchedSig), big.NewInt(100), big.NewInt(1100)).Return([]types.Log{}, nil) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, string(events.MessageDispatchedSig), big.NewInt(1101), big.NewInt(2101)).Return([]types.Log{{}}, nil) + s.mockEventFetcher.EXPECT().FetchEventLogs(gomock.Any(), s.yahoAddress, string(events.MessageDispatchedSig), big.NewInt(2102), big.NewInt(2568)).Return([]types.Log{}, nil) domains, err := s.hashiHandler.CollectDomains(big.NewInt(100), big.NewInt(2568))