node/node_test: generalize testConsensus()

This commit is contained in:
tbjump 2023-06-08 20:16:49 +00:00 committed by tbjump
parent 575d2fe9a0
commit c3ec2206a2
2 changed files with 22 additions and 8 deletions

View File

@ -157,7 +157,7 @@ func GuardianOptionStatusServer(statusAddr string) *GuardianOption {
// pprof server. NOT necessarily safe to expose publicly - only enable it in dev mode to avoid exposing it by // pprof server. NOT necessarily safe to expose publicly - only enable it in dev mode to avoid exposing it by
// accident. There's benefit to having pprof enabled on production nodes, but we would likely want to expose it // accident. There's benefit to having pprof enabled on production nodes, but we would likely want to expose it
// via a dedicated port listening on localhost, or via the admin UNIX socket. // via a dedicated port listening on localhost, or via the admin UNIX socket.
if g.env == common.UnsafeDevNet { if g.env == common.UnsafeDevNet || g.env == common.GoTest {
// Pass requests to http.DefaultServeMux, which pprof automatically registers with as an import side-effect. // Pass requests to http.DefaultServeMux, which pprof automatically registers with as an import side-effect.
router.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux) router.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
} }

View File

@ -297,12 +297,18 @@ func testStatusServer(ctx context.Context, logger *zap.Logger, statusAddr string
return nil return nil
} }
func TestNodes(t *testing.T) { func TestMain(m *testing.M) {
const testTimeout = time.Second * 60 readiness.NoPanic = true // otherwise we'd panic when running multiple guardians
}
// TestInvalidWatcherConfig tries to instantiate a guardian with various invlid []watchers.WatcherConfig and asserts that it errors
func TestInvalidWatcherConfig(t *testing.T) {
// TODO
}
// TestBasicConsensus tests that a set of guardians can form consensus on certain messages and reject certain other messages
func TestBasicConsensus(t *testing.T) {
const numGuardians = 4 // Quorum will be 3 out of 4 guardians. const numGuardians = 4 // Quorum will be 3 out of 4 guardians.
const guardianSetIndex = 5 // index of the active guardian set (can be anything, just needs to be set to something)
const vaaCheckGuardianIndex uint = 0 // we will query this guardian's publicrpc for VAAs
const adminRpcGuardianIndex uint = 0 // we will query this guardian's adminRpc
msgZeroEmitter := someMessage() msgZeroEmitter := someMessage()
msgZeroEmitter.EmitterAddress = vaa.Address{} msgZeroEmitter.EmitterAddress = vaa.Address{}
@ -350,11 +356,19 @@ func TestNodes(t *testing.T) {
// TODO add a testcase to test the automatic re-observation requests. // TODO add a testcase to test the automatic re-observation requests.
// Need to refactor various usage of wall time to a mockable time first. E.g. using https://github.com/benbjohnson/clock // Need to refactor various usage of wall time to a mockable time first. E.g. using https://github.com/benbjohnson/clock
} }
testConsensus(t, testCases, numGuardians)
}
// testConsensus spins up `numGuardians` guardians and runs & verifies the testCases
func testConsensus(t *testing.T, testCases []testCase, numGuardians int) {
const testTimeout = time.Second * 60
const guardianSetIndex = 5 // index of the active guardian set (can be anything, just needs to be set to something)
const vaaCheckGuardianIndex uint = 0 // we will query this guardian's publicrpc for VAAs
const adminRpcGuardianIndex uint = 0 // we will query this guardian's adminRpc
// Test's main lifecycle context. // Test's main lifecycle context.
rootCtx, rootCtxCancel := context.WithTimeout(context.Background(), testTimeout) rootCtx, rootCtxCancel := context.WithTimeout(context.Background(), testTimeout)
defer rootCtxCancel() defer rootCtxCancel()
readiness.NoPanic = true // otherwise we'd panic when running multiple guardians
zapLogger, zapObserver := setupLogsCapture() zapLogger, zapObserver := setupLogsCapture()