From 3fd2abea8430a1ef8dcb568b1e69ba158fb7e522 Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Mon, 8 May 2023 19:15:48 -0700 Subject: [PATCH] test on edge --- .../integration_tests/consensus_test.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/proxyd/proxyd/integration_tests/consensus_test.go b/proxyd/proxyd/integration_tests/consensus_test.go index da162b0..02da59b 100644 --- a/proxyd/proxyd/integration_tests/consensus_test.go +++ b/proxyd/proxyd/integration_tests/consensus_test.go @@ -135,6 +135,41 @@ func TestConsensus(t *testing.T) { require.Equal(t, 1, len(consensusGroup)) }) + t.Run("prevent using a backend lagging behind 2", func(t *testing.T) { + h1.ResetOverrides() + h2.ResetOverrides() + bg.Consensus.Unban() + + h1.AddOverride(&ms.MethodTemplate{ + Method: "eth_getBlockByNumber", + Block: "latest", + Response: buildGetBlockResponse("0x1", "hash1"), + }) + + h2.AddOverride(&ms.MethodTemplate{ + Method: "eth_getBlockByNumber", + Block: "latest", + Response: buildGetBlockResponse("0x33", "hash0x100"), + }) + h2.AddOverride(&ms.MethodTemplate{ + Method: "eth_getBlockByNumber", + Block: "0x100", + Response: buildGetBlockResponse("0x33", "hash0x100"), + }) + + for _, be := range bg.Backends { + bg.Consensus.UpdateBackend(ctx, be) + } + bg.Consensus.UpdateBackendGroupConsensus(ctx) + + // since we ignored node1, the consensus should be at 0x100 + 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()