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

add testing framework #33

Merged
merged 2 commits into from
May 30, 2024
Merged
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
144 changes: 74 additions & 70 deletions src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,88 @@
function testInstruction(
encodedInstruction: string = "0x208b7fff7fff7ffe",
): void {
const instruction: [any[]] = DECODE_INSTRUCTION(encodedInstruction);
console.log(instruction);
}
function testRunner() {
if (typeof GasTap === "undefined") {
eval(
UrlFetchApp.fetch(
"https://raw.githubusercontent.com/huan/gast/master/src/gas-tap-lib.js",
).getContentText(),
ClementWalter marked this conversation as resolved.
Show resolved Hide resolved
);
}

function testGetR1C1(): void {
var ss: GoogleAppsScript.Spreadsheet.Spreadsheet =
SpreadsheetApp.getActiveSpreadsheet();
var sheet: GoogleAppsScript.Spreadsheet.Sheet = ss.getSheets()[0];
var test = new GasTap();

var range: GoogleAppsScript.Spreadsheet.Range = sheet.getRange("B5");
var formula: number = range.getColumn();
Logger.log(formula);
}
test("instruction decoder", (t) => {
var encodedInstruction: string = "0x208b7fff7fff7ffe";
const instruction: [any[]] = DECODE_INSTRUCTION(encodedInstruction);
const expectedInstruction: [any[]] = [
["Ret", "[FP - 2]", "[FP - 1]", "jmp abs", "AP", "Dst"],
];
t.deepEqual(instruction, expectedInstruction);
});

function testGetProgram(): void {
const program: any[][] = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName("Program")
.getRange("A2:A")
.getValues();
Logger.log(program);
}
test("object from array", (t) => {
const keys: string[] = ["a", "b", "c"];
ClementWalter marked this conversation as resolved.
Show resolved Hide resolved
const values: number[] = [1, 2, 3];
const target: any = objectFromEntries(keys, values);
const expectedTarget = { b: 2.0, a: 1.0, c: 3.0 };
t.deepEqual(target, expectedTarget);
});

function testObjectFromArray(): void {
const keys: string[] = ["a", "b", "c"];
const values: number[] = [1, 2, 3];
const target: any = objectFromEntries(keys, values);
Logger.log(target);
}
test("ec addition (pedersen)", (t) => {
var P = new AffinePoint(
ClementWalter marked this conversation as resolved.
Show resolved Hide resolved
"45477851653901153117103016505176923677805691341513469374986918421704783798",
"183085939200008105303514891306249502070824714566204820793608690653248096343",
);
var Q = new AffinePoint(
"1110490586165327629491026518265864493948957016447342824580924691292949995955",
"3150911138446828848637348285516855379003902600135909185517179002759670428860",
);
var minusP = new AffinePoint(
"45477851653901153117103016505176923677805691341513469374986918421704783798",
"-183085939200008105303514891306249502070824714566204820793608690653248096343",
);
var neutralElement = new AffinePoint("0x0", "0x0", true);

function testCurrentStep(): void {
Logger.log(getLastActiveRowIndex("A") - 2);
}
var R: AffinePoint;
var expectedR;

function testAddition(): void {
var P = new AffinePoint(
"45477851653901153117103016505176923677805691341513469374986918421704783798",
"183085939200008105303514891306249502070824714566204820793608690653248096343",
);
var Q = new AffinePoint(
"1110490586165327629491026518265864493948957016447342824580924691292949995955",
"3150911138446828848637348285516855379003902600135909185517179002759670428860",
);
var minusP = new AffinePoint(
"45477851653901153117103016505176923677805691341513469374986918421704783798",
"-183085939200008105303514891306249502070824714566204820793608690653248096343",
);
var neutralElement = new AffinePoint("0x0", "0x0", true);
Logger.log(add(P, neutralElement));
//Expect :
//x=45477851653901153117103016505176923677805691341513469374986918421704783798
//y=183085939200008105303514891306249502070824714566204820793608690653248096343
Logger.log(add(neutralElement, P));
//x=45477851653901153117103016505176923677805691341513469374986918421704783798
//y=183085939200008105303514891306249502070824714566204820793608690653248096343
Logger.log(add(P, minusP));
//Expect :
//isNeutralElement=true
Logger.log(add(P, P));
//Expect :
//x=1968885970339083619948296146201104092252508104349267720068326878178341392969
//y=593121236708823356289653686480454355603982629001053929931980663109960391985
Logger.log(add(P, Q));
//Expect :
//x=2825233123465961750980798694652743017262313358557354910947070689454726096961
//y=3554824400633731496516020947624430028316074332303691877626182575674539922487
}
R = add(P, neutralElement);
expectedR = P;
t.deepEqual(R, expectedR, "P + 0 = P");

function testPedersen(): void {
Logger.log(
pedersen(
R = add(neutralElement, P);
expectedR = P;
t.deepEqual(R, expectedR, "0 + P = P");

R = add(P, minusP);
t.equal(R.isNeutralElement, true, "P - P = 0");

R = add(P, P);
expectedR = new AffinePoint(
"1968885970339083619948296146201104092252508104349267720068326878178341392969",
"593121236708823356289653686480454355603982629001053929931980663109960391985",
);
t.deepEqual(R, expectedR, "P + P");

R = add(P, Q);
expectedR = new AffinePoint(
"2825233123465961750980798694652743017262313358557354910947070689454726096961",
"3554824400633731496516020947624430028316074332303691877626182575674539922487",
);
t.deepEqual(R, expectedR, "P + Q");
});

test("pedersen hash", (t) => {
var hash: string = pedersen(
BigInt(
"0x03d937c035c878245caf64531a5756109c53068da139362728feb561405371cb",
),
BigInt(
"0x0208a0a10250e382e1e4bbe2880906c2791bf6275695e02fbbc6aeff9cd8b31a",
),
).toString(16),
);
//Expect :
//30e480bed5fe53fa909cc0f8c4d99b8f9f2c016be4c41e13a4848797979c662
).toString(16);
var expectedHash: string =
"30e480bed5fe53fa909cc0f8c4d99b8f9f2c016be4c41e13a4848797979c662";
t.equal(hash, expectedHash);
});

test.finish();
}
1 change: 0 additions & 1 deletion src/ui/Code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function DECODE_INSTRUCTION(encodedInstruction: string): [any[]] {
const instruction: decodedInstruction = decodeInstruction(
BigInt(encodedInstruction),
);
Logger.log(instruction);

if (
instruction.Opcode === Opcodes.NOp &&
Expand Down
Loading