Skip to content

Commit 38e0c38

Browse files
committed
test: add mock test for falconVerify
1 parent ab53bd3 commit 38e0c38

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

docs/coverage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,4 @@ See which `algorand-typescript` stubs are implemented by the `algorand-typescrip
151151
| op.sqrt | Native |
152152
| op.substring | Native |
153153
| op.vrfVerify | Mockable |
154+
| op.falconVerify | Mockable |

src/impl/crypto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ export const mimc = (_c: MimcConfigurations, _a: StubBytesCompat): bytes => {
147147
throw new NotImplementedError('mimc')
148148
}
149149

150+
/** @internal */
151+
export const falconVerify = (_a: StubBytesCompat, _b: StubBytesCompat, _c: StubBytesCompat): boolean => {
152+
throw new NotImplementedError('falconVerify')
153+
}
154+
150155
const curveMap = {
151156
[Ecdsa.Secp256k1]: 'secp256k1',
152157
[Ecdsa.Secp256r1]: 'p256',

src/internal/op.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export {
2424
ed25519verify,
2525
ed25519verifyBare,
2626
EllipticCurve,
27+
falconVerify,
2728
keccak256,
2829
mimc,
2930
sha256,

tests/crypto-op-codes.algo.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ vi.mock('../src/impl/crypto', async (importOriginal) => {
3030
...mod,
3131
vrfVerify: vi.fn(mod.vrfVerify),
3232
mimc: vi.fn(mod.mimc),
33+
falconVerify: vi.fn(mod.falconVerify),
3334
}
3435
})
3536

@@ -362,6 +363,27 @@ describe('crypto op codes', async () => {
362363
)
363364
})
364365
})
366+
367+
describe('falconVerify', async () => {
368+
const a = Bytes.fromHex('528b9e23d93d0e020a119d7ba213f6beb1c1f3495a217166ecd20f5a70e7c2d7')
369+
const b = op.bzero(1232).toFixed({ length: 1232 })
370+
371+
const c = op.bzero(1793).toFixed({ length: 1793 })
372+
373+
test('should throw not available error', async () => {
374+
const mockedFalconVerify = op.falconVerify as Mock<typeof op.falconVerify>
375+
// restore to original stub implemention which should throw not available error
376+
mockedFalconVerify.mockRestore()
377+
expect(() => op.falconVerify(a, b, c)).toThrow('falconVerify is not available in test context')
378+
})
379+
380+
test('should return mocked result', () => {
381+
const mockedFalconVerify = op.falconVerify as Mock<typeof op.falconVerify>
382+
mockedFalconVerify.mockReturnValue(true)
383+
const result = op.falconVerify(a, b, c)
384+
expect(result).toBe(true)
385+
})
386+
})
365387
})
366388

367389
const generateEcdsaTestData = (v: Ecdsa) => {

0 commit comments

Comments
 (0)