From 53e4a369abe70c0fdc446fbe12d9b082f43435a2 Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Tue, 9 May 2023 14:20:23 -0700 Subject: [PATCH] test edge cases --- .../integration_tests/consensus_test.go | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/proxyd/proxyd/integration_tests/consensus_test.go b/proxyd/proxyd/integration_tests/consensus_test.go index 02da59b..729fade 100644 --- a/proxyd/proxyd/integration_tests/consensus_test.go +++ b/proxyd/proxyd/integration_tests/consensus_test.go @@ -135,7 +135,7 @@ func TestConsensus(t *testing.T) { require.Equal(t, 1, len(consensusGroup)) }) - t.Run("prevent using a backend lagging behind 2", func(t *testing.T) { + t.Run("prevent using a backend lagging behind - at limit", func(t *testing.T) { h1.ResetOverrides() h2.ResetOverrides() bg.Consensus.Unban() @@ -146,6 +146,7 @@ func TestConsensus(t *testing.T) { Response: buildGetBlockResponse("0x1", "hash1"), }) + // 0x1 + 50 = 0x33 h2.AddOverride(&ms.MethodTemplate{ Method: "eth_getBlockByNumber", Block: "latest", @@ -170,6 +171,41 @@ func TestConsensus(t *testing.T) { require.Equal(t, 2, len(consensusGroup)) }) + t.Run("prevent using a backend lagging behind - one before limit", func(t *testing.T) { + h1.ResetOverrides() + h2.ResetOverrides() + bg.Consensus.Unban() + + h1.AddOverride(&ms.MethodTemplate{ + Method: "eth_getBlockByNumber", + Block: "latest", + Response: buildGetBlockResponse("0x1", "hash1"), + }) + + // 0x1 + 49 = 0x32 + h2.AddOverride(&ms.MethodTemplate{ + Method: "eth_getBlockByNumber", + Block: "latest", + Response: buildGetBlockResponse("0x32", "hash0x100"), + }) + h2.AddOverride(&ms.MethodTemplate{ + Method: "eth_getBlockByNumber", + Block: "0x100", + Response: buildGetBlockResponse("0x32", "hash0x100"), + }) + + for _, be := range bg.Backends { + bg.Consensus.UpdateBackend(ctx, be) + } + bg.Consensus.UpdateBackendGroupConsensus(ctx) + + require.Equal(t, "0x1", bg.Consensus.GetConsensusBlockNumber().String()) + + consensusGroup := bg.Consensus.GetConsensusGroup() + + require.Equal(t, 2, len(consensusGroup)) + }) + t.Run("prevent using a backend not in sync", func(t *testing.T) { h1.ResetOverrides() h2.ResetOverrides()