tornado-trees/test/snark.test.js

25 lines
799 B
JavaScript
Raw Normal View History

2021-02-02 14:27:58 +03:00
const { expect } = require('chai')
2021-02-01 16:40:32 +03:00
const MerkleTree = require('fixed-merkle-tree')
const { poseidonHash2, randomBN } = require('../src/utils')
const { batchTreeUpdate, prove } = require('../src/controller')
const levels = 20
const CHUNK_TREE_HEIGHT = 2
2021-02-02 14:20:59 +03:00
describe('Snark', () => {
2021-02-01 16:40:32 +03: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(),
})
}
const data = await batchTreeUpdate(tree, events)
2021-02-02 14:20:59 +03:00
const proof = await prove(data, './artifacts/circuits/BatchTreeUpdate')
2021-02-02 14:38:11 +03:00
expect(proof.length).to.be.gt(0)
2021-02-01 16:40:32 +03:00
})
})