fix tests; remove hardcoded batchHeight
This commit is contained in:
parent
93dd5d5e86
commit
4f732d05bc
@ -55,9 +55,9 @@ function prove(input, keyBasePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function batchTreeUpdate(tree, events) {
|
function batchTreeUpdate(tree, events) {
|
||||||
const batchHeight = 2 //await this.tornadoTreesContract.CHUNK_TREE_HEIGHT()
|
const batchHeight = Math.log2(events.length)
|
||||||
if (events.length !== 1 << batchHeight) {
|
if (!Number.isInteger(batchHeight)) {
|
||||||
throw new Error('events length does not match the batch size')
|
throw new Error('events length has to be power of 2')
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldRoot = tree.root().toString()
|
const oldRoot = tree.root().toString()
|
||||||
|
@ -140,14 +140,15 @@ describe('TornadoTrees', function () {
|
|||||||
instance: toFixedHex(e.args.instance, 20),
|
instance: toFixedHex(e.args.instance, 20),
|
||||||
block: toFixedHex(e.args.block, 4),
|
block: toFixedHex(e.args.block, 4),
|
||||||
}))
|
}))
|
||||||
;({ input, args } = controller.batchTreeUpdate(tree, registeredEvents.slice(0, 4)))
|
;({ input, args } = controller.batchTreeUpdate(tree, registeredEvents.slice(0, notes.length)))
|
||||||
proof = await controller.prove(input, './artifacts/circuits/BatchTreeUpdate')
|
proof = await controller.prove(input, './artifacts/circuits/BatchTreeUpdate')
|
||||||
await tornadoTrees.updateDepositTree(proof, ...args)
|
await tornadoTrees.updateDepositTree(proof, ...args)
|
||||||
updatedRoot = await tornadoTrees.depositRoot()
|
updatedRoot = await tornadoTrees.depositRoot()
|
||||||
expect(updatedRoot).to.be.equal(tree.root())
|
expect(updatedRoot).to.be.equal(tree.root())
|
||||||
})
|
})
|
||||||
it('should work for batch+N filled v1 tree', async () => {
|
it('should work for batch+N filled v1 tree', async () => {
|
||||||
for (let i = 4; i < 6; i++) {
|
const batchSize = 2 ** CHUNK_TREE_HEIGHT
|
||||||
|
for (let i = batchSize; i < batchSize + 2; i++) {
|
||||||
notes.push({
|
notes.push({
|
||||||
instance: instances[i % instances.length],
|
instance: instances[i % instances.length],
|
||||||
depositBlock: blocks[i % blocks.length],
|
depositBlock: blocks[i % blocks.length],
|
||||||
@ -172,27 +173,32 @@ describe('TornadoTrees', function () {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// load first batchSize deposits
|
||||||
let { input, args } = controller.batchTreeUpdate(tree, depositEvents)
|
let { input, args } = controller.batchTreeUpdate(tree, depositEvents)
|
||||||
let proof = await controller.prove(input, './artifacts/circuits/BatchTreeUpdate')
|
let proof = await controller.prove(input, './artifacts/circuits/BatchTreeUpdate')
|
||||||
await newTornadoTrees.updateDepositTree(proof, ...args)
|
await newTornadoTrees.updateDepositTree(proof, ...args)
|
||||||
let updatedRoot = await newTornadoTrees.depositRoot()
|
let updatedRoot = await newTornadoTrees.depositRoot()
|
||||||
expect(updatedRoot).to.be.equal(tree.root())
|
expect(updatedRoot).to.be.equal(tree.root())
|
||||||
|
|
||||||
// register 6 new deposits for the new trees
|
// register 2 * `notes.length` new deposits on the new trees
|
||||||
|
for (let i = 0; i < notes.length; i++) {
|
||||||
|
await register(notes[i], newTornadoTrees, tornadoProxy)
|
||||||
|
}
|
||||||
for (let i = 0; i < notes.length; i++) {
|
for (let i = 0; i < notes.length; i++) {
|
||||||
await register(notes[i], newTornadoTrees, tornadoProxy)
|
await register(notes[i], newTornadoTrees, tornadoProxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get 2 events from v1 tress
|
// get 2 extra events from v1 tress
|
||||||
let events = notes.slice(4).map((note) => ({
|
let events = notes.slice(batchSize).map((note) => ({
|
||||||
hash: toFixedHex(note.commitment),
|
hash: toFixedHex(note.commitment),
|
||||||
instance: toFixedHex(note.instance, 20),
|
instance: toFixedHex(note.instance, 20),
|
||||||
block: toFixedHex(note.depositBlock, 4),
|
block: toFixedHex(note.depositBlock, 4),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const registeredEvents = await newTornadoTrees.queryFilter(depositDataEventFilter)
|
let registeredEvents = await newTornadoTrees.queryFilter(depositDataEventFilter)
|
||||||
|
registeredEvents = registeredEvents.slice(batchSize) // cut processed deposits from v1
|
||||||
events = events.concat(
|
events = events.concat(
|
||||||
registeredEvents.slice(0, 2).map((e) => ({
|
registeredEvents.slice(0, batchSize - 2).map((e) => ({
|
||||||
hash: toFixedHex(e.args.hash),
|
hash: toFixedHex(e.args.hash),
|
||||||
instance: toFixedHex(e.args.instance, 20),
|
instance: toFixedHex(e.args.instance, 20),
|
||||||
block: toFixedHex(e.args.block, 4),
|
block: toFixedHex(e.args.block, 4),
|
||||||
@ -205,7 +211,7 @@ describe('TornadoTrees', function () {
|
|||||||
updatedRoot = await newTornadoTrees.depositRoot()
|
updatedRoot = await newTornadoTrees.depositRoot()
|
||||||
expect(updatedRoot).to.be.equal(tree.root())
|
expect(updatedRoot).to.be.equal(tree.root())
|
||||||
|
|
||||||
events = registeredEvents.slice(6).map((e) => ({
|
events = registeredEvents.slice(batchSize - 2, 2 * batchSize - 2).map((e) => ({
|
||||||
hash: toFixedHex(e.args.hash),
|
hash: toFixedHex(e.args.hash),
|
||||||
instance: toFixedHex(e.args.instance, 20),
|
instance: toFixedHex(e.args.instance, 20),
|
||||||
block: toFixedHex(e.args.block, 4),
|
block: toFixedHex(e.args.block, 4),
|
||||||
|
Loading…
Reference in New Issue
Block a user