-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for inactivity submission states
- Loading branch information
1 parent
64c02b4
commit 01d69fc
Showing
1 changed file
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package inactivity | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/keep-network/keep-core/pkg/net" | ||
"github.com/keep-network/keep-core/pkg/protocol/state" | ||
) | ||
|
||
func TestReceivedMessages(t *testing.T) { | ||
state := state.NewBaseAsyncState() | ||
|
||
message1 := &claimSignatureMessage{senderID: 1} | ||
message2 := &claimSignatureMessage{senderID: 2} | ||
message3 := &claimSignatureMessage{senderID: 1} | ||
message4 := &claimSignatureMessage{senderID: 3} | ||
message5 := &claimSignatureMessage{senderID: 3} | ||
|
||
state.ReceiveToHistory(newMockNetMessage(message1)) | ||
state.ReceiveToHistory(newMockNetMessage(message2)) | ||
state.ReceiveToHistory(newMockNetMessage(message3)) | ||
state.ReceiveToHistory(newMockNetMessage(message4)) | ||
state.ReceiveToHistory(newMockNetMessage(message5)) | ||
|
||
expectedMessages := []*claimSignatureMessage{message1, message2, message4} | ||
actualType1Messages := receivedMessages[*claimSignatureMessage](state) | ||
if !reflect.DeepEqual(expectedMessages, actualType1Messages) { | ||
t.Errorf( | ||
"unexpected messages\n"+ | ||
"expected: [%v]\n"+ | ||
"actual: [%v]", | ||
expectedMessages, | ||
actualType1Messages, | ||
) | ||
} | ||
} | ||
|
||
type mockNetMessage struct { | ||
payload interface{} | ||
} | ||
|
||
func newMockNetMessage(payload interface{}) *mockNetMessage { | ||
return &mockNetMessage{payload} | ||
} | ||
|
||
func (mnm *mockNetMessage) TransportSenderID() net.TransportIdentifier { | ||
panic("not implemented") | ||
} | ||
|
||
func (mnm *mockNetMessage) SenderPublicKey() []byte { | ||
panic("not implemented") | ||
} | ||
|
||
func (mnm *mockNetMessage) Payload() interface{} { | ||
return mnm.payload | ||
} | ||
|
||
func (mnm *mockNetMessage) Type() string { | ||
payload, ok := mnm.payload.(message) | ||
if !ok { | ||
panic("wrong payload type") | ||
} | ||
|
||
return payload.Type() | ||
} | ||
|
||
func (mnm *mockNetMessage) Seqno() uint64 { | ||
panic("not implemented") | ||
} |