From 3ce669e7e55c110aedacbae8bc0934a854affaba Mon Sep 17 00:00:00 2001 From: Coby Date: Sun, 14 Apr 2024 12:19:17 -0400 Subject: [PATCH] fixing unit tests --- package-lock.json | 28 +++++------------------ package.json | 2 +- src/lib/packed-types/PackedBool.test.ts | 18 +++++++++------ src/lib/packed-types/PackedString.test.ts | 20 ++++++++-------- src/lib/packed-types/PackedUInt32.test.ts | 20 +++++++++------- 5 files changed, 41 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d04559..2c8abec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "o1js-pack", - "version": "0.5.1", + "version": "0.5.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "o1js-pack", - "version": "0.5.1", + "version": "0.5.4", "license": "Apache-2.0", "devDependencies": { "@babel/preset-env": "^7.16.4", @@ -24,7 +24,7 @@ "typescript": "^4.7.2" }, "peerDependencies": { - "o1js": "^0.16.0" + "o1js": "^0.18.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -3995,15 +3995,6 @@ "node": ">=0.4.0" } }, - "node_modules/detect-gpu": { - "version": "5.0.32", - "resolved": "https://registry.npmjs.org/detect-gpu/-/detect-gpu-5.0.32.tgz", - "integrity": "sha512-Z310uSFzHnWoInT7czpgPH8yuragsoylzFTatKHSZ11UDSm+pTRnR8U2bkhwGn9AECjl72oYoJWD+G3P8RW2NQ==", - "peer": true, - "dependencies": { - "webgl-constants": "^1.1.1" - } - }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -7451,14 +7442,13 @@ "dev": true }, "node_modules/o1js": { - "version": "0.16.0", - "resolved": "https://registry.npmjs.org/o1js/-/o1js-0.16.0.tgz", - "integrity": "sha512-H6fKHLgH68v18De0tZydQKqF2bOIvF+EsPHJ+P53dJDOaS7Dlp8Uf4hGVo8S8luCfYsFvCdDGU3YwfegfCk6TQ==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/o1js/-/o1js-0.18.0.tgz", + "integrity": "sha512-A4XFfRLUHxB8ZUzctpxmYA4kBi3ZRwSgeK/KKuWxf2kDmaxjWOxbCzH/1wHelom4QKIgSIaJpXkAtR0jJv7tqw==", "peer": true, "dependencies": { "blakejs": "1.2.1", "cachedir": "^2.4.0", - "detect-gpu": "^5.0.5", "isomorphic-fetch": "^3.0.0", "js-sha256": "^0.9.0", "reflect-metadata": "^0.1.13", @@ -8811,12 +8801,6 @@ "makeerror": "1.0.12" } }, - "node_modules/webgl-constants": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/webgl-constants/-/webgl-constants-1.1.1.tgz", - "integrity": "sha512-LkBXKjU5r9vAW7Gcu3T5u+5cvSvh5WwINdr0C+9jpzVB41cjQAP5ePArDtk/WHYdVj0GefCgM73BA7FlIiNtdg==", - "peer": true - }, "node_modules/webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", diff --git a/package.json b/package.json index 4277df0..ef15bfc 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,6 @@ "typescript": "^4.7.2" }, "peerDependencies": { - "o1js": "^0.16.2" + "o1js": "^0.18.0" } } diff --git a/src/lib/packed-types/PackedBool.test.ts b/src/lib/packed-types/PackedBool.test.ts index 2cdac4a..d1bda30 100644 --- a/src/lib/packed-types/PackedBool.test.ts +++ b/src/lib/packed-types/PackedBool.test.ts @@ -71,13 +71,17 @@ describe('PackedBool', () => { packedBool.assertEquals(outsidePackedBool); }); }).not.toThrow(); - expect(() => { - Provable.runAndCheck(() => { - const fakePacked = outsidePackedBool.packed.add(32); - const packedBool = new PackedBool(fakePacked); - packedBool.assertEquals(outsidePackedBool); - }); - }).toThrow(); + + // TODO: This test should not be in the "provable" block since it's not in the runAndCheck + // It seems like failures in the runAndCheck can't be tested for with #toThrow + try { + const fakePacked = outsidePackedBool.packed.add(32); + const packedBool = new PackedBool(fakePacked); + packedBool.assertEquals(outsidePackedBool); + fail('Expected to throw Field.assertEquals error'); + } catch (e: any) { + expect(e.message).toContain('Field.assertEquals'); + } }); }); }); diff --git a/src/lib/packed-types/PackedString.test.ts b/src/lib/packed-types/PackedString.test.ts index 1417ca5..715cbf3 100644 --- a/src/lib/packed-types/PackedString.test.ts +++ b/src/lib/packed-types/PackedString.test.ts @@ -130,15 +130,17 @@ describe('PackedString', () => { }); }).not.toThrow(); - expect(() => { - Provable.runAndCheck(() => { - const fakePacked = [...outsideEthAddress.packed]; - fakePacked[0] = fakePacked[0].add(1); - const myEthAddress = new EthAddressString(fakePacked); - - myEthAddress.assertEquals(outsideEthAddress); - }); - }).toThrow(); + // TODO: This test should not be in the "provable" block since it's not in the runAndCheck + // It seems like failures in the runAndCheck can't be tested for with #toThrow + try { + const fakePacked = [...outsideEthAddress.packed]; + fakePacked[0] = fakePacked[0].add(1); + const myEthAddress = new EthAddressString(fakePacked); + myEthAddress.assertEquals(outsideEthAddress); + fail('Expected to throw Field.assertEquals error'); + } catch (e: any) { + expect(e.message).toContain('Field.assertEquals'); + } }); }); }); diff --git a/src/lib/packed-types/PackedUInt32.test.ts b/src/lib/packed-types/PackedUInt32.test.ts index f721f0f..c11e7e2 100644 --- a/src/lib/packed-types/PackedUInt32.test.ts +++ b/src/lib/packed-types/PackedUInt32.test.ts @@ -75,20 +75,24 @@ describe('PackedUInt32', () => { }); }).not.toThrow(); }); - it('#assertEquals', () => { + it('#assertEquals', async () => { expect(() => { Provable.runAndCheck(() => { const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed); packedUInt32.assertEquals(outsidePackedUInt); }); }).not.toThrow(); - expect(() => { - Provable.runAndCheck(() => { - const fakePacked = outsidePackedUInt.packed.add(32); - const packedUInt32 = new PackedUInt32(fakePacked); - packedUInt32.assertEquals(outsidePackedUInt); - }); - }).toThrow(); + + // TODO: This test should not be in the "provable" block since it's not in the runAndCheck + // It seems like failures in the runAndCheck can't be tested for with #toThrow + try { + const fakePacked = outsidePackedUInt.packed.add(32); + const packedUInt32 = new PackedUInt32(fakePacked); + packedUInt32.assertEquals(outsidePackedUInt); + fail('Expected to throw Field.assertEquals error'); + } catch (e: any) { + expect(e.message).toContain('Field.assertEquals'); + } }); }); });