Skip to content

Commit

Permalink
chore_: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kaichaosun committed Jun 11, 2024
1 parent 17dafb5 commit 61e2d71
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions protocol/common/raw_messages_persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,7 @@ func TestUpdateRawMessageSent(t *testing.T) {
require.NoError(t, err)

rawMessageID := "1"
err = p.SaveRawMessage(&RawMessage{
ID: rawMessageID,
ResendType: ResendTypeRawMessage,
LocalChatID: "",
CommunityID: []byte("c1"),
CommunityKeyExMsgType: KeyExMsgRekey,
Sender: pk,
ResendMethod: ResendMethodSendPrivate,
Recipients: []*ecdsa.PublicKey{pk.Public().(*ecdsa.PublicKey)},
Sent: true,
LastSent: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
})
err = p.SaveRawMessage(buildRawMessage(rawMessageID, pk))
require.NoError(t, err)

rawMessage, err := p.RawMessageByID(rawMessageID)
Expand All @@ -79,7 +68,6 @@ func TestUpdateRawMessageSent(t *testing.T) {
m, err := p.RawMessageByID(rawMessageID)
require.NoError(t, err)
require.False(t, m.Sent)
require.Equal(t, m.LastSent, uint64(0))
}

func TestUpdateRawMessageLastSent(t *testing.T) {
Expand All @@ -92,18 +80,7 @@ func TestUpdateRawMessageLastSent(t *testing.T) {
require.NoError(t, err)

rawMessageID := "1"
err = p.SaveRawMessage(&RawMessage{
ID: rawMessageID,
ResendType: ResendTypeRawMessage,
LocalChatID: "",
CommunityID: []byte("c1"),
CommunityKeyExMsgType: KeyExMsgRekey,
Sender: pk,
ResendMethod: ResendMethodSendPrivate,
Recipients: []*ecdsa.PublicKey{pk.Public().(*ecdsa.PublicKey)},
Sent: true,
LastSent: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
})
err = p.SaveRawMessage(buildRawMessage(rawMessageID, pk))
require.NoError(t, err)

rawMessage, err := p.RawMessageByID(rawMessageID)
Expand All @@ -118,3 +95,18 @@ func TestUpdateRawMessageLastSent(t *testing.T) {
require.NoError(t, err)
require.Equal(t, m.LastSent, uint64(0))
}

func buildRawMessage(rawMessageID string, pk *ecdsa.PrivateKey) *RawMessage {
return &RawMessage{
ID: rawMessageID,
ResendType: ResendTypeRawMessage,
LocalChatID: "",
CommunityID: []byte("c1"),
CommunityKeyExMsgType: KeyExMsgRekey,
Sender: pk,
ResendMethod: ResendMethodSendPrivate,
Recipients: []*ecdsa.PublicKey{pk.Public().(*ecdsa.PublicKey)},
Sent: true,
LastSent: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
}
}

0 comments on commit 61e2d71

Please sign in to comment.