tornado-trees/test/snark.test.js

25 lines
794 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')
2021-02-07 13:27:00 +03:00
const { batchTreeUpdate, prove } = require('../src/index')
2021-02-01 16:40:32 +03:00
const levels = 20
2021-02-26 11:17:13 +03:00
const CHUNK_TREE_HEIGHT = 8
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(),
})
}
2021-02-02 22:46:51 +03:00
const { input } = batchTreeUpdate(tree, events)
const proof = await prove(input, './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
})
})