Skip to content

Commit

Permalink
fix: add broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad committed Dec 21, 2024
1 parent 5e3a5c8 commit b1a212f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 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)

Check failure on line 442 in sync/firewall/firewall_test.go

View workflow job for this annotation

GitHub Actions / linting

Error return value of `td.state.CommitBlock` is not checked (errcheck)

Check failure on line 442 in sync/firewall/firewall_test.go

View workflow job for this annotation

GitHub Actions / build-linux

Error return value of `td.state.CommitBlock` is not checked (errcheck)

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)

Check failure on line 479 in sync/firewall/firewall_test.go

View workflow job for this annotation

GitHub Actions / linting

Error return value of `td.state.CommitBlock` is not checked (errcheck)

Check failure on line 479 in sync/firewall/firewall_test.go

View workflow job for this annotation

GitHub Actions / build-linux

Error return value of `td.state.CommitBlock` is not checked (errcheck)

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

0 comments on commit b1a212f

Please sign in to comment.