Address linter issues

This commit is contained in:
Andrea Maria Piana 2022-03-28 11:10:40 +01:00
parent 3b3921f483
commit 8a5f77dc37
22 changed files with 90 additions and 85 deletions

View File

@ -88,7 +88,7 @@ func TestVerifyAccountPassword(t *testing.T) {
require.FailNow(t, fmt.Sprintf("unexpected error: expected \n'%v', got \n'%v'", testCase.expectedError, err)) require.FailNow(t, fmt.Sprintf("unexpected error: expected \n'%v', got \n'%v'", testCase.expectedError, err))
} }
if err == nil { if err == nil {
if accountKey == nil { if accountKey == nil { // nolint: staticcheck
require.Fail(t, "no error reported, but account key is missing") require.Fail(t, "no error reported, but account key is missing")
} }
accountAddress := types.BytesToAddress(types.FromHex(testCase.address)) accountAddress := types.BytesToAddress(types.FromHex(testCase.address))

View File

@ -1022,7 +1022,7 @@ func (b *GethStatusBackend) ConnectionChange(typ string, expensive bool) {
defer b.mu.Unlock() defer b.mu.Unlock()
state := connection.State{ state := connection.State{
Type: connection.NewConnectionType(typ), Type: connection.NewType(typ),
Expensive: expensive, Expensive: expensive,
} }
if typ == connection.None { if typ == connection.None {

View File

@ -239,7 +239,7 @@ func (db *Database) SetToProcessedByIDs(ids []int) (err error) {
} }
in = in[:len(in)-1] + ")" in = in[:len(in)-1] + ")"
update, err = tx.Prepare("UPDATE app_metrics SET processed = 1 WHERE id IN " + in) update, err = tx.Prepare("UPDATE app_metrics SET processed = 1 WHERE id IN " + in) // nolint: gosec
if err != nil { if err != nil {
return err return err
} }

View File

@ -9,17 +9,17 @@ import (
// //
// Zero value represents default assumption about network (online and unknown type). // Zero value represents default assumption about network (online and unknown type).
type State struct { type State struct {
Offline bool `json:"offline"` Offline bool `json:"offline"`
Type connectionType `json:"type"` Type Type `json:"type"`
Expensive bool `json:"expensive"` Expensive bool `json:"expensive"`
} }
// connectionType represents description of available // Type represents description of available
// connection types as reported by React Native (see // connection types as reported by React Native (see
// https://facebook.github.io/react-native/docs/netinfo.html) // https://facebook.github.io/react-native/docs/netinfo.html)
// We're interested mainly in 'wifi' and 'cellular', but // We're interested mainly in 'wifi' and 'cellular', but
// other types are also may be used. // other types are also may be used.
type connectionType byte type Type byte
const ( const (
Offline = "offline" Offline = "offline"
@ -29,8 +29,8 @@ const (
None = "none" None = "none"
) )
// NewConnectionType creates new connectionType from string. // NewType creates new Type from string.
func NewConnectionType(s string) connectionType { func NewType(s string) Type {
switch s { switch s {
case Cellular: case Cellular:
return connectionCellular return connectionCellular
@ -41,11 +41,11 @@ func NewConnectionType(s string) connectionType {
return connectionUnknown return connectionUnknown
} }
// ConnectionType constants // Type constants
const ( const (
connectionUnknown connectionType = iota connectionUnknown Type = iota
connectionCellular // cellular, LTE, 4G, 3G, EDGE, etc. connectionCellular // cellular, LTE, 4G, 3G, EDGE, etc.
connectionWifi // WIFI or iOS simulator connectionWifi // WIFI or iOS simulator
) )
func (c State) IsExpensive() bool { func (c State) IsExpensive() bool {

View File

@ -3,15 +3,15 @@ package connection
import "testing" import "testing"
func TestConnectionType(t *testing.T) { func TestConnectionType(t *testing.T) {
c := NewConnectionType("wifi") c := NewType("wifi")
if c != connectionWifi { if c != connectionWifi {
t.Fatalf("Wrong connection type: %v", c) t.Fatalf("Wrong connection type: %v", c)
} }
c = NewConnectionType("cellular") c = NewType("cellular")
if c != connectionCellular { if c != connectionCellular {
t.Fatalf("Wrong connection type: %v", c) t.Fatalf("Wrong connection type: %v", c)
} }
c = NewConnectionType("bluetooth") c = NewType("bluetooth")
if c != connectionUnknown { if c != connectionUnknown {
t.Fatalf("Wrong connection type: %v", c) t.Fatalf("Wrong connection type: %v", c)
} }

View File

@ -44,9 +44,9 @@ func TestGetExistingHistory(t *testing.T) {
func TestNewHistoryRequest(t *testing.T) { func TestNewHistoryRequest(t *testing.T) {
store := createInMemStore(t) store := createInMemStore(t)
id := types.Hash{1} id := types.Hash{1}
req, err := store.GetRequest(id) _, err := store.GetRequest(id)
require.Error(t, err) require.Error(t, err)
req = store.NewRequest() req := store.NewRequest()
req.ID = id req.ID = id
th, err := store.GetHistory(types.TopicType{1}, time.Hour) th, err := store.GetHistory(types.TopicType{1}, time.Hour)

1
go.mod
View File

@ -74,7 +74,6 @@ require (
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e golang.org/x/crypto v0.0.0-20211202192323-5770296d904e
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
golang.org/x/tools v0.1.2 // indirect golang.org/x/tools v0.1.2 // indirect
google.golang.org/protobuf v1.27.1
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0

View File

@ -913,7 +913,7 @@ func (m *Manager) SetPrivateKey(id []byte, privKey *ecdsa.PrivateKey) error {
return m.persistence.SetPrivateKey(id, privKey) return m.persistence.SetPrivateKey(id, privKey)
} }
func (m *Manager) GetSyncedRawCommunity(id []byte) (*rawCommunityRow, error) { func (m *Manager) GetSyncedRawCommunity(id []byte) (*RawCommunityRow, error) {
return m.persistence.getSyncedRawCommunity(id) return m.persistence.getSyncedRawCommunity(id)
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/protobuf"
) )
type rawCommunityRow struct { type RawCommunityRow struct {
ID []byte ID []byte
PrivateKey []byte PrivateKey []byte
Description []byte Description []byte
@ -16,8 +16,8 @@ type rawCommunityRow struct {
Muted bool Muted bool
} }
func fromSyncCommunityProtobuf(syncCommProto *protobuf.SyncCommunity) rawCommunityRow { func fromSyncCommunityProtobuf(syncCommProto *protobuf.SyncCommunity) RawCommunityRow {
return rawCommunityRow{ return RawCommunityRow{
ID: syncCommProto.Id, ID: syncCommProto.Id,
PrivateKey: syncCommProto.PrivateKey, PrivateKey: syncCommProto.PrivateKey,
Description: syncCommProto.Description, Description: syncCommProto.Description,
@ -28,8 +28,8 @@ func fromSyncCommunityProtobuf(syncCommProto *protobuf.SyncCommunity) rawCommuni
} }
} }
func (p *Persistence) scanRowToStruct(rowScan func(dest ...interface{}) error) (*rawCommunityRow, error) { func (p *Persistence) scanRowToStruct(rowScan func(dest ...interface{}) error) (*RawCommunityRow, error) {
rcr := new(rawCommunityRow) rcr := new(RawCommunityRow)
syncedAt := sql.NullTime{} syncedAt := sql.NullTime{}
err := rowScan( err := rowScan(
@ -52,7 +52,7 @@ func (p *Persistence) scanRowToStruct(rowScan func(dest ...interface{}) error) (
return rcr, nil return rcr, nil
} }
func (p *Persistence) getAllCommunitiesRaw() (rcrs []*rawCommunityRow, err error) { func (p *Persistence) getAllCommunitiesRaw() (rcrs []*RawCommunityRow, err error) {
var rows *sql.Rows var rows *sql.Rows
// Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing. // Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing.
rows, err = p.db.Query(`SELECT * FROM communities_communities`) rows, err = p.db.Query(`SELECT * FROM communities_communities`)
@ -81,19 +81,19 @@ func (p *Persistence) getAllCommunitiesRaw() (rcrs []*rawCommunityRow, err error
return rcrs, nil return rcrs, nil
} }
func (p *Persistence) getRawCommunityRow(id []byte) (*rawCommunityRow, error) { func (p *Persistence) getRawCommunityRow(id []byte) (*RawCommunityRow, error) {
// Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing. // Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing.
qr := p.db.QueryRow(`SELECT * FROM communities_communities WHERE id = ?`, id) qr := p.db.QueryRow(`SELECT * FROM communities_communities WHERE id = ?`, id)
return p.scanRowToStruct(qr.Scan) return p.scanRowToStruct(qr.Scan)
} }
func (p *Persistence) getSyncedRawCommunity(id []byte) (*rawCommunityRow, error) { func (p *Persistence) getSyncedRawCommunity(id []byte) (*RawCommunityRow, error) {
// Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing. // Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing.
qr := p.db.QueryRow(`SELECT * FROM communities_communities WHERE id = ? AND synced_at > 0`, id) qr := p.db.QueryRow(`SELECT * FROM communities_communities WHERE id = ? AND synced_at > 0`, id)
return p.scanRowToStruct(qr.Scan) return p.scanRowToStruct(qr.Scan)
} }
func (p *Persistence) saveRawCommunityRow(rawCommRow rawCommunityRow) error { func (p *Persistence) saveRawCommunityRow(rawCommRow RawCommunityRow) error {
_, err := p.db.Exec( _, err := p.db.Exec(
`INSERT INTO communities_communities ("id", "private_key", "description", "joined", "verified", "synced_at", "muted") VALUES (?, ?, ?, ?, ?, ?, ?)`, `INSERT INTO communities_communities ("id", "private_key", "description", "joined", "verified", "synced_at", "muted") VALUES (?, ?, ?, ?, ?, ?, ?)`,
rawCommRow.ID, rawCommRow.ID,
@ -107,7 +107,7 @@ func (p *Persistence) saveRawCommunityRow(rawCommRow rawCommunityRow) error {
return err return err
} }
func (p *Persistence) saveRawCommunityRowWithoutSyncedAt(rawCommRow rawCommunityRow) error { func (p *Persistence) saveRawCommunityRowWithoutSyncedAt(rawCommRow RawCommunityRow) error {
_, err := p.db.Exec( _, err := p.db.Exec(
`INSERT INTO communities_communities ("id", "private_key", "description", "joined", "verified", "muted") VALUES (?, ?, ?, ?, ?, ?)`, `INSERT INTO communities_communities ("id", "private_key", "description", "joined", "verified", "muted") VALUES (?, ?, ?, ?, ?, ?)`,
rawCommRow.ID, rawCommRow.ID,

View File

@ -567,6 +567,7 @@ func (s *MessengerCommunitiesSuite) TestImportCommunity() {
} }
response, err = s.bob.CreateCommunityCategory(category) response, err = s.bob.CreateCommunityCategory(category)
s.Require().NoError(err)
community = response.Communities()[0] community = response.Communities()[0]
privateKey, err := s.bob.ExportCommunity(community.ID()) privateKey, err := s.bob.ExportCommunity(community.ID())

View File

@ -714,7 +714,8 @@ func (db sqlitePersistence) AllMessagesFromChatsAndCommunitiesWhichMatchTerm(com
allFields := db.tableUserMessagesAllFieldsJoin() allFields := db.tableUserMessagesAllFieldsJoin()
finalQuery := fmt.Sprintf(` finalQuery := fmt.Sprintf( // nolint: gosec
`
SELECT SELECT
%s, %s,
substr('0000000000000000000000000000000000000000000000000000000000000000' || m1.clock_value, -64, 64) || m1.id as cursor substr('0000000000000000000000000000000000000000000000000000000000000000' || m1.clock_value, -64, 64) || m1.id as cursor

View File

@ -369,7 +369,7 @@ func NewMessenger(
pushNotificationClientConfig = &pushnotificationclient.Config{} pushNotificationClientConfig = &pushnotificationclient.Config{}
} }
sqlitePersistence := NewSQLitePersistence(database) sqlitePersistence := newSQLitePersistence(database)
// Overriding until we handle different identities // Overriding until we handle different identities
pushNotificationClientConfig.Identity = identity pushNotificationClientConfig.Identity = identity
pushNotificationClientConfig.Logger = logger pushNotificationClientConfig.Logger = logger

View File

@ -28,7 +28,7 @@ type sqlitePersistence struct {
db *sql.DB db *sql.DB
} }
func NewSQLitePersistence(db *sql.DB) *sqlitePersistence { func newSQLitePersistence(db *sql.DB) *sqlitePersistence {
return &sqlitePersistence{common.NewRawMessagesPersistence(db), db} return &sqlitePersistence{common.NewRawMessagesPersistence(db), db}
} }

View File

@ -29,7 +29,7 @@ func TestTableUserMessagesAllFieldsCount(t *testing.T) {
func TestSaveMessages(t *testing.T) { func TestSaveMessages(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
id := strconv.Itoa(i) id := strconv.Itoa(i)
@ -45,7 +45,7 @@ func TestSaveMessages(t *testing.T) {
func TestMessagesByIDs(t *testing.T) { func TestMessagesByIDs(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
var ids []string var ids []string
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
@ -63,7 +63,7 @@ func TestMessagesByIDs(t *testing.T) {
func TestMessageByID(t *testing.T) { func TestMessageByID(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
id := "1" id := "1"
err = insertMinimalMessage(p, id) err = insertMinimalMessage(p, id)
@ -77,7 +77,7 @@ func TestMessageByID(t *testing.T) {
func TestMessagesExist(t *testing.T) { func TestMessagesExist(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
err = insertMinimalMessage(p, "1") err = insertMinimalMessage(p, "1")
require.NoError(t, err) require.NoError(t, err)
@ -101,7 +101,7 @@ func TestMessagesExist(t *testing.T) {
func TestMessageByChatID(t *testing.T) { func TestMessageByChatID(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
chatID := testPublicChatID chatID := testPublicChatID
count := 1000 count := 1000
pageSize := 50 pageSize := 50
@ -308,7 +308,7 @@ func TestPinMessageByChatID(t *testing.T) {
func TestMessageReplies(t *testing.T) { func TestMessageReplies(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
chatID := testPublicChatID chatID := testPublicChatID
message1 := &common.Message{ message1 := &common.Message{
ID: "id-1", ID: "id-1",
@ -363,7 +363,7 @@ func TestMessageReplies(t *testing.T) {
func TestMessageByChatIDWithTheSameClocks(t *testing.T) { func TestMessageByChatIDWithTheSameClocks(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
chatID := testPublicChatID chatID := testPublicChatID
clockValues := []uint64{10, 10, 9, 9, 9, 11, 12, 11, 100000, 6, 4, 5, 5, 5, 5} clockValues := []uint64{10, 10, 9, 9, 9, 11, 12, 11, 100000, 6, 4, 5, 5, 5, 5}
count := len(clockValues) count := len(clockValues)
@ -423,7 +423,7 @@ func TestMessageByChatIDWithTheSameClocks(t *testing.T) {
func TestDeleteMessageByID(t *testing.T) { func TestDeleteMessageByID(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
id := "1" id := "1"
err = insertMinimalMessage(p, id) err = insertMinimalMessage(p, id)
@ -443,7 +443,7 @@ func TestDeleteMessageByID(t *testing.T) {
func TestDeleteMessagesByChatID(t *testing.T) { func TestDeleteMessagesByChatID(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
err = insertMinimalMessage(p, "1") err = insertMinimalMessage(p, "1")
require.NoError(t, err) require.NoError(t, err)
@ -468,7 +468,7 @@ func TestMarkMessageSeen(t *testing.T) {
chatID := "test-chat" chatID := "test-chat"
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
id := "1" id := "1"
err = insertMinimalMessage(p, id) err = insertMinimalMessage(p, id)
@ -491,7 +491,7 @@ func TestMarkMessageSeen(t *testing.T) {
func TestUpdateMessageOutgoingStatus(t *testing.T) { func TestUpdateMessageOutgoingStatus(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
id := "1" id := "1"
err = insertMinimalMessage(p, id) err = insertMinimalMessage(p, id)
@ -508,7 +508,7 @@ func TestUpdateMessageOutgoingStatus(t *testing.T) {
func TestMessagesIDsByType(t *testing.T) { func TestMessagesIDsByType(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
ids, err := p.RawMessagesIDsByType(protobuf.ApplicationMetadataMessage_CHAT_MESSAGE) ids, err := p.RawMessagesIDsByType(protobuf.ApplicationMetadataMessage_CHAT_MESSAGE)
require.NoError(t, err) require.NoError(t, err)
@ -536,7 +536,7 @@ func TestMessagesIDsByType(t *testing.T) {
func TestExpiredMessagesIDs(t *testing.T) { func TestExpiredMessagesIDs(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
ids, err := p.ExpiredMessagesIDs(messageResendMaxCount) ids, err := p.ExpiredMessagesIDs(messageResendMaxCount)
require.NoError(t, err) require.NoError(t, err)
@ -568,7 +568,7 @@ func TestExpiredMessagesIDs(t *testing.T) {
func TestPersistenceEmojiReactions(t *testing.T) { func TestPersistenceEmojiReactions(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
// reverse order as we use DESC // reverse order as we use DESC
id1 := "1" id1 := "1"
id2 := "2" id2 := "2"
@ -695,7 +695,7 @@ func minimalRawMessage(id string, messageType protobuf.ApplicationMetadataMessag
func TestMessagesAudioDurationMsNull(t *testing.T) { func TestMessagesAudioDurationMsNull(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
id := "message-id-1" id := "message-id-1"
err = insertMinimalMessage(p, id) err = insertMinimalMessage(p, id)
@ -716,7 +716,7 @@ func TestMessagesAudioDurationMsNull(t *testing.T) {
func TestSaveChat(t *testing.T) { func TestSaveChat(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
chat := CreatePublicChat("test-chat", &testTimeSource{}) chat := CreatePublicChat("test-chat", &testTimeSource{})
chat.LastMessage = &common.Message{} chat.LastMessage = &common.Message{}
@ -732,7 +732,7 @@ func TestSaveMentions(t *testing.T) {
chatID := testPublicChatID chatID := testPublicChatID
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
key, err := crypto.GenerateKey() key, err := crypto.GenerateKey()
require.NoError(t, err) require.NoError(t, err)
@ -760,7 +760,7 @@ func TestSaveMentions(t *testing.T) {
func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) { func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
chatID := "0xabcd1234" chatID := "0xabcd1234"
hash := []byte{0x1} hash := []byte{0x1}
@ -788,7 +788,7 @@ func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) {
func TestSaveContactIdentityImage(t *testing.T) { func TestSaveContactIdentityImage(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
key, err := crypto.GenerateKey() key, err := crypto.GenerateKey()
require.NoError(t, err) require.NoError(t, err)
@ -837,7 +837,7 @@ func TestSaveLinks(t *testing.T) {
chatID := testPublicChatID chatID := testPublicChatID
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
require.NoError(t, err) require.NoError(t, err)
@ -863,7 +863,7 @@ func TestSaveLinks(t *testing.T) {
func TestHideMessage(t *testing.T) { func TestHideMessage(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
chatID := testPublicChatID chatID := testPublicChatID
message := &common.Message{ message := &common.Message{
ID: "id-1", ID: "id-1",
@ -894,7 +894,7 @@ func TestHideMessage(t *testing.T) {
func TestDeactivatePublicChat(t *testing.T) { func TestDeactivatePublicChat(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
publicChatID := "public-chat-id" publicChatID := "public-chat-id"
var currentClockValue uint64 = 10 var currentClockValue uint64 = 10
@ -962,7 +962,7 @@ func TestDeactivateOneToOneChat(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
var currentClockValue uint64 = 10 var currentClockValue uint64 = 10
timesource := &testTimeSource{} timesource := &testTimeSource{}
@ -1038,7 +1038,7 @@ func TestConfirmations(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
confirmation1 := &common.RawMessageConfirmation{ confirmation1 := &common.RawMessageConfirmation{
DataSyncID: dataSyncID1, DataSyncID: dataSyncID1,
@ -1101,7 +1101,7 @@ func TestConfirmationsAtLeastOne(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
confirmation1 := &common.RawMessageConfirmation{ confirmation1 := &common.RawMessageConfirmation{
DataSyncID: dataSyncID1, DataSyncID: dataSyncID1,
@ -1142,7 +1142,7 @@ func TestActivityCenterPersistence(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
chat := CreatePublicChat("test-chat", &testTimeSource{}) chat := CreatePublicChat("test-chat", &testTimeSource{})
message := &common.Message{} message := &common.Message{}
@ -1279,7 +1279,7 @@ func TestActivityCenterPersistence(t *testing.T) {
func TestSaveCommunityChat(t *testing.T) { func TestSaveCommunityChat(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
identity := &protobuf.ChatIdentity{ identity := &protobuf.ChatIdentity{
DisplayName: "community-chat-name", DisplayName: "community-chat-name",
@ -1307,7 +1307,7 @@ func TestSaveCommunityChat(t *testing.T) {
func TestHasPendingNotificationsForChatSanityCheck(t *testing.T) { func TestHasPendingNotificationsForChatSanityCheck(t *testing.T) {
db, err := openTestDB() db, err := openTestDB()
require.NoError(t, err) require.NoError(t, err)
p := NewSQLitePersistence(db) p := newSQLitePersistence(db)
result, err := p.HasPendingNotificationsForChat("test-chat-id") result, err := p.HasPendingNotificationsForChat("test-chat-id")
require.NoError(t, err) require.NoError(t, err)

View File

@ -100,7 +100,8 @@ func TestCommunitiesMigrationNotDirty(t *testing.T) {
require.Error(t, err) require.Error(t, err)
// Set dirty to false // Set dirty to false
_, err = db.Exec(`UPDATE ` + migrationsTable + ` SET dirty = 0`) // Disabling linter as migrationsTable is controlled by us
_, err = db.Exec(`UPDATE ` + migrationsTable + ` SET dirty = 0`) // nolint: gosec
require.NoError(t, err) require.NoError(t, err)
// Version and dirty should be true and set to communities migration // Version and dirty should be true and set to communities migration

View File

@ -15,7 +15,8 @@ func newSQLitePersistence(db *sql.DB, tableName string) *SqlitePersistence {
} }
func (s *SqlitePersistence) Add(chatID string, key []byte) error { func (s *SqlitePersistence) Add(chatID string, key []byte) error {
statement := fmt.Sprintf("INSERT INTO %s(chat_id, key) VALUES(?, ?)", s.tableName) // tableName controlled by us
statement := fmt.Sprintf("INSERT INTO %s(chat_id, key) VALUES(?, ?)", s.tableName) // nolint:gosec
stmt, err := s.db.Prepare(statement) stmt, err := s.db.Prepare(statement)
if err != nil { if err != nil {
return err return err
@ -29,7 +30,8 @@ func (s *SqlitePersistence) Add(chatID string, key []byte) error {
func (s *SqlitePersistence) All() (map[string][]byte, error) { func (s *SqlitePersistence) All() (map[string][]byte, error) {
keys := make(map[string][]byte) keys := make(map[string][]byte)
statement := fmt.Sprintf("SELECT chat_id, key FROM %s", s.tableName) // tableName controlled by us
statement := fmt.Sprintf("SELECT chat_id, key FROM %s", s.tableName) // nolint: gosec
stmt, err := s.db.Prepare(statement) stmt, err := s.db.Prepare(statement)
if err != nil { if err != nil {

View File

@ -43,7 +43,7 @@ func NewAPI(rpcClient *rpc.Client, accountsManager *account.GethManager, rpcFilt
} }
} }
type uri struct { type URI struct {
Scheme string Scheme string
Host string Host string
Path string Path string
@ -450,7 +450,7 @@ func (api *API) SetPubKeyEstimate(ctx context.Context, chainID uint64, txArgs tr
return ethClient.EstimateGas(ctx, callMsg) return ethClient.EstimateGas(ctx, callMsg)
} }
func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string) (*uri, error) { func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string) (*URI, error) {
scheme := "https" scheme := "https"
contentHash, err := api.ContentHash(ctx, chainID, username) contentHash, err := api.ContentHash(ctx, chainID, username)
if err != nil { if err != nil {
@ -458,7 +458,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
} }
if len(contentHash) == 0 { if len(contentHash) == 0 {
return &uri{}, nil return &URI{}, nil
} }
data, codec, err := multicodec.RemoveCodec(contentHash) data, codec, err := multicodec.RemoveCodec(contentHash)
@ -481,7 +481,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
return nil, errors.Wrap(err, "failed to obtain base36 representation") return nil, errors.Wrap(err, "failed to obtain base36 representation")
} }
host := str + ".ipfs.infura-ipfs.io/" host := str + ".ipfs.infura-ipfs.io/"
return &uri{scheme, host, ""}, nil return &URI{scheme, host, ""}, nil
case "ipns-ns": case "ipns-ns":
id, offset := binary.Uvarint(data) id, offset := binary.Uvarint(data)
if id == 0 { if id == 0 {
@ -497,7 +497,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
return nil, err return nil, err
} }
return &uri{scheme, string(decodedMHash.Digest), ""}, nil return &URI{scheme, string(decodedMHash.Digest), ""}, nil
case "swarm-ns": case "swarm-ns":
id, offset := binary.Uvarint(data) id, offset := binary.Uvarint(data)
if id == 0 { if id == 0 {
@ -512,7 +512,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
return nil, err return nil, err
} }
path := "/bzz:/" + hex.EncodeToString(decodedMHash.Digest) + "/" path := "/bzz:/" + hex.EncodeToString(decodedMHash.Digest) + "/"
return &uri{scheme, "swarm-gateways.net", path}, nil return &URI{scheme, "swarm-gateways.net", path}, nil
default: default:
return nil, fmt.Errorf("unknown codec name %s", codecName) return nil, fmt.Errorf("unknown codec name %s", codecName)
} }

View File

@ -61,7 +61,7 @@ func (e *Envelope) rlpWithoutNonce() []byte {
// NewEnvelope wraps a Waku message with expiration and destination data // NewEnvelope wraps a Waku message with expiration and destination data
// included into an envelope for network forwarding. // included into an envelope for network forwarding.
func NewEnvelope(ttl uint32, topic TopicType, msg *sentMessage, now time.Time) *Envelope { func NewEnvelope(ttl uint32, topic TopicType, msg *SentMessage, now time.Time) *Envelope {
env := Envelope{ env := Envelope{
Expiry: uint32(now.Add(time.Second * time.Duration(ttl)).Unix()), Expiry: uint32(now.Add(time.Second * time.Duration(ttl)).Unix()),
TTL: ttl, TTL: ttl,

View File

@ -53,7 +53,7 @@ type MessageParams struct {
// SentMessage represents an end-user data packet to transmit through the // SentMessage represents an end-user data packet to transmit through the
// Waku protocol. These are wrapped into Envelopes that need not be // Waku protocol. These are wrapped into Envelopes that need not be
// understood by intermediate nodes, just forwarded. // understood by intermediate nodes, just forwarded.
type sentMessage struct { type SentMessage struct {
Raw []byte Raw []byte
} }
@ -148,9 +148,9 @@ func (msg *ReceivedMessage) isAsymmetricEncryption() bool {
} }
// NewSentMessage creates and initializes a non-signed, non-encrypted Waku message. // NewSentMessage creates and initializes a non-signed, non-encrypted Waku message.
func NewSentMessage(params *MessageParams) (*sentMessage, error) { func NewSentMessage(params *MessageParams) (*SentMessage, error) {
const payloadSizeFieldMaxSize = 4 const payloadSizeFieldMaxSize = 4
msg := sentMessage{} msg := SentMessage{}
msg.Raw = make([]byte, 1, msg.Raw = make([]byte, 1,
flagsLength+payloadSizeFieldMaxSize+len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit) flagsLength+payloadSizeFieldMaxSize+len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit)
msg.Raw[0] = 0 // set all the flags to zero msg.Raw[0] = 0 // set all the flags to zero
@ -161,7 +161,7 @@ func NewSentMessage(params *MessageParams) (*sentMessage, error) {
} }
// addPayloadSizeField appends the auxiliary field containing the size of payload // addPayloadSizeField appends the auxiliary field containing the size of payload
func (msg *sentMessage) addPayloadSizeField(payload []byte) { func (msg *SentMessage) addPayloadSizeField(payload []byte) {
fieldSize := getSizeOfPayloadSizeField(payload) fieldSize := getSizeOfPayloadSizeField(payload)
field := make([]byte, 4) field := make([]byte, 4)
binary.LittleEndian.PutUint32(field, uint32(len(payload))) binary.LittleEndian.PutUint32(field, uint32(len(payload)))
@ -181,7 +181,7 @@ func getSizeOfPayloadSizeField(payload []byte) int {
// appendPadding appends the padding specified in params. // appendPadding appends the padding specified in params.
// If no padding is provided in params, then random padding is generated. // If no padding is provided in params, then random padding is generated.
func (msg *sentMessage) appendPadding(params *MessageParams) error { func (msg *SentMessage) appendPadding(params *MessageParams) error {
if len(params.Padding) != 0 { if len(params.Padding) != 0 {
// padding data was provided by the Dapp, just use it as is // padding data was provided by the Dapp, just use it as is
msg.Raw = append(msg.Raw, params.Padding...) msg.Raw = append(msg.Raw, params.Padding...)
@ -208,7 +208,7 @@ func (msg *sentMessage) appendPadding(params *MessageParams) error {
// sign calculates and sets the cryptographic signature for the message, // sign calculates and sets the cryptographic signature for the message,
// also setting the sign flag. // also setting the sign flag.
func (msg *sentMessage) sign(key *ecdsa.PrivateKey) error { func (msg *SentMessage) sign(key *ecdsa.PrivateKey) error {
if IsMessageSigned(msg.Raw[0]) { if IsMessageSigned(msg.Raw[0]) {
// this should not happen, but no reason to panic // this should not happen, but no reason to panic
log.Error("failed to sign the message: already signed") log.Error("failed to sign the message: already signed")
@ -227,7 +227,7 @@ func (msg *sentMessage) sign(key *ecdsa.PrivateKey) error {
} }
// encryptAsymmetric encrypts a message with a public key. // encryptAsymmetric encrypts a message with a public key.
func (msg *sentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error { func (msg *SentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
if !ValidatePublicKey(key) { if !ValidatePublicKey(key) {
return errors.New("invalid public key provided for asymmetric encryption") return errors.New("invalid public key provided for asymmetric encryption")
} }
@ -240,7 +240,7 @@ func (msg *sentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
// encryptSymmetric encrypts a message with a topic key, using AES-GCM-256. // encryptSymmetric encrypts a message with a topic key, using AES-GCM-256.
// nonce size should be 12 bytes (see cipher.gcmStandardNonceSize). // nonce size should be 12 bytes (see cipher.gcmStandardNonceSize).
func (msg *sentMessage) encryptSymmetric(key []byte) (err error) { func (msg *SentMessage) encryptSymmetric(key []byte) (err error) {
if !ValidateDataIntegrity(key, AESKeyLength) { if !ValidateDataIntegrity(key, AESKeyLength) {
return errors.New("invalid key provided for symmetric encryption, size: " + strconv.Itoa(len(key))) return errors.New("invalid key provided for symmetric encryption, size: " + strconv.Itoa(len(key)))
} }
@ -262,7 +262,7 @@ func (msg *sentMessage) encryptSymmetric(key []byte) (err error) {
} }
// Wrap bundles the message into an Envelope to transmit over the network. // Wrap bundles the message into an Envelope to transmit over the network.
func (msg *sentMessage) Wrap(options *MessageParams, now time.Time) (envelope *Envelope, err error) { func (msg *SentMessage) Wrap(options *MessageParams, now time.Time) (envelope *Envelope, err error) {
if options.TTL == 0 { if options.TTL == 0 {
options.TTL = DefaultTTL options.TTL = DefaultTTL
} }

View File

@ -444,7 +444,7 @@ func TestPaddingAppendedToSymMessagesWithSignature(t *testing.T) {
// Simulate a message with a payload just under 256 so that // Simulate a message with a payload just under 256 so that
// payload + flag + signature > 256. Check that the result // payload + flag + signature > 256. Check that the result
// is padded on the next 256 boundary. // is padded on the next 256 boundary.
msg := sentMessage{} msg := SentMessage{}
const payloadSizeFieldMinSize = 1 const payloadSizeFieldMinSize = 1
msg.Raw = make([]byte, flagsLength+payloadSizeFieldMinSize+len(params.Payload)) msg.Raw = make([]byte, flagsLength+payloadSizeFieldMinSize+len(params.Payload))

View File

@ -212,7 +212,7 @@ func initializeBloomFilterMode(t *testing.T) {
}, },
} }
go startServer(t, node.server) // nolint: staticcheck go startServer(t, node.server) // nolint: staticcheck, govet
nodes[i] = &node nodes[i] = &node
} }
@ -232,7 +232,7 @@ func initializeBloomFilterMode(t *testing.T) {
func startServer(t *testing.T, s *p2p.Server) { func startServer(t *testing.T, s *p2p.Server) {
err := s.Start() err := s.Start()
if err != nil { if err != nil {
t.Fatalf("failed to start the first server. err: %v", err) t.Fatalf("failed to start the first server. err: %v", err) // nolint: staticcheck
} }
atomic.AddInt64(&result.started, 1) atomic.AddInt64(&result.started, 1)

View File

@ -93,7 +93,8 @@ func CreateTable(db *sql.DB, tableName string) error {
} }
func Clean(db *sql.DB, tableName string) error { func Clean(db *sql.DB, tableName string) error {
sqlStmt := fmt.Sprintf("DELETE FROM %s;", tableName) // This is fully controlled by us
sqlStmt := fmt.Sprintf("DELETE FROM %s;", tableName) // nolint: gosec
_, err := db.Exec(sqlStmt) _, err := db.Exec(sqlStmt)
if err != nil { if err != nil {
return err return err