mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
fix test code
This commit is contained in:
@@ -5,8 +5,10 @@ import fs from 'fs';
|
||||
import {
|
||||
VERIFICATION_TYPE_ENUM_PROVE,
|
||||
VERIFICATION_TYPE_ENUM_DSC,
|
||||
PROVE_RSA_BLINDED_DSC_COMMITMENT_INDEX
|
||||
PROVE_RSA_BLINDED_DSC_COMMITMENT_INDEX,
|
||||
PROVE_RSA_CURRENT_DATE_INDEX
|
||||
} from "../../../common/src/constants/contractConstants";
|
||||
import { Block } from "ethers";
|
||||
import { PassportData } from "../../../common/src/utils/types";
|
||||
import { genMockPassportData } from "../../../common/src/utils/genMockPassportData";
|
||||
import {
|
||||
@@ -53,6 +55,9 @@ describe("Test one time verification flow", async function () {
|
||||
let addr1: any;
|
||||
let addr2: any;
|
||||
|
||||
let prove_proof: any;
|
||||
let dsc_proof: any;
|
||||
|
||||
// mock passport
|
||||
let mockPassport: PassportData = genMockPassportData(
|
||||
"rsa_sha256",
|
||||
@@ -170,6 +175,24 @@ describe("Test one time verification flow", async function () {
|
||||
);
|
||||
|
||||
snapshotId = await ethers.provider.send("evm_snapshot", []);
|
||||
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
const currentTimestamp = convertYYMMDDToTimestamp(prove_proof, PROVE_RSA_CURRENT_DATE_INDEX);
|
||||
const latestBlock = await ethers.provider.getBlock("latest") as Block;
|
||||
if (currentTimestamp < latestBlock.timestamp - 172800) {
|
||||
console.log("This proof is outdated, generating new proof");
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
@@ -179,21 +202,6 @@ describe("Test one time verification flow", async function () {
|
||||
|
||||
describe("test", async function() {
|
||||
it("Should be able to mint and set attributes", async function() {
|
||||
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
await oneTimeSBT.mint(
|
||||
PROVE_RSA_65537_SHA256_VERIFIER_ID,
|
||||
DSC_RSA65537_SHA256_4096_VERIFIER_ID,
|
||||
@@ -213,24 +221,9 @@ describe("Test one time verification flow", async function () {
|
||||
});
|
||||
|
||||
it("Should not be able to mint with invalid prove proof", async function() {
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let invalid_prove_proof = prove_proof;
|
||||
let invalid_prove_proof = JSON.parse(JSON.stringify(prove_proof));
|
||||
invalid_prove_proof[0] = [0, 0];
|
||||
|
||||
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
await expect(
|
||||
oneTimeSBT.mint(
|
||||
PROVE_RSA_65537_SHA256_VERIFIER_ID,
|
||||
@@ -239,7 +232,7 @@ describe("Test one time verification flow", async function () {
|
||||
a: invalid_prove_proof[0],
|
||||
b: invalid_prove_proof[1],
|
||||
c: invalid_prove_proof[2],
|
||||
pubSignals: prove_proof[3]
|
||||
pubSignals: invalid_prove_proof[3]
|
||||
},
|
||||
{
|
||||
a: dsc_proof[0],
|
||||
@@ -255,20 +248,6 @@ describe("Test one time verification flow", async function () {
|
||||
});
|
||||
|
||||
it("Should not be able to mint with invalid dsc proof", async function() {
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
let invalid_dsc_proof = dsc_proof;
|
||||
invalid_dsc_proof[0] = [0, 0];
|
||||
|
||||
@@ -286,7 +265,7 @@ describe("Test one time verification flow", async function () {
|
||||
a: invalid_dsc_proof[0],
|
||||
b: invalid_dsc_proof[1],
|
||||
c: invalid_dsc_proof[2],
|
||||
pubSignals: dsc_proof[3]
|
||||
pubSignals: invalid_dsc_proof[3]
|
||||
},
|
||||
)
|
||||
).to.be.revertedWithCustomError(
|
||||
@@ -296,20 +275,6 @@ describe("Test one time verification flow", async function () {
|
||||
});
|
||||
|
||||
it("Should not be able to mint with invalid blinded dcs", async function() {
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
let invalid_prove_proof = prove_proof;
|
||||
invalid_prove_proof[3][PROVE_RSA_BLINDED_DSC_COMMITMENT_INDEX] = 0;
|
||||
|
||||
@@ -437,5 +402,49 @@ describe("Test one time verification flow", async function () {
|
||||
let dsc_proof = JSON.parse("[" + rawCallData_dsc + "]");
|
||||
fs.writeFileSync("./test/integrationTest/proof_dsc.json", JSON.stringify(dsc_proof));
|
||||
return dsc_proof;
|
||||
};
|
||||
|
||||
function convertYYMMDDToTimestamp(proveProof: any[], index: number): number {
|
||||
const dateDigits = proveProof[3].slice(index, index + 6);
|
||||
|
||||
if (dateDigits.length !== 6) {
|
||||
throw new Error("Insufficient date digits");
|
||||
}
|
||||
|
||||
const digits = dateDigits.map((digit: string) => {
|
||||
const num = Number(BigInt(digit));
|
||||
if (isNaN(num) || num < 0 || num > 9) {
|
||||
throw new Error(`Invalid digit value: ${digit}`);
|
||||
}
|
||||
return num.toString();
|
||||
});
|
||||
|
||||
// Correctly join the digits without padding each digit
|
||||
const yymmdd = digits.join('');
|
||||
console.log("yymmdd: ", yymmdd);
|
||||
|
||||
const yy = parseInt(yymmdd.slice(0, 2), 10);
|
||||
const mm = parseInt(yymmdd.slice(2, 4), 10);
|
||||
const dd = parseInt(yymmdd.slice(4, 6), 10);
|
||||
|
||||
const year = 2000 + yy;
|
||||
|
||||
if (mm < 1 || mm > 12) {
|
||||
throw new Error(`Invalid month value: ${mm}`);
|
||||
}
|
||||
|
||||
if (dd < 1 || dd > 31) {
|
||||
throw new Error(`Invalid day value: ${dd}`);
|
||||
}
|
||||
|
||||
const date = new Date(year, mm - 1, dd);
|
||||
if (date.getFullYear() !== year || date.getMonth() !== mm - 1 || date.getDate() !== dd) {
|
||||
throw new Error("Invalid date provided");
|
||||
}
|
||||
|
||||
const timestamp = Math.floor(date.getTime() / 1000);
|
||||
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -1 +1 @@
|
||||
[["0x24ba9d649f5a06f94d80bcba2aecd0b884bfcb0158901d515274c05b844efeaa","0x03f065fafc622d89e0dde18bd2a8cb2a09dbbe3c92b3843c9304e3e46bca60c3"],[["0x0a925f4feeb60ccd6f0ccb89ae1fe8302fcae46fbd0f0444acac67ad1135179c","0x211b5cc5e162b0c28f741157ac2009ceb0e0319334c7fcc1a8126635276350f1"],["0x2a071d0a53b804fb7225c369d4204a724076e783d9b41e4ebefacf6f32dbf618","0x0b4ab3d3ecba9dcc49792680127c48ed7f4ab02cf0939b19072bc92d96c7323b"]],["0x238d17933d790f5c734e29c315b1abe58e0aac32a3dedad40c0b251e1dcc949b","0x30225ca0dcafbb405edbf7e05483193341c7c12640410a84ec960a2b0f6afdfb"],["0x0030186e34532bd2527db97cb8452c23620434945a2a41faf060e74a5ca9aceb"]]
|
||||
[["0x03e50b3c08f74261e9facdb204937fdd61367483f51f08416af792a1d1cbd879","0x20c37dc1781c6365130505ea65fed9b6648080cb0e64af51c0974462260be481"],[["0x1ef75d57be6f743c5ea15d0043a2255eb575d3ecba92d15edb56fe29e6306b85","0x0ff62770b9cce788ce1fd102eeb6f66db6bc536a803124b8f48d484ebee138db"],["0x0d26fe18ad8fe026d2fa5c3b3ef4d68839319ce1fb3a8c12ccbf2c1d8512b86d","0x065812043fee1b864e69ecbbfc7c2ede328bf2b5e117a05f6f3159b5cb160241"]],["0x08543216d8f0dc42187962522996d204e35a7456ed1e966fadc070d868c1f352","0x06cc0dd9e172b6a22c97c5daf71108b2ad70dae392c9f44e9a52467ee70cb087"],["0x0030186e34532bd2527db97cb8452c23620434945a2a41faf060e74a5ca9aceb"]]
|
||||
@@ -1 +1 @@
|
||||
[["0x00e15e942224cabd624ce1a1950b21c6a7542f971b0b517e4ddbe798eb413276","0x020c43e89f6f32d18240f412ce6ff23c91f73f2ef1add62e3287de47cc9c1934"],[["0x1665c66a2fb763ee20439ac7b220ee6d6ad6665f177f235870a51fd027556fe1","0x2244b0c039ff2175fddfef1d3e5148ad111d18979f023ba2ece28bf597fa593e"],["0x18bc5c9767ee3c146e8d0e38ffb2960d5c4e57ed92a95737bad979f14cdff323","0x08b3de25aa44d2cefd78b46ac89098a0d4f7cc38791a3c849a97a38e9725e9ae"]],["0x166ba6cb8f85bc3d95d56996dd3e5e047324ccfdf041a58a7fe39f147d758bf2","0x1a02f81f700fc1594fcae70e5e46f73afea1a97512eae74753e20600e72b9d86"],["0x15338daadd18ce0c3bf1e04b835f33aed04f8d7f113e708f73056cb628414baa","0x00413c534555484755483c45534e4f48504c413c3c544e4f5055444152463c50","0x003331303439415246343433323138414135313c3c3c3c3c3c3c3c545245424c","0x00000000000032303c3c3c3c3c3c3c3c3c3c3c3c3c3c353133303130344d3131","0x0000000000000000000000000000000000000000000000000000000000000032","0x0000000000000000000000000000000000000000000000000000000000000030","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0041414141414141414141414141414141414141414141414141414141414141","0x0000000000004141414141414141414141414141414141414141414141414141","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0030186e34532bd2527db97cb8452c23620434945a2a41faf060e74a5ca9aceb","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000004","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8","0x0000000000000000000000000000000000000000000000000000000000000419"]]
|
||||
[["0x14446eac7e62c33783f4407d58c6b694ec9209caaf8002d467c294cd8a350373","0x1787552685ab87dea0cef21ecb33edf311b2baadaa496631c88c9f865a9dad38"],[["0x16578ccdb35b1c1a383474f03747ad9241d942642bae3c92f74080b47cc23105","0x2901f37f415b0abea6b3ab5fd9cd0dbc21e25b9a37c40c280e18f2bb2f7b2034"],["0x287a160c5cd2382359152c02a5bcb224b68d2f3aa6e087a5910a0f341cc97764","0x010d7df92b23fca34cb61dc54a9d8e88d7f99facc2e4e9b008f5517bb9da624f"]],["0x19026aec59ec453cccd8ed58b705e3bcf5f87938d41433f2cc2c19f637592e2b","0x19cad4e9d4ef6ddef83e9739509b3b02729528e61246a956cee6b91fb14361c3"],["0x2b8712069affa7f52e351e6b3871bf1d13e259c1f09df4ae805b5c6dcb4c14ec","0x00413c534555484755483c45534e4f48504c413c3c544e4f5055444152463c50","0x003331303439415246343433323138414135313c3c3c3c3c3c3c3c545245424c","0x00000000000032303c3c3c3c3c3c3c3c3c3c3c3c3c3c353133303130344d3131","0x0000000000000000000000000000000000000000000000000000000000000032","0x0000000000000000000000000000000000000000000000000000000000000030","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0041414141414141414141414141414141414141414141414141414141414141","0x0000000000004141414141414141414141414141414141414141414141414141","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0030186e34532bd2527db97cb8452c23620434945a2a41faf060e74a5ca9aceb","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000004","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000006","0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8","0x0000000000000000000000000000000000000000000000000000000000000419"]]
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user