From 4a1fc29a8bd745984953b8b794226ea44ccc5c9e Mon Sep 17 00:00:00 2001 From: dev0x1 Date: Tue, 10 Oct 2023 17:30:34 +0530 Subject: [PATCH] add poseidon test for 6-elements array --- .../contracts/test/hasher/PoseidonHasher.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/contracts/test/hasher/PoseidonHasher.test.ts b/packages/contracts/test/hasher/PoseidonHasher.test.ts index 4c384a22..77b6a228 100644 --- a/packages/contracts/test/hasher/PoseidonHasher.test.ts +++ b/packages/contracts/test/hasher/PoseidonHasher.test.ts @@ -8,6 +8,7 @@ import { BigNumber } from 'ethers'; import { contract, ethers } from 'hardhat'; import { PoseidonHasher } from '@webb-tools/anchors'; const assert = require('assert'); +import { poseidon } from 'circomlibjs'; contract('Poseidon hasher', (accounts) => { let hasherInstance: PoseidonHasher; @@ -20,9 +21,18 @@ contract('Poseidon hasher', (accounts) => { }); describe('#sponge-hash', () => { - it('should hash random values of array', async () => { + it('should hash random values of 6-elements array', async () => { const inputs: any = []; - for (let i = 0; i < 13; i++) { + for (let i = 0; i < 6; i++) { + inputs.push(randomBN()); + } + let contractResult = await hasherInstance.contract.hash6(inputs); + let result = poseidon(inputs); + assert.strictEqual(result.toString(), contractResult.toString()); + }); + it('should hash random values of 50-elements array', async () => { + const inputs: any = []; + for (let i = 0; i < 50; i++) { inputs.push(randomBN()); } let contractResult = await hasherInstance.contract.hash(inputs);