Skip to content
Snippets Groups Projects
Commit 19d2e956 authored by Jonah Husson's avatar Jonah Husson
Browse files

Add testing with cypher tests

parent 3b80a8c5
No related branches found
No related tags found
2 merge requests!60Revert "Fail a test to be sure it works",!45Add testing with cypher tests
This commit is part of merge request !45. Comments created here will be created in the context of that merge request.
......@@ -15,6 +15,7 @@ import (
"github.com/hack-pad/go-indexeddb/idb"
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/netTime"
"os"
"strconv"
......@@ -26,6 +27,7 @@ import (
"gitlab.com/elixxir/client/v4/cmix/rounds"
cryptoBroadcast "gitlab.com/elixxir/crypto/broadcast"
"gitlab.com/elixxir/crypto/channel"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/xx_network/primitives/id"
)
......@@ -38,10 +40,17 @@ func dummyCallback(uint64, *id.ID, bool) {}
// Happy path, insert message and look it up
func TestWasmModel_msgIDLookup(t *testing.T) {
cipher, err := cryptoChannel.NewCipher([]byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
t.Run(fmt.Sprintf("Test-%d", i), func(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "test"
testMsgId := channel.MakeMessageID([]byte(testString), &id.ID{1})
eventModel, err := newWASMModel(testString, nil, dummyCallback)
eventModel, err := newWASMModel(testString, c, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
}
......@@ -61,14 +70,22 @@ func TestWasmModel_msgIDLookup(t *testing.T) {
if uuid == 0 {
t.Fatalf("Expected to get a UUID!")
}
})
}
}
// Test wasmModel.UpdateSentStatus happy path and ensure fields don't change.
func Test_wasmModel_UpdateSentStatus(t *testing.T) {
cipher, err := cryptoChannel.NewCipher([]byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
t.Run(fmt.Sprintf("Test-%d", i), func(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "test"
testMsgId := channel.MakeMessageID([]byte(testString), &id.ID{1})
eventModel, err := newWASMModel(testString, nil, dummyCallback)
eventModel, err := newWASMModel(testString, c, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
}
......@@ -117,12 +134,20 @@ func Test_wasmModel_UpdateSentStatus(t *testing.T) {
if resultMsg.Nickname != testString {
t.Fatalf("Unexpected Nickname: %v", resultMsg.Nickname)
}
})
}
}
// Smoke test wasmModel.JoinChannel/wasmModel.LeaveChannel happy paths.
func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
cipher, err := cryptoChannel.NewCipher([]byte("testpass"), []byte("testsalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
t.Run(fmt.Sprintf("Test-%d", i), func(t *testing.T) {
storage.GetLocalStorage().Clear()
eventModel, err := newWASMModel("test", nil, dummyCallback)
eventModel, err := newWASMModel("test", c, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
}
......@@ -156,13 +181,21 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
if len(results) != 1 {
t.Fatalf("Expected 1 channels to exist")
}
})
}
}
// 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())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
t.Run(fmt.Sprintf("Test-%d", i), func(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "testHello"
eventModel, err := newWASMModel(testString, nil, dummyCallback)
eventModel, err := newWASMModel(testString, c, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
}
......@@ -189,13 +222,21 @@ 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())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
t.Run(fmt.Sprintf("Test-%d", i), func(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "testHello"
eventModel, err := newWASMModel(testString, nil, dummyCallback)
eventModel, err := newWASMModel(testString, c, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
}
......@@ -222,16 +263,25 @@ 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())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
t.Run(fmt.Sprintf("Test-%d", i), func(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "test_deleteMsgByChannel"
totalMessages := 10
expectedMessages := 5
eventModel, err := newWASMModel(testString, nil, dummyCallback)
eventModel, err := newWASMModel(testString, c, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
}
......@@ -279,14 +329,22 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
if len(result) != expectedMessages {
t.Errorf("Expected %d messages, got %d", expectedMessages, len(result))
}
})
}
}
// 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())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
t.Run(fmt.Sprintf("Test-%d", i), func(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "test_receiveHelper_UniqueIndex"
eventModel, err := newWASMModel(testString, nil, dummyCallback)
testString := fmt.Sprintf("test_receiveHelper_UniqueIndex_%d", i)
eventModel, err := newWASMModel(testString, c, dummyCallback)
if err != nil {
t.Fatal(err)
}
......@@ -360,4 +418,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
t.Fatalf("%+v", err)
}
// TODO: Convert JSON to Message, ensure Message ID fields differ
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment