Skip to content

Commit

Permalink
Add test for saving raw messages to the database
Browse files Browse the repository at this point in the history
  • Loading branch information
qfrank committed Mar 22, 2024
1 parent 1c5def6 commit 0d167d2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions protocol/common/raw_messages_persistence_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package common

import (
"testing"

"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/sqlite"
"github.com/status-im/status-go/t/helpers"
"github.com/stretchr/testify/require"
)

func TestSaveRawMessage(t *testing.T) {
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
require.NoError(t, err)
require.NoError(t, sqlite.Migrate(db))
p := NewRawMessagesPersistence(db)

pk, err := crypto.GenerateKey()
require.NoError(t, err)

err = p.SaveRawMessage(&RawMessage{
ID: "1",
ResendType: ResendTypeRawMessage,
LocalChatID: "",
CommunityID: []byte("c1"),
CommunityKeyExMsgType: KeyExMsgRekey,
Sender: pk,
})
require.NoError(t, err)
m, err := p.RawMessageByID("1")
require.NoError(t, err)
require.Equal(t, "1", m.ID)
require.Equal(t, ResendTypeRawMessage, m.ResendType)
require.Equal(t, KeyExMsgRekey, m.CommunityKeyExMsgType)
require.Equal(t, "c1", string(m.CommunityID))
require.Equal(t, pk, m.Sender)

}

0 comments on commit 0d167d2

Please sign in to comment.