From 34ee9dcb0db218ed0eb08e433d3f763bd5e03558 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 5 Feb 2021 20:38:52 +0300 Subject: [PATCH] test with events --- test/tornadoTrees.test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/tornadoTrees.test.js b/test/tornadoTrees.test.js index ed036cb..c90766a 100644 --- a/test/tornadoTrees.test.js +++ b/test/tornadoTrees.test.js @@ -111,6 +111,33 @@ describe('TornadoTrees', function () { updatedRoot = await tornadoTrees.depositRoot() expect(updatedRoot).to.be.equal(tree.root()) }) + + it('should work with events from contracts', async () => { + let { input, args } = controller.batchTreeUpdate(tree, depositEvents) + let proof = await controller.prove(input, './artifacts/circuits/BatchTreeUpdate') + await tornadoTrees.updateDepositTree(proof, ...args) + let updatedRoot = await tornadoTrees.depositRoot() + expect(updatedRoot).to.be.equal(tree.root()) + + const filter = tornadoTrees.filters.DepositData() + const migratedEvents = await tornadoTrees.queryFilter(filter) + console.log('events', JSON.stringify(migratedEvents, null, 2)) + // + for (let i = 0; i < notes.length; i++) { + await register(notes[i], tornadoTrees, tornadoProxy) + } + let registeredEvents = await tornadoTrees.queryFilter(filter) + registeredEvents = registeredEvents.map((e) => ({ + hash: toFixedHex(e.args.hash), + instance: toFixedHex(e.args.instance, 20), + block: toFixedHex(e.args.block, 4), + })) + ;({ input, args } = controller.batchTreeUpdate(tree, registeredEvents)) + proof = await controller.prove(input, './artifacts/circuits/BatchTreeUpdate') + await tornadoTrees.updateDepositTree(proof, ...args) + updatedRoot = await tornadoTrees.depositRoot() + expect(updatedRoot).to.be.equal(tree.root()) + }) it('should reject for partially filled tree') it('should reject for outdated deposit root') it('should reject for incorrect insert index')