Skip to content

Commit

Permalink
test(other) fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Dec 8, 2024
1 parent 1b70704 commit 706a809
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
4 changes: 0 additions & 4 deletions state/mock.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package state

import (
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -104,9 +103,6 @@ func (m *MockState) CommitBlock(blk *block.Block, cert *certificate.BlockCertifi
m.lk.Lock()
defer m.lk.Unlock()

if cert.Height() != m.TestStore.LastHeight+1 {
return fmt.Errorf("invalid height")
}
m.TestStore.SaveBlock(blk, cert)

return nil
Expand Down
2 changes: 1 addition & 1 deletion sync/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (f *Firewall) isExpiredMessage(msgData []byte) bool {

// The message is expired, or the consensus height is behind the network's current height.
// In either case, the message is dropped and won't be propagated.
if consensusHeight < f.state.LastBlockHeight()-1 {
if f.state.LastBlockHeight() > 0 && consensusHeight < f.state.LastBlockHeight()-1 {
f.logger.Warn("firewall: expired message", "message height", consensusHeight, "our height", f.state.LastBlockHeight())

return true
Expand Down
18 changes: 4 additions & 14 deletions sync/firewall/firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,20 +438,15 @@ func TestAllowBlockRequest(t *testing.T) {

td := setup(t, conf)

td.state.CommitTestBlocks(10)
testBlk, testCert := td.GenerateTestBlock(2_900_001)
td.state.CommitBlock(testBlk, testCert)

t.Run("expired message", func(t *testing.T) {
msg := makeTestGossipMessage(td.state.LastBlockHeight() - 2)

assert.Equal(t, network.Drop, td.firewall.AllowBlockRequest(msg))
})

t.Run("expired message", func(t *testing.T) {
msg := makeTestGossipMessage(td.state.LastBlockHeight() + 2)

assert.Equal(t, network.Drop, td.firewall.AllowBlockRequest(msg))
})

t.Run("rate limit exceeded", func(t *testing.T) {
msg := makeTestGossipMessage(td.state.LastBlockHeight())

Expand Down Expand Up @@ -480,20 +475,15 @@ func TestAllowConsensusRequest(t *testing.T) {

td := setup(t, conf)

td.state.CommitTestBlocks(10)
testBlk, testCert := td.GenerateTestBlock(2_900_001)
td.state.CommitBlock(testBlk, testCert)

t.Run("expired message", func(t *testing.T) {
msg := makeTestGossipMessage(td.state.LastBlockHeight() - 2)

assert.Equal(t, network.Drop, td.firewall.AllowConsensusRequest(msg))
})

t.Run("expired message", func(t *testing.T) {
msg := makeTestGossipMessage(td.state.LastBlockHeight() + 2)

assert.Equal(t, network.Drop, td.firewall.AllowConsensusRequest(msg))
})

t.Run("rate limit exceeded", func(t *testing.T) {
msg := makeTestGossipMessage(td.state.LastBlockHeight())

Expand Down
8 changes: 4 additions & 4 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestMain(m *testing.M) {
tConfigs[i].Logger.Levels["default"] = "info"
tConfigs[i].Logger.Levels["_state"] = "info"
tConfigs[i].Logger.Levels["_sync"] = "info"
tConfigs[i].Logger.Levels["_consensus"] = "info"
tConfigs[i].Logger.Levels["_consensus"] = "debug"
tConfigs[i].Logger.Levels["_network"] = "info"
tConfigs[i].Logger.Levels["_pool"] = "info"
tConfigs[i].Sync.Firewall.BannedNets = make([]string, 0)
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestMain(m *testing.M) {
genParams.BondInterval = 8
genParams.CommitteeSize = tCommitteeSize
genParams.TransactionToLiveInterval = 8
tGenDoc = genesis.MakeGenesis(time.Now(), accs, vals, genParams)
tGenDoc = genesis.MakeGenesis(time.Now().Add(10*time.Second), accs, vals, genParams)

for i := 0; i < tTotalNodes; i++ {
tNodes[i], _ = node.NewNode(
Expand All @@ -156,10 +156,10 @@ func TestMain(m *testing.M) {
tConfigs[tNodeIdx3].Network.BootstrapAddrStrings = []string{bootstrapAddr}
tConfigs[tNodeIdx4].Network.BootstrapAddrStrings = []string{bootstrapAddr}
}

time.Sleep(1 * time.Second)
}

time.Sleep(10 * time.Second)

tCtx = context.Background()
conn, err := grpc.NewClient(
tGRPCAddress,
Expand Down

0 comments on commit 706a809

Please sign in to comment.