Skip to content
Snippets Groups Projects
Commit 910435f1 authored by Jono Wenger's avatar Jono Wenger
Browse files

Merge remote-tracking branch 'origin/release' into project/adminCommands

# Conflicts:
#	go.mod
#	go.sum
#	indexedDb/channels/implementation_test.go
parents de4d0a83 8f3ed6e1
Branches
Tags
2 merge requests!60Revert "Fail a test to be sure it works",!32Admin Commands
......@@ -25,6 +25,8 @@ stages:
build:
stage: build
except:
- tags
script:
- go mod vendor -v
- mkdir -p release
......@@ -36,6 +38,8 @@ build:
wasm-test:
stage: test
except:
- tags
script:
- export PATH=/root/go/bin:$PATH
- echo > utils/utils_js.s
......@@ -44,23 +48,29 @@ wasm-test:
go-test:
stage: test
except:
- tags
script:
- go mod vendor -v
- go test ./... -v
version_check:
stage: version_check
except:
- tags
only:
- master
- release
image: $DOCKER_IMAGE
script:
- GITTAG=$(git describe --tags)
- CODEVERS=$(cat utils/version.go | grep "const SEMVER =" | cut -d ' ' -f4 | tr -d '"')
- if [[ $GITTAG != $CODEVERS ]]; then echo "VERSION NUMBER BAD $GITTAG != $CODEVER"; exit -1; fi
- CODEVERS=$(cat storage/version.go | grep "const SEMVER =" | cut -d ' ' -f4 | tr -d '"')
- if [[ $GITTAG != $CODEVERS ]]; then echo "VERSION NUMBER BAD $GITTAG != $CODEVERS"; exit -1; fi
tag:
stage: build
except:
- tags
image: $DOCKER_IMAGE
script:
- git remote add origin_tags git@$GITLAB_SERVER:elixxir/xxdk-wasm.git || true
......@@ -76,6 +86,8 @@ tag:
# master/release, this will fail to pull the latest client, and the docs will not update.
doc-update:
stage: doc-update
except:
- tags
image: $DOCKER_IMAGE
script:
# We use GOPRIVATE blank because not want to directly pull client, we want to use the public cache.
......
......@@ -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,17 +40,28 @@ 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 _, c := range []cryptoChannel.Cipher{nil, cipher} {
cs := ""
if cipher != nil {
cs = "_withCipher"
}
t.Run(fmt.Sprintf("TestWasmModel_msgIDLookup%s", cs), 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)
}
testMsg := buildMessage([]byte(testString), testMsgId.Bytes(), nil,
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, netTime.Now(),
time.Second, 0, 0, false, false, channels.Sent)
testString, []byte(testString), []byte{8, 6, 7, 5}, 0,
netTime.Now(), time.Second, 0, 0, false, false, channels.Sent)
_, err = eventModel.receiveHelper(testMsg, false)
if err != nil {
t.Fatalf("%+v", err)
......@@ -61,6 +74,8 @@ func TestWasmModel_msgIDLookup(t *testing.T) {
if msg.ID == 0 {
t.Fatalf("Expected to get a UUID!")
}
})
}
}
// Happy path, insert message and delete it
......@@ -107,12 +122,22 @@ func TestWasmModel_DeleteMessage(t *testing.T) {
}
}
// Test wasmModel.UpdateFromUUID happy path and ensure fields don't change.
func Test_wasmModel_UpdateFromUUID(t *testing.T) {
// 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 _, c := range []cryptoChannel.Cipher{nil, cipher} {
cs := ""
if cipher != nil {
cs = "_withCipher"
}
t.Run(fmt.Sprintf("Test_wasmModel_UpdateSentStatus%s", cs), 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)
}
......@@ -137,8 +162,8 @@ func Test_wasmModel_UpdateFromUUID(t *testing.T) {
// Update the sentStatus
expectedStatus := channels.Failed
eventModel.UpdateFromUUID(uuid, nil, nil,
nil, nil, nil, &expectedStatus)
eventModel.UpdateFromUUID(
uuid, nil, nil, nil, nil, nil, &expectedStatus)
// Check the resulting status
results, err = indexedDb.Dump(eventModel.db, messageStoreName)
......@@ -161,12 +186,24 @@ func Test_wasmModel_UpdateFromUUID(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 _, c := range []cryptoChannel.Cipher{nil, cipher} {
cs := ""
if cipher != nil {
cs = "_withCipher"
}
t.Run(fmt.Sprintf("Test_wasmModel_JoinChannel_LeaveChannel%s", cs), 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)
}
......@@ -200,13 +237,25 @@ 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 _, c := range []cryptoChannel.Cipher{nil, cipher} {
cs := ""
if cipher != nil {
cs = "_withCipher"
}
t.Run(fmt.Sprintf("Test_wasmModel_UUIDTest%s", cs), 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)
}
......@@ -233,13 +282,25 @@ 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 _, c := range []cryptoChannel.Cipher{nil, cipher} {
cs := ""
if cipher != nil {
cs = "_withCipher"
}
t.Run(fmt.Sprintf("Test_wasmModel_DuplicateReceives%s", cs), 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)
}
......@@ -266,16 +327,28 @@ 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 _, c := range []cryptoChannel.Cipher{nil, cipher} {
cs := ""
if cipher != nil {
cs = "_withCipher"
}
t.Run(fmt.Sprintf("Test_wasmModel_deleteMsgByChannel%s", cs), 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)
}
......@@ -323,14 +396,26 @@ 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} {
cs := ""
if cipher != nil {
cs = "_withCipher"
}
t.Run(fmt.Sprintf("TestWasmModel_receiveHelper_UniqueIndex%s", cs), 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)
}
......@@ -358,8 +443,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
// First message insert should succeed
testMsgId := channel.MakeMessageID([]byte(testString), &id.ID{1})
testMsg := buildMessage([]byte(testString), testMsgId.Bytes(), nil,
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, netTime.Now(),
time.Second, 0, 0, false, false, channels.Sent)
testString, []byte(testString), []byte{8, 6, 7, 5}, 0,
netTime.Now(), time.Second, 0, 0, false, false, channels.Sent)
_, err = eventModel.receiveHelper(testMsg, false)
if err != nil {
t.Fatal(err)
......@@ -381,8 +466,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
// Now insert a message with a different message ID from the first
testMsgId2 := channel.MakeMessageID([]byte(testString), &id.ID{2})
testMsg = buildMessage([]byte(testString), testMsgId2.Bytes(), nil,
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, netTime.Now(),
time.Second, 0, 0, false, false, channels.Sent)
testString, []byte(testString), []byte{8, 6, 7, 5}, 0,
netTime.Now(), time.Second, 0, 0, false, false, channels.Sent)
primaryKey, err := eventModel.receiveHelper(testMsg, false)
if err != nil {
t.Fatal(err)
......@@ -404,4 +489,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
t.Fatalf("%+v", err)
}
// TODO: Convert JSON to Message, ensure Message ID fields differ
})
}
}
......@@ -18,7 +18,7 @@ import (
)
// SEMVER is the current semantic version of xxDK WASM.
const SEMVER = "0.1.10"
const SEMVER = "0.1.13"
// Storage keys.
const (
......
......@@ -32,6 +32,10 @@ func CopyBytesToJS(src []byte) js.Value {
// JsToJson converts the Javascript value to JSON.
func JsToJson(value js.Value) string {
if value.IsUndefined() {
return "null"
}
return JSON.Call("stringify", value).String()
}
......
......@@ -113,6 +113,22 @@ func TestJsToJson(t *testing.T) {
}
}
// Tests that JsToJson return a null object when the Javascript object is
// undefined.
func TestJsToJson_Undefined(t *testing.T) {
expected, err := json.Marshal(nil)
if err != nil {
t.Errorf("Failed to JSON marshal test object: %+v", err)
}
jsJson := JsToJson(js.Undefined())
if string(expected) != jsJson {
t.Errorf("Recieved incorrect JSON from Javascript object."+
"\nexpected: %s\nreceived: %s", expected, jsJson)
}
}
// Tests that JsonToJS can convert a JSON object with multiple types to a
// Javascript object and that all values match.
func TestJsonToJS(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment