diff --git a/indexedDb/channels/implementation_test.go b/indexedDb/channels/implementation_test.go index 9e14fbe74b7dac0500be469ebf29c0c3c2df64b7..79a02de774ae701b6b579d356690f931f7a53457 100644 --- a/indexedDb/channels/implementation_test.go +++ b/indexedDb/channels/implementation_test.go @@ -206,7 +206,7 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) { if c != nil { cs = "_withCipher" } - t.Run(fmt.Sprintf("Test_wasmModel_JoinChannel_LeaveChannel%s", cs), func(t *testing.T) { + t.Run("Test_wasmModel_JoinChannel_LeaveChannel"+cs, func(t *testing.T) { storage.GetLocalStorage().Clear() eventModel, err := newWASMModel("test", c, dummyCallback) if err != nil { @@ -248,7 +248,8 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) { // Test UUID gets returned when different messages are added. func Test_wasmModel_UUIDTest(t *testing.T) { - cipher, err := cryptoChannel.NewCipher([]byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) + cipher, err := cryptoChannel.NewCipher( + []byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) if err != nil { t.Fatalf("Failed to create cipher") } @@ -257,7 +258,7 @@ func Test_wasmModel_UUIDTest(t *testing.T) { if c != nil { cs = "_withCipher" } - t.Run(fmt.Sprintf("Test_wasmModel_UUIDTest%s", cs), func(t *testing.T) { + t.Run("Test_wasmModel_UUIDTest"+cs, func(t *testing.T) { storage.GetLocalStorage().Clear() testString := "testHello" + cs eventModel, err := newWASMModel(testString, c, dummyCallback) @@ -293,7 +294,8 @@ func Test_wasmModel_UUIDTest(t *testing.T) { // Tests if the same message ID being sent always returns the same UUID. func Test_wasmModel_DuplicateReceives(t *testing.T) { - cipher, err := cryptoChannel.NewCipher([]byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) + cipher, err := cryptoChannel.NewCipher( + []byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) if err != nil { t.Fatalf("Failed to create cipher") } @@ -302,7 +304,7 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) { if c != nil { cs = "_withCipher" } - t.Run(fmt.Sprintf("Test_wasmModel_DuplicateReceives%s", cs), func(t *testing.T) { + t.Run("Test_wasmModel_DuplicateReceives"+cs, func(t *testing.T) { storage.GetLocalStorage().Clear() testString := "testHello" eventModel, err := newWASMModel(testString, c, dummyCallback) @@ -339,7 +341,8 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) { // Happy path: Inserts many messages, deletes some, and checks that the final // result is as expected. func Test_wasmModel_deleteMsgByChannel(t *testing.T) { - cipher, err := cryptoChannel.NewCipher([]byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) + cipher, err := cryptoChannel.NewCipher( + []byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) if err != nil { t.Fatalf("Failed to create cipher") } @@ -348,7 +351,7 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) { if c != nil { cs = "_withCipher" } - t.Run(fmt.Sprintf("Test_wasmModel_deleteMsgByChannel%s", cs), func(t *testing.T) { + t.Run("Test_wasmModel_deleteMsgByChannel"+cs, func(t *testing.T) { storage.GetLocalStorage().Clear() testString := "test_deleteMsgByChannel" totalMessages := 10 @@ -372,10 +375,12 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) { thisChannel = keepChannel } - testMsgId := message.DeriveChannelMessageID(&id.ID{byte(i)}, 0, []byte(testStr)) - eventModel.ReceiveMessage(thisChannel, testMsgId, testStr, testStr, - []byte{8, 6, 7, 5}, 0, 0, netTime.Now(), time.Second, - rounds.Round{ID: id.Round(0)}, 0, channels.Sent, false) + testMsgId := message.DeriveChannelMessageID( + &id.ID{byte(i)}, 0, []byte(testStr)) + eventModel.ReceiveMessage(thisChannel, testMsgId, testStr, + testStr, []byte{8, 6, 7, 5}, 0, 0, netTime.Now(), + time.Second, rounds.Round{ID: id.Round(0)}, 0, + channels.Sent, false) } // Check pre-results @@ -408,7 +413,8 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) { // This test is designed to prove the behavior of unique indexes. // Inserts will not fail, they simply will not happen. func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) { - cipher, err := cryptoChannel.NewCipher([]byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) + cipher, err := cryptoChannel.NewCipher( + []byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG()) if err != nil { t.Fatalf("Failed to create cipher") } @@ -417,7 +423,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) { if c != nil { cs = "_withCipher" } - t.Run(fmt.Sprintf("TestWasmModel_receiveHelper_UniqueIndex%s", cs), func(t *testing.T) { + t.Run("TestWasmModel_receiveHelper_UniqueIndex"+cs, func(t *testing.T) { storage.GetLocalStorage().Clear() testString := fmt.Sprintf("test_receiveHelper_UniqueIndex_%d", i) eventModel, err := newWASMModel(testString, c, dummyCallback) @@ -465,7 +471,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) { } // Now insert a message with a different message ID from the first - testMsgId2 := message.DeriveChannelMessageID(&id.ID{2}, 0, []byte(testString)) + testMsgId2 := message.DeriveChannelMessageID( + &id.ID{2}, 0, []byte(testString)) testMsg = buildMessage([]byte(testString), testMsgId2.Bytes(), nil, testString, []byte(testString), []byte{8, 6, 7, 5}, 0, 0, netTime.Now(), time.Second, 0, 0, false, false, channels.Sent) diff --git a/indexedDb/dm/implementation.go b/indexedDb/dm/implementation.go index d6703af622e84f159a7ee1060c8ed46372b92536..afd4e3bff44d739d7a8d3d687563c390fde7f743 100644 --- a/indexedDb/dm/implementation.go +++ b/indexedDb/dm/implementation.go @@ -96,8 +96,9 @@ func buildMessage(messageID, parentID []byte, text []byte, } func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte, - pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, timestamp time.Time, - round rounds.Round, mType dm.MessageType, status dm.Status) uint64 { + pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, + timestamp time.Time, round rounds.Round, mType dm.MessageType, + status dm.Status) uint64 { parentErr := errors.New("failed to Receive") // If there is no extant Conversation, create one. @@ -138,13 +139,13 @@ func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte, } func (w *wasmModel) ReceiveText(messageID message.ID, nickname, text string, - pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, timestamp time.Time, - round rounds.Round, status dm.Status) uint64 { + pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, + timestamp time.Time, round rounds.Round, status dm.Status) uint64 { parentErr := errors.New("failed to ReceiveText") // If there is no extant Conversation, create one. _, err := indexedDb.Get(w.db, conversationStoreName, utils.CopyBytesToJS(pubKey)) - if err != nil { + if err != nil { if strings.Contains(err.Error(), indexedDb.ErrDoesNotExist) { err = w.joinConversation(nickname, pubKey, dmToken, codeset) if err != nil { @@ -181,10 +182,9 @@ func (w *wasmModel) ReceiveText(messageID message.ID, nickname, text string, return uuid } -func (w *wasmModel) ReceiveReply(messageID message.ID, reactionTo message.ID, - nickname, text string, pubKey ed25519.PublicKey, dmToken uint32, - codeset uint8, timestamp time.Time, round rounds.Round, - status dm.Status) uint64 { +func (w *wasmModel) ReceiveReply(messageID, reactionTo message.ID, nickname, + text string, pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, + timestamp time.Time, round rounds.Round, status dm.Status) uint64 { parentErr := errors.New("failed to ReceiveReply") // If there is no extant Conversation, create one. @@ -226,9 +226,9 @@ func (w *wasmModel) ReceiveReply(messageID message.ID, reactionTo message.ID, return uuid } -func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID, - nickname, reaction string, pubKey ed25519.PublicKey, dmToken uint32, - codeset uint8, timestamp time.Time, round rounds.Round, status dm.Status) uint64 { +func (w *wasmModel) ReceiveReaction(messageID, reactionTo message.ID, nickname, + reaction string, pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, + timestamp time.Time, round rounds.Round, status dm.Status) uint64 { parentErr := errors.New("failed to ReceiveText") // If there is no extant Conversation, create one. @@ -270,9 +270,8 @@ func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID, return uuid } -func (w *wasmModel) UpdateSentStatus(uuid uint64, - messageID message.ID, timestamp time.Time, round rounds.Round, - status dm.Status) { +func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID, + timestamp time.Time, round rounds.Round, status dm.Status) { parentErr := errors.New("failed to UpdateSentStatus") // FIXME: this is a bit of race condition without the mux. @@ -323,8 +322,8 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, } // receiveHelper is a private helper for receiving any sort of message. -func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64, - error) { +func (w *wasmModel) receiveHelper( + newMessage *Message, isUpdate bool) (uint64, error) { // Convert to jsObject newMessageJson, err := json.Marshal(newMessage) if err != nil { @@ -365,8 +364,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64, } // msgIDLookup gets the UUID of the Message with the given messageID. -func (w *wasmModel) msgIDLookup(messageID message.ID) (uint64, - error) { +func (w *wasmModel) msgIDLookup(messageID message.ID) (uint64, error) { resultObj, err := indexedDb.GetIndex(w.db, messageStoreName, messageStoreMessageIndex, utils.CopyBytesToJS(messageID.Marshal())) if err != nil { diff --git a/indexedDb/utils.go b/indexedDb/utils.go index 4b32064ae84254a42112c78feb36510c2501376d..a5bef78685ef34452aca396e1aea3f5206cf4ab6 100644 --- a/indexedDb/utils.go +++ b/indexedDb/utils.go @@ -157,8 +157,8 @@ func Put(db *idb.Database, objectStoreName string, value js.Value) (js.Value, er return result, nil } -// Delete is a generic helper for removing values from the given [idb.ObjectStore]. -// Only usable by primary key. +// Delete is a generic helper for removing values from the given +// [idb.ObjectStore]. Only usable by primary key. func Delete(db *idb.Database, objectStoreName string, key js.Value) error { parentErr := errors.Errorf("failed to Delete %s/%s", objectStoreName, key)