-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add proposer test case * Add proposer test case for utilizing old proposal * Simplify view comparison in tests * Add runPropose verification * Add runPrevote verification * Add prevote step timeout * Add runPrecommit verification * Update watchForRoundJumps * Add missing cleanup, broadcast * Clean up the consensus state * Remove leftover comment * Simplify the final timer expiring * Add additional comments to the types * Add support for options * Fix uninitialized logger in tests * Add unit test for non-proposer receiving a fresh proposal * Swap out the useless bloom * Add unit tests for non-proposer receiving invalid proposals * Add unit tests for runPrevote * Add unit tests for runPrecommit * Add unit tests for the cache, options, quorum * Simplify state timeouts * Add unit tests for future round jumps * Add unit tests for dropping messages * Add unit tests for dropping messages
- Loading branch information
1 parent
a0c948d
commit c5b94aa
Showing
16 changed files
with
2,447 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package core | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gnolang/go-tendermint/messages/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMessageCache_AddMessages(t *testing.T) { | ||
t.Parallel() | ||
|
||
isValidFn := func(_ *types.PrevoteMessage) bool { | ||
return true | ||
} | ||
|
||
t.Run("non-duplicate messages", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create the cache | ||
cache := newMessageCache[*types.PrevoteMessage](isValidFn) | ||
|
||
// Generate non-duplicate messages | ||
messages := generatePrevoteMessages(t, 10, &types.View{}, nil) | ||
|
||
// Add the messages | ||
cache.addMessages(messages) | ||
|
||
// Make sure all messages are added | ||
fetchedMessages := cache.getMessages() | ||
|
||
for index, message := range messages { | ||
assert.True(t, message.Equals(fetchedMessages[index])) | ||
} | ||
}) | ||
|
||
t.Run("duplicate messages", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ( | ||
numMessages = 10 | ||
numDuplicates = numMessages / 2 | ||
) | ||
|
||
// Create the cache | ||
cache := newMessageCache[*types.PrevoteMessage](isValidFn) | ||
|
||
// Generate non-duplicate messages | ||
messages := generatePrevoteMessages(t, numMessages, &types.View{}, nil) | ||
|
||
// Make sure some are duplicated | ||
for i := 0; i < numDuplicates; i++ { | ||
messages[i].Sender = []byte("common sender") | ||
} | ||
|
||
expectedMessages := messages[numDuplicates-1:] | ||
|
||
// Add the messages | ||
cache.addMessages(messages) | ||
|
||
// Make sure all messages are added | ||
fetchedMessages := cache.getMessages() | ||
|
||
assert.Len(t, fetchedMessages, len(expectedMessages)) | ||
|
||
for index, message := range expectedMessages { | ||
assert.True(t, message.Equals(fetchedMessages[index])) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package core | ||
|
||
import ( | ||
"io" | ||
"log/slog" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewTendermint_Options(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("Withlogger", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
l := slog.New(slog.NewTextHandler(io.Discard, nil)) | ||
|
||
tm := NewTendermint( | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
WithLogger(l), | ||
) | ||
|
||
assert.Equal(t, tm.logger, l) | ||
}) | ||
|
||
t.Run("WithProposeTimeout", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
timeout := Timeout{ | ||
Initial: 500 * time.Millisecond, | ||
Delta: 0, | ||
} | ||
|
||
tm := NewTendermint( | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
WithProposeTimeout(timeout), | ||
) | ||
|
||
assert.Equal(t, tm.timeouts[propose], timeout) | ||
}) | ||
|
||
t.Run("WithPrevoteTimeout", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
timeout := Timeout{ | ||
Initial: 500 * time.Millisecond, | ||
Delta: 0, | ||
} | ||
|
||
tm := NewTendermint( | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
WithPrevoteTimeout(timeout), | ||
) | ||
|
||
assert.Equal(t, tm.timeouts[prevote], timeout) | ||
}) | ||
|
||
t.Run("WithPrecommitTimeout", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
timeout := Timeout{ | ||
Initial: 500 * time.Millisecond, | ||
Delta: 0, | ||
} | ||
|
||
tm := NewTendermint( | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
WithPrecommitTimeout(timeout), | ||
) | ||
|
||
assert.Equal(t, tm.timeouts[precommit], timeout) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.