node/node_test: add test for l1finalizer
This commit is contained in:
parent
5b33b047a0
commit
49a3fa44aa
|
@ -12,6 +12,7 @@ import (
|
||||||
math_rand "math/rand"
|
math_rand "math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -48,6 +49,7 @@ import (
|
||||||
const LOCAL_RPC_PORTRANGE_START = 10000
|
const LOCAL_RPC_PORTRANGE_START = 10000
|
||||||
const LOCAL_P2P_PORTRANGE_START = 10100
|
const LOCAL_P2P_PORTRANGE_START = 10100
|
||||||
const LOCAL_STATUS_PORTRANGE_START = 10200
|
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\"}")
|
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)
|
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 {
|
func mockStatusPort(mockGuardianIndex uint) uint {
|
||||||
return mockGuardianIndex + LOCAL_STATUS_PORTRANGE_START
|
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 "" }),
|
GuardianOptionP2P(gs[mockGuardianIndex].p2pKey, networkID, bootstrapPeers, nodeName, false, p2pPort, func() string { return "" }),
|
||||||
GuardianOptionPublicRpcSocket(publicSocketPath, common.GrpcLogDetailFull),
|
GuardianOptionPublicRpcSocket(publicSocketPath, common.GrpcLogDetailFull),
|
||||||
GuardianOptionPublicrpcTcpService(publicRpc, common.GrpcLogDetailFull),
|
GuardianOptionPublicrpcTcpService(publicRpc, common.GrpcLogDetailFull),
|
||||||
|
GuardianOptionPublicWeb(mockPublicWeb(mockGuardianIndex), publicSocketPath, "", false, path.Join(dataDir, "autocert")),
|
||||||
GuardianOptionAdminService(adminSocketPath, nil, nil, rpcMap),
|
GuardianOptionAdminService(adminSocketPath, nil, nil, rpcMap),
|
||||||
GuardianOptionStatusServer(fmt.Sprintf("[::]:%d", mockStatusPort(mockGuardianIndex))),
|
GuardianOptionStatusServer(fmt.Sprintf("[::]:%d", mockStatusPort(mockGuardianIndex))),
|
||||||
GuardianOptionProcessor(),
|
GuardianOptionProcessor(),
|
||||||
|
@ -701,9 +708,14 @@ func TestWatcherConfigs(t *testing.T) {
|
||||||
opts: []*GuardianOption{
|
opts: []*GuardianOption{
|
||||||
GuardianOptionWatchers([]watchers.WatcherConfig{
|
GuardianOptionWatchers([]watchers.WatcherConfig{
|
||||||
&mock.WatcherConfig{
|
&mock.WatcherConfig{
|
||||||
NetworkID: "mock",
|
NetworkID: "mock1",
|
||||||
ChainID: vaa.ChainIDSolana,
|
ChainID: vaa.ChainIDSolana,
|
||||||
},
|
},
|
||||||
|
&mock.WatcherConfig{
|
||||||
|
NetworkID: "mock2",
|
||||||
|
ChainID: vaa.ChainIDEthereum,
|
||||||
|
L1FinalizerRequired: "mock1",
|
||||||
|
},
|
||||||
}, nil),
|
}, nil),
|
||||||
},
|
},
|
||||||
err: "",
|
err: "",
|
||||||
|
@ -724,6 +736,19 @@ func TestWatcherConfigs(t *testing.T) {
|
||||||
},
|
},
|
||||||
err: "NetworkID already configured: mock",
|
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)
|
testGuardianConfigurations(t, tc)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ type WatcherConfig struct {
|
||||||
MockObservationC chan *common.MessagePublication // Channel to feed this watcher mock observations that it will then make
|
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.
|
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
|
MockSetC <-chan *common.GuardianSet
|
||||||
|
L1FinalizerRequired watchers.NetworkID // (optional)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WatcherConfig) GetNetworkID() watchers.NetworkID {
|
func (wc *WatcherConfig) GetNetworkID() watchers.NetworkID {
|
||||||
|
@ -30,7 +31,7 @@ func (wc *WatcherConfig) GetChainID() vaa.ChainID {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WatcherConfig) RequiredL1Finalizer() watchers.NetworkID {
|
func (wc *WatcherConfig) RequiredL1Finalizer() watchers.NetworkID {
|
||||||
return ""
|
return wc.L1FinalizerRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WatcherConfig) SetL1Finalizer(l1finalizer interfaces.L1Finalizer) {
|
func (wc *WatcherConfig) SetL1Finalizer(l1finalizer interfaces.L1Finalizer) {
|
||||||
|
@ -43,5 +44,5 @@ func (wc *WatcherConfig) Create(
|
||||||
setC chan<- *common.GuardianSet,
|
setC chan<- *common.GuardianSet,
|
||||||
env common.Environment,
|
env common.Environment,
|
||||||
) (interfaces.L1Finalizer, supervisor.Runnable, error) {
|
) (interfaces.L1Finalizer, supervisor.Runnable, error) {
|
||||||
return nil, NewWatcherRunnable(msgC, obsvReqC, setC, wc), nil
|
return MockL1Finalizer{}, NewWatcherRunnable(msgC, obsvReqC, setC, wc), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,3 +42,9 @@ func NewWatcherRunnable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MockL1Finalizer struct{}
|
||||||
|
|
||||||
|
func (f MockL1Finalizer) GetLatestFinalizedBlockNumber() uint64 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue