node/node_test: add test for l1finalizer

This commit is contained in:
tbjump 2023-06-12 15:58:55 +00:00 committed by tbjump
parent 5b33b047a0
commit 49a3fa44aa
3 changed files with 40 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import (
math_rand "math/rand"
"net/http"
"os"
"path"
"regexp"
"strconv"
"strings"
@ -48,6 +49,7 @@ import (
const LOCAL_RPC_PORTRANGE_START = 10000
const LOCAL_P2P_PORTRANGE_START = 10100
const LOCAL_STATUS_PORTRANGE_START = 10200
const LOCAL_PUBLICWEB_PORTRANGE_START = 10300
var PROMETHEUS_METRIC_VALID_HEARTBEAT_RECEIVED = []byte("wormhole_p2p_broadcast_messages_received_total{type=\"valid_heartbeat\"}")
@ -105,6 +107,10 @@ func mockPublicRpc(mockGuardianIndex uint) string {
return fmt.Sprintf("127.0.0.1:%d", mockGuardianIndex+LOCAL_RPC_PORTRANGE_START)
}
func mockPublicWeb(mockGuardianIndex uint) string {
return fmt.Sprintf("127.0.0.1:%d", mockGuardianIndex+LOCAL_PUBLICWEB_PORTRANGE_START)
}
func mockStatusPort(mockGuardianIndex uint) uint {
return mockGuardianIndex + LOCAL_STATUS_PORTRANGE_START
}
@ -164,6 +170,7 @@ func mockGuardianRunnable(gs []*mockGuardian, mockGuardianIndex uint, obsDb mock
GuardianOptionP2P(gs[mockGuardianIndex].p2pKey, networkID, bootstrapPeers, nodeName, false, p2pPort, func() string { return "" }),
GuardianOptionPublicRpcSocket(publicSocketPath, common.GrpcLogDetailFull),
GuardianOptionPublicrpcTcpService(publicRpc, common.GrpcLogDetailFull),
GuardianOptionPublicWeb(mockPublicWeb(mockGuardianIndex), publicSocketPath, "", false, path.Join(dataDir, "autocert")),
GuardianOptionAdminService(adminSocketPath, nil, nil, rpcMap),
GuardianOptionStatusServer(fmt.Sprintf("[::]:%d", mockStatusPort(mockGuardianIndex))),
GuardianOptionProcessor(),
@ -701,9 +708,14 @@ func TestWatcherConfigs(t *testing.T) {
opts: []*GuardianOption{
GuardianOptionWatchers([]watchers.WatcherConfig{
&mock.WatcherConfig{
NetworkID: "mock",
NetworkID: "mock1",
ChainID: vaa.ChainIDSolana,
},
&mock.WatcherConfig{
NetworkID: "mock2",
ChainID: vaa.ChainIDEthereum,
L1FinalizerRequired: "mock1",
},
}, nil),
},
err: "",
@ -724,6 +736,19 @@ func TestWatcherConfigs(t *testing.T) {
},
err: "NetworkID already configured: mock",
},
{
name: "watcher-noL1",
opts: []*GuardianOption{
GuardianOptionWatchers([]watchers.WatcherConfig{
&mock.WatcherConfig{
NetworkID: "mock",
ChainID: vaa.ChainIDSolana,
L1FinalizerRequired: "something-that-does-not-exist",
},
}, nil),
},
err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.",
},
}
testGuardianConfigurations(t, tc)
}

View File

@ -14,11 +14,12 @@ type ObservationDb map[eth_common.Hash]*common.MessagePublication
// The Mock Watcher is a watcher that will make a new observation
type WatcherConfig struct {
NetworkID watchers.NetworkID // human readable name
ChainID vaa.ChainID // ChainID
MockObservationC chan *common.MessagePublication // Channel to feed this watcher mock observations that it will then make
ObservationDb ObservationDb // If the watcher receives a re-observation request with a TxHash in this map, it will make the corresponding observation in this map.
MockSetC <-chan *common.GuardianSet
NetworkID watchers.NetworkID // human readable name
ChainID vaa.ChainID // ChainID
MockObservationC chan *common.MessagePublication // Channel to feed this watcher mock observations that it will then make
ObservationDb ObservationDb // If the watcher receives a re-observation request with a TxHash in this map, it will make the corresponding observation in this map.
MockSetC <-chan *common.GuardianSet
L1FinalizerRequired watchers.NetworkID // (optional)
}
func (wc *WatcherConfig) GetNetworkID() watchers.NetworkID {
@ -30,7 +31,7 @@ func (wc *WatcherConfig) GetChainID() vaa.ChainID {
}
func (wc *WatcherConfig) RequiredL1Finalizer() watchers.NetworkID {
return ""
return wc.L1FinalizerRequired
}
func (wc *WatcherConfig) SetL1Finalizer(l1finalizer interfaces.L1Finalizer) {
@ -43,5 +44,5 @@ func (wc *WatcherConfig) Create(
setC chan<- *common.GuardianSet,
env common.Environment,
) (interfaces.L1Finalizer, supervisor.Runnable, error) {
return nil, NewWatcherRunnable(msgC, obsvReqC, setC, wc), nil
return MockL1Finalizer{}, NewWatcherRunnable(msgC, obsvReqC, setC, wc), nil
}

View File

@ -42,3 +42,9 @@ func NewWatcherRunnable(
}
}
}
type MockL1Finalizer struct{}
func (f MockL1Finalizer) GetLatestFinalizedBlockNumber() uint64 {
return 0
}