tornado-trees/test/snark.test.js

25 lines
794 B
JavaScript
Raw Permalink Normal View History

2021-02-02 12:27:58 +01:00
const { expect } = require('chai')
2021-02-01 14:40:32 +01:00
const MerkleTree = require('fixed-merkle-tree')
const { poseidonHash2, randomBN } = require('../src/utils')
2021-02-07 11:27:00 +01:00
const { batchTreeUpdate, prove } = require('../src/index')
2021-02-01 14:40:32 +01:00
const levels = 20
2021-02-26 09:17:13 +01:00
const CHUNK_TREE_HEIGHT = 8
2021-02-02 12:20:59 +01:00
describe('Snark', () => {
2021-02-01 14:40:32 +01:00
it('should work', async () => {
const tree = new MerkleTree(levels, [], { hashFunction: poseidonHash2 })
const events = []
for (let i = 0; i < 2 ** CHUNK_TREE_HEIGHT; i++) {
events.push({
hash: randomBN(31).toString(),
instance: randomBN(20).toString(),
block: randomBN(4).toString(),
})
}
2021-02-02 20:46:51 +01:00
const { input } = batchTreeUpdate(tree, events)
const proof = await prove(input, './artifacts/circuits/BatchTreeUpdate')
2021-02-02 12:38:11 +01:00
expect(proof.length).to.be.gt(0)
2021-02-01 14:40:32 +01:00
})
})