8000 feat: test with rust test by ieow · Pull Request #1 · ieow/tkey · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: test with rust test #1

New issue

Have a question about this project? Sign up for a free GitHub account to o 8000 pen 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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions packages/default/test/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { keccak256 } from "web3-utils";

import ThresholdKey from "../src/index";
import { getMetadataUrl, getServiceProvider, initStorageLayer, isMocked } from "./helpers";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { greet, test_function_fail, test_function_pass } from "./wasm-nodejs/tkey";

const rejects = async (fn, error, msg) => { 8000
let f = () => {};
Expand Down Expand Up @@ -67,6 +69,9 @@ export const sharedTestCases = (mode, torusSP, storageLayer) => {
let tb;
beforeEach("Setup ThresholdKey", async function () {
tb = new ThresholdKey({ serviceProvider: customSP, storageLayer: customSL, manualSync: mode });

// eslint-disable-next-line no-console
console.log(greet("test"));
});
it("#should be able to initializeNewKey using initialize and reconstruct it", async function () {
const sp = customSP;
Expand All @@ -79,6 +84,12 @@ export const sharedTestCases = (mode, torusSP, storageLayer) => {
if (tb2.privKey.cmp(reconstructedKey.privKey) !== 0) {
fail("key should be able to be reconstructed");
}

// eslint-disable-next-line no-console
console.log(greet("pass json as string to rust thru wasm, and run the test function in rust"));
// eslint-disable-next-line no-console
console.log(await test_function_pass(JSON.stringify({ test: "pass" })));
await test_function_fail(JSON.stringify({ test: "failed" }));
});
it(`#should be able to reconstruct key when initializing a key, manualSync=${mode}`, async function () {
const resp1 = await tb._initializeNewKey({ initializeModules: true });
Expand Down
135 changes: 135 additions & 0 deletions packages/default/test/wasm-nodejs/tkey.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} json_string
* @returns {string}
*/
export function test_function_pass(json_string: string): string;
/**
* @param {string} json_string
* @returns {string}
*/
export function test_function_fail(json_string: string): string;
/**
* @param {string} repo
* @returns {Promise<any>}
*/
export function run(repo: string): Promise<any>;
/**
* @param {string} curve_n
* @returns {string}
*/
export function generate_private_key(curve_n: string): string;
/**
* @param {boolean} enable_logging
* @param {string} host_url
* @param {bigint} server_time_offset
* @returns {number}
*/
export function storage_layer(enable_logging: boolean, host_url: string, server_time_offset: bigint): number;
/**
* @param {number} ptr
*/
export function storage_layer_free(ptr: number): void;
/**
* @param {boolean} enable_logging
* @param {string} postbox_key
* @param {string} curve_n
* @returns {number}
*/
export function service_provider(enable_logging: boolean, postbox_key: string, curve_n: string): number;
/**
* @param {number} ptr
*/
export function service_provider_free(ptr: number): void;
/**
* @param {number} metadata
* @param {number} shares
* @param {number} storage_layer
* @param {number} service_provider
* @param {number} local_metadata_transitions
* @param {number} last_fetch_cloud_metadata
* @param {boolean} enable_logging
* @param {boolean} manual_sync
* @returns {number}
*/
export function threshold_key(metadata: number, shares: number, storage_layer: number, service_provider: number, local_metadata_transitions: number, last_fetch_cloud_metadata: number, enable_logging: boolean, manual_sync: boolean): number;
/**
* @param {number} ptr
*/
export function threshold_key_free(ptr: number): void;
/**
* @param {number} threshold_key
* @param {string | undefined} import_share
* @param {number} input
* @param {boolean} never_initialize_new_key
* @param {boolean} include_local_metadata_transitions
* @param {string} curve_n
* @returns {number}
*/
export function threshold_key_initialize(threshold_key: number, import_share: string | undefined, input: number, never_initialize_new_key: boolean, include_local_metadata_transitions: boolean, curve_n: string): number;
/**
* @param {number} threshold_key
* @param {string} curve_n
* @returns {any}
*/
export function threshold_key_reconstruct(threshold_key: number, curve_n: string): any;
/**
* @param {number} ptr
* @returns {number}
*/
export function test_ptr(ptr: number): number;
/**
* @returns {number}
*/
export function null_ptr(): number;
/**
* @param {string} name
* @returns {string}
*/
export function greet(name: string): string;
/**
* @param {string} x
* @param {string} y
* @returns {Point}
*/
export function new_point(x: string, y: string): Point;
/**
* @param {Point} point
* @returns {string}
*/
export function from_point(point: Point): string;
/**
* @param {string} encoding
* @returns {Point}
*/
export function point_from_decode(encoding: string): Point;
/**
* @param {Point} point
* @returns {string}
*/
export function compress_pubkey(point: Point): string;
/**
* @param {Point} point
* @returns {string}
*/
export function new_metadata(point: Point): string;
/**
* @param {Point} point
* @returns {number}
*/
export function new_mut_metadata(point: Point): number;
/**
* @param {number} metadata
*/
export function metadata_free(metadata: number): void;
/**
* @param {number} metadata
* @returns {string}
*/
export function metadata_get_pubkey(metadata: number): string;
/**
*/
export class Point {
free(): void;
}
Loading
0