Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress Implemented for binary search on a secret array #276

Merged
merged 57 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e128434
cypress installed
Snafkin547 Apr 11, 2024
f532a29
Baseline Cypress components created
Snafkin547 Apr 12, 2024
6d97c8c
Baseline Cypress components created
Snafkin547 Apr 12, 2024
bdfb56e
Baseline Cypress test created but ws not working properly
Snafkin547 Apr 12, 2024
43d2c9a
Baseline Cypress test created but input not appropriate
Snafkin547 Apr 12, 2024
22c7bc1
Web worker worked
Snafkin547 Apr 17, 2024
7a347d6
Web worker worked
Snafkin547 Apr 17, 2024
97f5e6d
Web worker worked
Snafkin547 Apr 17, 2024
b29fe85
Refactored
Snafkin547 Apr 17, 2024
cb3ca5f
ts config for cypress done
Snafkin547 Apr 17, 2024
914cdb5
Type conflict resolved
Snafkin547 Apr 17, 2024
417cb59
prettier
Snafkin547 Apr 17, 2024
8f12bbe
bubble sort worked
Snafkin547 Apr 18, 2024
4259c89
refactored binary search
Snafkin547 Apr 18, 2024
9325f9b
Refactored Array Binary Search
Snafkin547 Apr 18, 2024
697711d
array concat works
Snafkin547 Apr 18, 2024
302583f
merge sort worked
Snafkin547 Apr 18, 2024
c56c803
Array Shuffle worked
Snafkin547 Apr 18, 2024
2df792c
Sustring Search Test done
Snafkin547 Apr 18, 2024
6bd9512
Modified some comments in test.cy
Snafkin547 Apr 18, 2024
ec6c1e9
Valentines day sample wokred
Snafkin547 Apr 18, 2024
d8b69b5
Updated it descriptions
Snafkin547 Apr 18, 2024
9142d27
Shell sort worked
Snafkin547 Apr 19, 2024
af44c20
Test workflow worked in array mpc as service
Snafkin547 Apr 22, 2024
93f285f
Update socket.js
Snafkin547 Apr 23, 2024
78f87e3
Update socket.js
Snafkin547 Apr 23, 2024
399040a
redoing investigation adftr connect
Snafkin547 Apr 23, 2024
80f5ff5
Merge branch 'cypress' of github.com:multiparty/jiff into cypress
Snafkin547 Apr 23, 2024
b9303ee
Retrieving previous state
Snafkin547 Apr 23, 2024
54be72d
Retrieving previous state
Snafkin547 Apr 23, 2024
a2bc4a8
Retrieving previous state
Snafkin547 Apr 23, 2024
13f9e30
retrieved prev jiff-client-restful
Snafkin547 Apr 23, 2024
10c1923
axios removed
Snafkin547 Apr 23, 2024
baadda0
axios removed
Snafkin547 Apr 23, 2024
a77868d
array-concat tests modified
Snafkin547 Apr 25, 2024
96cd726
cypress added
Snafkin547 Apr 25, 2024
e0431cd
renamed cypress
Snafkin547 Apr 25, 2024
3613e87
file dir changed
Snafkin547 Apr 25, 2024
f0e7443
Update test.sh
Snafkin547 Apr 25, 2024
390d0fd
wait time between tests added
Snafkin547 Apr 25, 2024
700bd71
added more wait time for shell sort
Snafkin547 Apr 25, 2024
5fdee85
Moved cypress to demos
Snafkin547 Apr 25, 2024
97b9162
cypress path updated in github action
Snafkin547 Apr 25, 2024
a242f74
demo files saved directry in demos
Snafkin547 Apr 25, 2024
3a2625d
cypress github action amended
Snafkin547 Apr 25, 2024
bffc0a6
Increased time wait for shell sort
Snafkin547 Apr 25, 2024
14a6dbb
valentine vote retrieved
Snafkin547 Apr 25, 2024
47e5e7c
Increased time wait for shell sort
Snafkin547 Apr 25, 2024
5dcefc0
Increased time wait for concat
Snafkin547 Apr 25, 2024
b42af0a
Increased time wait for concat
Snafkin547 Apr 25, 2024
b8c6168
modified concat test back to orgnal
Snafkin547 Apr 25, 2024
5111bd2
j appended
Snafkin547 Apr 25, 2024
933c58b
j appended
Snafkin547 Apr 25, 2024
a69767d
Retrieved arr-mpc as service
Snafkin547 Apr 25, 2024
3233ff2
readme retrieved
Snafkin547 Apr 25, 2024
79fca7d
Wrongly referenced path corrected
Snafkin547 Apr 25, 2024
b2f92d8
Wrongly referenced path corrected
Snafkin547 Apr 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
}
}
});
58 changes: 58 additions & 0 deletions cypress/e2e/array-binary-search/client.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- Basic UI for running the demo in the browser -->

<html>
<head>
<title>Binary Search Tree</title>
<style>
.error {
color: #FF0000;
}
</style>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
Fixed Show fixed Hide fixed
<script src="../../../dist/jiff-client.js"></script>
<script src="../../../dist/jiff-client-websockets.js"></script>

<!-- Contains UI Handlers and Input Checks -->
<script type="text/javascript" src="./client.js"></script>

<!-- Contains the MPC implementation -->
<script type="text/javascript" src="./mpc.js"></script>
</head>
<body>
<h1>Connect JIFF</h1>
<label for="computation_id">Computation ID</label><input id="computation_id" value="test"></input><br/><br/>
<label for="role">Choose Role</label>
<button id="connectButton" onclick="connect(1);connect(2)">Connect</button>
<br/><br/>
<hr/>
<div class="container" id="input1" style="display: block">
<div class="row">
<h1>Input Sorted Array</h1>
</div>
<div>
<p>Enter an array of sorted positive integers, each smaller than 13.</p>
</div>
<textarea rows="4" cols="50" id="inputArray">[1, 2, 7, 10, 11, 12]</textarea>
<br/><br/>
<div class="row">
<button class="btn btn-secondary" id="submit1" onclick="submitArray();">Submit</button>
</div>
</div>

<div class="container" id="input2" style="display: block">
<div class="row">
<h1>Input Search Element.</h1>
</div>
<div>
<p>Must be less than 13</p>
</div>
<input id="inputElement" pattern="[0-9]*"/>
<br/><br/>
<div class="row">
<button class="btn btn-secondary" id="submit2" onclick="submitElement();">Submit</button>
</div>
</div>

<div id="output"></div>
</body>
</html>
91 changes: 91 additions & 0 deletions cypress/e2e/array-binary-search/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
let worker = new Worker('./web-worker.js');

function connect(party_id) {

Check failure on line 3 in cypress/e2e/array-binary-search/client.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/client.js#L3

'connect' is defined but never used.
$('#connectButton').prop('disabled', true);
var computation_id = $('#computation_id').val();

var options = { party_id: party_id, party_count: 2, Zp: 13 };

var hostname = window.location.hostname.trim();
var port = window.location.port;
if (port == null || port === '') {
port = '80';
}
if (!(hostname.startsWith('http://') || hostname.startsWith('https://'))) {
hostname = 'http://' + hostname;
}
if (hostname.endsWith('/')) {
hostname = hostname.substring(0, hostname.length - 1);
}
if (hostname.indexOf(':') > -1 && hostname.lastIndexOf(':') > hostname.indexOf(':')) {
hostname = hostname.substring(0, hostname.lastIndexOf(':'));
}

hostname = hostname + ':' + port;

// eslint-disable-next-line no-undef
if (party_id === 1) {
worker.postMessage({
type: 'init_array',
hostname: hostname,
computation_id: computation_id,
options: options
});
} else if (party_id === 2) {
worker.postMessage({
type: 'init_elem',
hostname: hostname,
computation_id: computation_id,
options: options
});
}
}

worker.onmessage = function (e) {
if (e.data.type === 'array') {
const msg = e.data.result === 1 ? 'Element Found' : 'Element Does Not Exist';
document.querySelector('#output').innerHTML += `<p>${msg}</p>`;
}
};

worker.onmessage = function (e) {
if (e.data.type === 'element') {
const msg = e.data.result === 1 ? 'Element Found' : 'Element Does Not Exist';
document.querySelector('#output').innerHTML += `<p>${msg}</p>`;
}
};

// eslint-disable-next-line no-unused-vars
function submitArray() {

Check failure on line 59 in cypress/e2e/array-binary-search/client.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/client.js#L59

'submitArray' is defined but never used.
var arr = JSON.parse($('#inputArray').val());
for (var i = 0; i < arr.length; i++) {

Check warning on line 61 in cypress/e2e/array-binary-search/client.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/client.js#L61

Expected a `for-of` loop instead of a `for` loop with this simple iteration.
if (arr[i] >= 13) {

Check warning on line 62 in cypress/e2e/array-binary-search/client.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/client.js#L62

Generic Object Injection Sink
alert('All numbers must be less than 13');
return;
}
}

worker.postMessage({
type: 'computeArray',
input: arr
});
}

// eslint-disable-next-line no-unused-vars
function submitElement() {

Check failure on line 75 in cypress/e2e/array-binary-search/client.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/client.js#L75

'submitElement' is defined but never used.
var element = $('#inputElement').val();
element = parseInt(element);

Check warning on line 77 in cypress/e2e/array-binary-search/client.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/client.js#L77

Always provide a base when using parseInt() functions
if (element == null || isNaN(element)) {
alert('Element must be a whole number');
return;
}
if (element < 0 || element >= 13) {
alert('Element must be between 0 and 13 exclusive');
return;
}

worker.postMessage({
type: 'computeElement',
input: element
});
}
77 changes: 77 additions & 0 deletions cypress/e2e/array-binary-search/mpc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
(function (exports, node) {

/**
* Connect to the server and initialize the jiff instance
*/
exports.connect = function (hostname, computation_id, options) {
var opt = Object.assign({}, options);
// Added options goes here
opt.crypto_provider = true;

if (node) {
// eslint-disable-next-line no-undef
JIFFClient = require('../../lib/jiff-client');
// eslint-disable-next-line no-undef,no-global-assign
$ = require('jquery-deferred');
// eslint-disable-next-line no-undef
jiff_websockets = require('../../lib/ext/jiff-client-websockets.js');
}

// eslint-disable-next-line no-undef
saved_instance = new JIFFClient(hostname, computation_id, opt);
// if you need any extensions, put them here
// eslint-disable-next-line no-undef
saved_instance.apply_extension(jiff_websockets, opt);

return saved_instance;
};

exports.compute = async function (input, jiff_instance) {
if (jiff_instance.id === 1) {
input.sort(function (a, b) {
return a - b;
});
}
return new Promise((resolve, reject) => {
jiff_instance.wait_for([1, 2], async () => {
try {
const inputs = await jiff_instance.share_array(input)

const array = inputs[1];
const elem = inputs[2];

const occurrences = await binary_search(array, elem);
result = await jiff_instance.open(occurrences);
resolve(result);

Check failure on line 45 in cypress/e2e/array-binary-search/mpc.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/mpc.js#L45

'result' is not defined.
} catch (error) {
reject(error);
}
});
});
};

function binary_search(array, element) {
if (array.length === 1) {
return array[0].seq(element);
}

// comparison
var mid = Math.floor(array.length / 2);
var cmp = element.slt(array[mid]);

// Slice array in half, choose slice depending on cmp
var nArray = [];
for (var i = 0; i < mid; i++) {
var c1 = array[i];
var c2 = array[mid + i];
nArray[i] = cmp.if_else(c1, c2);

Check warning on line 67 in cypress/e2e/array-binary-search/mpc.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/mpc.js#L67

Generic Object Injection Sink
}

// watch out for off by 1 errors if length is odd.
if (2 * mid < array.length) {
nArray[mid] = array[2 * mid];
}

return binary_search(nArray, element);
}
})(typeof exports === 'undefined' ? (this.mpc = {}) : exports, typeof exports !== 'undefined');
33 changes: 33 additions & 0 deletions cypress/e2e/array-binary-search/test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe('Array Binary Search', () => {
before(() => {
// Load the fixture data before the tests
cy.fixture('mpc_input.json').as('inputData');

Check failure on line 4 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L4

Unsafe call of an `any` typed value.
});

it('Search Output', () => {
// Visit the HTML page
cy.visit('http://localhost:8080/cypress/e2e/array-binary-search/client.html');

Check failure on line 9 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L9

Unsafe call of an `any` typed value.

// Load the input data and interact with the UI
cy.get('@inputData').then((inputData) => {

Check failure on line 12 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L12

Unsafe member access .get on an `any` value.
const arrayInput = (inputData as any)['array-binary-search']['1'] as number[];
const elementInput = (inputData as any)['array-binary-search']['2'] as number;

Check failure on line 14 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L14

Unsafe member access ['array-binary-search'] on an `any` value.

// Ensure the correct role is selected and the inputs are visible
cy.get('#connectButton').click();

// Input the array by contributor 1
cy.get('#input1').should('be.visible');

Check failure on line 20 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L20

Unsafe call of an `any` typed value.
cy.get('#inputArray').clear().type(JSON.stringify(arrayInput));
cy.get('#submit1').click();

// Input the element to be searched by contributor 2
cy.get('#input2').should('be.visible');

Check failure on line 25 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L25

Unsafe call of an `any` typed value.

Check failure on line 25 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L25

Unsafe member access .get on an `any` value.
cy.get('#inputElement').clear().type(`${elementInput}`);
cy.get('#submit2').click();

Check failure on line 27 in cypress/e2e/array-binary-search/test.cy.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/test.cy.ts#L27

Unsafe call of an `any` typed value.

// Check the output
cy.get('#output').should('contain', 'Element Found');
});
});
});
27 changes: 27 additions & 0 deletions cypress/e2e/array-binary-search/web-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
importScripts('./mpc.js', '../../../dist/jiff-client.js', '../../../dist/jiff-client-websockets.js');

let elem_instance;
let array_instance;

self.onmessage = function (event) {
const data = event.data;

switch (data.type) {
case 'init_elem':
elem_instance = mpc.connect(data.hostname, data.computation_id, data.options);

Check failure on line 11 in cypress/e2e/array-binary-search/web-worker.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/web-worker.js#L11

'mpc' is not defined.
break;
case 'init_array':
array_instance = mpc.connect(data.hostname, data.computation_id, data.options);

Check failure on line 14 in cypress/e2e/array-binary-search/web-worker.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/web-worker.js#L14

'mpc' is not defined.
break;
case 'computeElement':
mpc.compute(data.input, elem_instance).then((result) => {
self.postMessage({ result: result, type: 'element' });
});
break;
case 'computeArray':
mpc.compute(data.input, array_instance).then((result) => {

Check failure on line 22 in cypress/e2e/array-binary-search/web-worker.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/e2e/array-binary-search/web-worker.js#L22

'mpc' is not defined.
self.postMessage({ result: result, type: 'array' });
});
break;
}
};
3 changes: 3 additions & 0 deletions cypress/fixtures/mpc_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"array-binary-search": {"1": [1, 2, 3], "2":3}
}
Empty file added cypress/support/commands.d.ts
Empty file.
1 change: 1 addition & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// / <reference types="cypress" />
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
// import './commands'

// Alternatively you can use CommonJS syntax:
require('./commands');
18 changes: 18 additions & 0 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let path = require('path');

Check failure on line 1 in cypress/support/server.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/support/server.ts#L1

Unsafe assignment of an `any` value.
let express = require('express');

Check failure on line 2 in cypress/support/server.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/support/server.ts#L2

Require statement not part of import statement.
let app = express();

Check failure on line 3 in cypress/support/server.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/support/server.ts#L3

Unsafe call of an `any` typed value.
let http = require('http').Server(app);

Check failure on line 4 in cypress/support/server.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/support/server.ts#L4

Unsafe assignment of an `any` value.
let JIFFServer = require('../../lib/jiff-server');
let jiff_instance = new JIFFServer(http, { logs: true });

// Serve static files.
app.use('/cypress', express.static(path.join(__dirname, '..', '..', 'cypress')));
app.use('/dist', express.static(path.join(__dirname, '..', '..', 'dist')));

Check failure on line 10 in cypress/support/server.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/support/server.ts#L10

Unsafe member access .use on an `any` value.
app.use('/lib/ext', express.static(path.join(__dirname, '..', '..', 'lib', 'ext')));

let jiffWebsocketServer = require('../../lib/ext/jiff-server-websockets');
jiff_instance.apply_extension(jiffWebsocketServer);

Check failure on line 14 in cypress/support/server.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cypress/support/server.ts#L14

Unsafe member access .apply_extension on an `any` value.

http.listen(8080, function () {
console.log('listening on *:8080');
});
Loading
Loading