// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "../IncrementalBinaryTree.sol"; contract IncrementalBinaryTreeTest { using IncrementalBinaryTree for IncrementalTreeData; event TreeCreated(bytes32 id, uint256 depth); event LeafInserted(bytes32 indexed treeId, uint256 leaf, uint256 root); event LeafUpdated(bytes32 indexed treeId, uint256 leaf, uint256 root); event LeafRemoved(bytes32 indexed treeId, uint256 leaf, uint256 root); mapping(bytes32 => IncrementalTreeData) public trees; function createTree(bytes32 _id, uint256 _depth) external { require(trees[_id].depth == 0, "IncrementalBinaryTreeTest: tree already exists"); trees[_id].init(_depth, 0); emit TreeCreated(_id, _depth); } function createTreeDefaultZeroes(bytes32 _id, uint256 _depth) external { require(trees[_id].depth == 0, "IncrementalBinaryTreeTest: tree already exists"); trees[_id].initWithDefaultZeroes(_depth); emit TreeCreated(_id, _depth); } function insertLeaf(bytes32 _treeId, uint256 _leaf) external { require(trees[_treeId].depth != 0, "IncrementalBinaryTreeTest: tree does not exist"); uint256 root = trees[_treeId].insert(_leaf); require(root == trees[_treeId].root, "root mismatch"); emit LeafInserted(_treeId, _leaf, root); } function updateLeaf( bytes32 _treeId, uint256 _leaf, uint256 _newLeaf, uint256[] calldata _proofSiblings, uint8[] calldata _proofPathIndices ) external { require(trees[_treeId].depth != 0, "IncrementalBinaryTreeTest: tree does not exist"); trees[_treeId].update(_leaf, _newLeaf, _proofSiblings, _proofPathIndices); emit LeafUpdated(_treeId, _newLeaf, trees[_treeId].root); } function removeLeaf( bytes32 _treeId, uint256 _leaf, uint256[] calldata _proofSiblings, uint8[] calldata _proofPathIndices ) external { require(trees[_treeId].depth != 0, "IncrementalBinaryTreeTest: tree does not exist"); trees[_treeId].remove(_leaf, _proofSiblings, _proofPathIndices); emit LeafRemoved(_treeId, _leaf, trees[_treeId].root); } }