From 192580fef6ff0d7ac62ddb6d8ba7d7d0fdfdb2f6 Mon Sep 17 00:00:00 2001 From: Jono Wenger <jono@elixxir.io> Date: Thu, 15 Sep 2022 12:08:57 -0700 Subject: [PATCH] Fixes to make wasm tests run --- .gitignore | 3 ++ wasm/README.md | 26 ++++++++-------- wasm/{testServer => }/clientServer.go | 11 ++++++- .../{testServer => clients}/assets/styles.css | 0 wasm/{testServer => clients}/assets/utils.js | 0 .../assets/wasm_exec.js | 6 ---- wasm/clients/sendE2E/README.md | 28 ++++++++++++++++++ .../sendE2E/receiver.html | 4 +-- .../sendE2E/receiver.ico | Bin .../sendE2ejs => clients/sendE2E/sendE2e.js} | 4 +++ .../sendE2E/sender.html | 6 ++-- .../sendE2E/sender.ico | Bin wasm/run.sh | 3 ++ wasm/runClientServer.sh | 9 ++++++ wasm/testServer/sendE2E/README.md | 27 ----------------- 15 files changed, 76 insertions(+), 51 deletions(-) rename wasm/{testServer => }/clientServer.go (87%) rename wasm/{testServer => clients}/assets/styles.css (100%) rename wasm/{testServer => clients}/assets/utils.js (100%) rename wasm/{testServer => clients}/assets/wasm_exec.js (98%) create mode 100644 wasm/clients/sendE2E/README.md rename wasm/{testServer => clients}/sendE2E/receiver.html (96%) rename wasm/{testServer => clients}/sendE2E/receiver.ico (100%) rename wasm/{testServer/sendE2E/sendE2ejs => clients/sendE2E/sendE2e.js} (98%) rename wasm/{testServer => clients}/sendE2E/sender.html (80%) rename wasm/{testServer => clients}/sendE2E/sender.ico (100%) create mode 100644 wasm/runClientServer.sh delete mode 100644 wasm/testServer/sendE2E/README.md diff --git a/.gitignore b/.gitignore index 6e40712..90c7c90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,14 @@ # Ignore Jetbrains IDE folder .idea/* + +# Ignore test files bin/* *.log *results* */.udb-cMix-session blob* junk* +*.wasm # Vim swap files *.swp diff --git a/wasm/README.md b/wasm/README.md index ebb0478..25c0e42 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -1,27 +1,29 @@ -# Running WASM Tests +# Running WebAssembly (WASM) Tests To run WASM tests, servers and gateways are run like normal, but the client is served by an HTTP server in the browser. -The `testServer` directory contains a basic HTTP server (`clientServer.go`) and -various directories each containing a different example. Each example contains -one or more cMix clients running in javascript. The `assets` directory contains -files used by all the examples. +`clientServer.go` is a basic HTTP server used to serve the Javascript clients. -To run the server, first ensure the compiled bindings are in the `bin` -directory. Then run the server +The `clients` directory contains various directories each containing a different +example. Each example contains one or more cMix clients running in javascript. +The `assets` directory contains files used by all the examples. + +To run the network and client server, use the provided `run.sh` script. + +```shell +$ ./run.sh +``` + +To run just the HTTP server, use the provided script. ```shell -$ GOOS=js GOARCH=wasm go build -o examples/xxdk.wasm -$ cd testServer/ -$ go run clientServer.go +$ ./runClientServer.sh ``` Navigate to http://localhost:9090 to see a list of files in the server and navigate to a `.html` file in any of the examples to open a client. -To start the network, run `run.sh` in the console. - ## `wasm_exec.js` diff --git a/wasm/testServer/clientServer.go b/wasm/clientServer.go similarity index 87% rename from wasm/testServer/clientServer.go rename to wasm/clientServer.go index c637bd4..6860672 100644 --- a/wasm/testServer/clientServer.go +++ b/wasm/clientServer.go @@ -10,11 +10,20 @@ package main import ( "fmt" "net/http" + "os" ) func main() { port := "9090" - root := "" + root := "clients" + + if len(os.Args) > 1 { + port = os.Args[1] + } + if len(os.Args) > 2 { + root = os.Args[2] + } + fmt.Printf("Starting server on port %s from %s\n", port, root) fmt.Printf("\thttp://localhost:%s\n", port) diff --git a/wasm/testServer/assets/styles.css b/wasm/clients/assets/styles.css similarity index 100% rename from wasm/testServer/assets/styles.css rename to wasm/clients/assets/styles.css diff --git a/wasm/testServer/assets/utils.js b/wasm/clients/assets/utils.js similarity index 100% rename from wasm/testServer/assets/utils.js rename to wasm/clients/assets/utils.js diff --git a/wasm/testServer/assets/wasm_exec.js b/wasm/clients/assets/wasm_exec.js similarity index 98% rename from wasm/testServer/assets/wasm_exec.js rename to wasm/clients/assets/wasm_exec.js index bba4a84..175a50a 100644 --- a/wasm/testServer/assets/wasm_exec.js +++ b/wasm/clients/assets/wasm_exec.js @@ -1,9 +1,3 @@ -/* - * Copyright Š 2020 xx network SEZC /// - * /// - * Use of this source code is governed by a license that can be found in the /// - * LICENSE file /// - */ // Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/wasm/clients/sendE2E/README.md b/wasm/clients/sendE2E/README.md new file mode 100644 index 0000000..ed18397 --- /dev/null +++ b/wasm/clients/sendE2E/README.md @@ -0,0 +1,28 @@ +# SendE2E Test + +This test sets up two clients in the browser and has one client send an E2E +message to the other. + +## Running the Test + +1. First, start the network and client HTTP server using the `run.sh` script. + This will start all the gateways and client registrar using localhost as + their public IP addresses and the NDF will be provided by the permissioning + server rather than downloaded from a gateway. + +2. Once rounds are running, on the receiver webpage, the local HTTP server will + start. Open http://localhost:9090 in the browser and navigate to the + `sendE2E` directory. Open the two clients, the sender (`sender.html`) and + receiver (`receiver.html`). + +3. On the receiver page, to start the client, upload the NDF file + `permissions-ndfoutput.json` from the `results` directory. Once the client + generates keys and joins the network, it will prompt its contact file for + download. Copy the contents of this file into the `recipientContactFile` + const in `sender.html`. + +4. On the sender webpage (make sure to refresh the page), select the NDF file as + described for the recipient above. This will start the sender client. Once it + generates its keys and joins the network, it will add the receiver client as + a partner, they will exchange requests and confirmations, and finally, the + sender will send an E2E message to the recipient. \ No newline at end of file diff --git a/wasm/testServer/sendE2E/receiver.html b/wasm/clients/sendE2E/receiver.html similarity index 96% rename from wasm/testServer/sendE2E/receiver.html rename to wasm/clients/sendE2E/receiver.html index 3fb9d34..8058380 100644 --- a/wasm/testServer/sendE2E/receiver.html +++ b/wasm/clients/sendE2E/receiver.html @@ -15,12 +15,12 @@ <link rel="shortcut icon" type="image/x-icon" href="receiver.ico"/> - <script type="text/javascript" src="sendE2ejs"></script> + <script type="text/javascript" src="sendE2e.js"></script> <script type="text/javascript" src="../assets/utils.js"></script> <script type="text/javascript" src="../assets/wasm_exec.js"></script> <script> const go = new Go(); - const binPath = '../../../bin/xxdk.wasm' + const binPath = '../assets/xxdk.wasm' WebAssembly.instantiateStreaming(fetch(binPath), go.importObject).then((result) => { go.run(result.instance); diff --git a/wasm/testServer/sendE2E/receiver.ico b/wasm/clients/sendE2E/receiver.ico similarity index 100% rename from wasm/testServer/sendE2E/receiver.ico rename to wasm/clients/sendE2E/receiver.ico diff --git a/wasm/testServer/sendE2E/sendE2ejs b/wasm/clients/sendE2E/sendE2e.js similarity index 98% rename from wasm/testServer/sendE2E/sendE2ejs rename to wasm/clients/sendE2E/sendE2e.js index ae63557..87ddcc2 100644 --- a/wasm/testServer/sendE2E/sendE2ejs +++ b/wasm/clients/sendE2E/sendE2e.js @@ -89,9 +89,13 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf, htmlConsole.log("Calling confirm on contact " + dec.decode(contact)) const rid = await e2eClient.Confirm(contact) htmlConsole.log("Called confirm on round " + rid) + }, + Reset: function (contact, receptionId, ephemeralId, roundId) { + htmlConsole.log("Reset: from " + Uint8ArrayToBase64(receptionId) + " on round " + roundId) } } + // Create an E2E client // Pass in auth object which controls auth callbacks for this client const params = GetDefaultE2EParams(); diff --git a/wasm/testServer/sendE2E/sender.html b/wasm/clients/sendE2E/sender.html similarity index 80% rename from wasm/testServer/sendE2E/sender.html rename to wasm/clients/sendE2E/sender.html index c88b0e9..ab70696 100644 --- a/wasm/testServer/sendE2E/sender.html +++ b/wasm/clients/sendE2E/sender.html @@ -14,12 +14,12 @@ <link rel="stylesheet" type="text/css" href="../assets/styles.css"> <link rel="shortcut icon" type="image/x-icon" href="sender.ico"/> - <script type="text/javascript" src="sendE2ejs"></script> + <script type="text/javascript" src="sendE2e.js"></script> <script type="text/javascript" src="../assets/utils.js"></script> <script type="text/javascript" src="../assets/wasm_exec.js"></script> <script> const go = new Go(); - const binPath = '../../../bin/xxdk.wasm' + const binPath = '../assets/xxdk.wasm' WebAssembly.instantiateStreaming(fetch(binPath), go.importObject).then((result) => { go.run(result.instance); @@ -39,7 +39,7 @@ const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") // Client specific parameters - const recipientContactFile = '<xxc(2)8xlGWi5QO7ypchZrwF0HIZwNv7MhrwojO1Zw6Mjmsx4DrgZ7Ugdw/BAr6UIgauCEAsxLTzY9qk+fDN6Q4lLf5bOCRKRavadoNTRpbG6GWmps0e1aMs6VsGflG4i95G4zWEu3tkGptr65SPC5c5/V1V9aYvf1rLSl8UwtiANaHlDdxy4ZEZbiibg7EnVi3mKZ3h4orsflDiWSwwSsdFbv9SxNmhzaFD4qpR0bi4jRyinyR4Ty6j8tA+ozcVo+Lt+gPeiUQqCt8NORS3Kcoe54yi4Lf9ylKxBumioRNytdyvo93r/SAX44w8j2tFTa+zYLz/Y09hPz391GHa3MDbDliPQgzRyJrAQRVJV9YcGTgi6ESDOFG3IoJbaNioHles7+2y/hqOKh3kCkbRtNozqGsp91PGiatCLx3bpRJq7h+o4Zk0yjZLf6e92JtFN4IBkHVc9RsiQEH8hy6tY9XLfvMOfr8xhWJ1gvIDxsS/Ice/lYkOs3zPCXwQXTBCAmZGZtsGxjMcSElz0d6cIVFBNgaGh3clWiWzz9nb62ofz0FcQ1O5n13L1Ir/41DyJU6GdeE5/+zvfqIKqSlAAAAgA76aDSbZXRB/a463h2byeQMw==xxc>'; + const recipientContactFile = '<xxc(2)bwLhF7GayqUb7ZpxbY2vh/tFAkhtEojNjFW7n4FZx8QDkAZiB9kZo+Dl3QlT8oBdNyBe+BKmgBt3FlVN9VngYcdl42kOmVztznMFM8KSLHa6NJyCv88jRTEiTq5rN/H884Vgg3/XcHbeezsefdfW48O24l6OeaZ+CQPA/ikYjsucrO2vhAi9BupWpfLR9IEWCPtK8wfgbo67T6QOyPlOKpsGqFt6WNfDuTjnnoPq6qJZhEnA251vJySV8ZAit6EHfQicTvCuscs5vCbIJoMOgEXkZBul3k3HTwxTCz4amQUuH7PtxGHe27RYxLiJaIyeLQFcjqlyReQV4t/jmoKK3m+N6LHGdyqSBFIlYGwzphGQySZ/zuCDqPGqXmoTHpB8V8rFs/jeabNiiNuw/1u67exFNdDcM6Fc7EdbZyDl80uPtrQIKUUda+HO+GVaoasMy2V4SY+UIOKFjtsBuX3gcmr9VKXenPhLCduLdMIjzCRZyuqNQ9SZ1hPLu4i8wyP8ZspOpKIJbRkpratdcrbnPd+Qg0wCQGu+iPEjbLS6ac56r4CKqGADH+kx9gAAAgA7xSs7dPeUgkCxcKBMKDrk9g==xxc>'; const myContactFileName = ''; const statePath = 'statePathSender'; const statePass = 'password'; diff --git a/wasm/testServer/sendE2E/sender.ico b/wasm/clients/sendE2E/sender.ico similarity index 100% rename from wasm/testServer/sendE2E/sender.ico rename to wasm/clients/sendE2E/sender.ico diff --git a/wasm/run.sh b/wasm/run.sh index 790799e..a752452 100644 --- a/wasm/run.sh +++ b/wasm/run.sh @@ -22,6 +22,9 @@ mkdir -p $GATEWAYLOGS # Start the network source network.sh +# Start the client HTTP server +source runClientServer.sh + # This remains commented out while using HTTP #echo "DOWNLOADING TLS Cert..." #CMD="openssl s_client -showcerts -connect $(tr -d '[:space:]' <results/startgwserver.txt)" diff --git a/wasm/runClientServer.sh b/wasm/runClientServer.sh new file mode 100644 index 0000000..3cb9596 --- /dev/null +++ b/wasm/runClientServer.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# This script starts a simple HTTP server to server Javascript clients. It also +# copies the WebAssembly binary into the server directory. + +# Copy the wasm binary to the server directory +cp ../bin/xxdk.wasm clients/assets/ + +go run clientServer.go 9090 ./clients/ \ No newline at end of file diff --git a/wasm/testServer/sendE2E/README.md b/wasm/testServer/sendE2E/README.md deleted file mode 100644 index 1a5bb7c..0000000 --- a/wasm/testServer/sendE2E/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# SendE2E Test - -This test sets up two clients in the browser and has one client send an E2E -message to the other. - -## Running the Test - -1. First, compile the WASM binary and start the local HTTP server. Refer to wasm - test [README](../README.md) for details on how to do this. Open the two - clients, the sender and receiver. - -2. Next, start the network using the `run.sh` script. This will start all the - gateways and client registrar using localhost as their public IP addresses - and the NDF will be provided by the permissioning server rather than - downloaded from a gateway. - -3. Once rounds are running, on the receiver webpage, navigate to the results - folder in integration and select the `permissions-ndfoutput.json` file. Doing - this will start the client. Once the client generates keys and joins the - network, it will prompt its contact file for download. Copy the contents of - this file into the `recipientContactFile` const in `sender.html`. - -4. On the sender webpage (make sure to refresh the page), select the NDF file as - described for the recipient above. This will start the sender client. Once it - generates its keys and joins the network, it will add the receiver client as - a partner, they will exchange requests and confirmations, and finally, the - sender will send an E2E message to the recipient. \ No newline at end of file -- GitLab