mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
quin tree update tests
This commit is contained in:
@@ -103,11 +103,11 @@ library IncrementalQuinTree {
|
||||
uint8[] calldata proofPathIndices
|
||||
) public {
|
||||
require(
|
||||
verify(self, leaf, proofSiblings, proofPathIndices),
|
||||
"IncrementalQuinTree: leaf is not part of the tree"
|
||||
leaf < SNARK_SCALAR_FIELD,
|
||||
"IncrementalQuinTree: leaf must be < SNARK_SCALAR_FIELD"
|
||||
);
|
||||
|
||||
uint256 hash = self.zeroes[0];
|
||||
uint256 hash = leaf;
|
||||
|
||||
for (uint8 i = 0; i < self.depth; i++) {
|
||||
uint256[5] memory nodes;
|
||||
|
||||
@@ -43,7 +43,6 @@ contract IncrementalBinaryTreeTest {
|
||||
trees[_treeId].depth != 0,
|
||||
"BinaryTreeTest: tree does not exist"
|
||||
);
|
||||
|
||||
trees[_treeId].update(_leaf, _proofSiblings, _proofPathIndices);
|
||||
|
||||
emit LeafUpdated(_treeId, _leaf, trees[_treeId].root);
|
||||
|
||||
@@ -87,6 +87,8 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
const treeId = ethers.utils.formatBytes32String("none")
|
||||
|
||||
const transaction = contract.updateLeaf(treeId, leaf, [0, 1], [0, 1])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("BinaryTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not update a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
@@ -103,7 +105,7 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
for (let i = 0; i < 4; i += 1)
|
||||
tree.insert(BigInt(i + 1))
|
||||
|
||||
const leaf = BigInt(22)
|
||||
const leaf = BigInt(1337)
|
||||
tree.update(2, leaf)
|
||||
const { root, pathIndices, siblings } = tree.createProof(2)
|
||||
const transaction = contract.updateLeaf(
|
||||
@@ -114,7 +116,6 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
)
|
||||
|
||||
await expect(transaction).to.emit(contract, "LeafUpdated").withArgs(treeId, leaf, root);
|
||||
|
||||
})
|
||||
|
||||
it("Should not remove a leaf if the tree does not exist", async () => {
|
||||
|
||||
@@ -86,6 +86,36 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
await expect(transaction).to.be.revertedWith("IncrementalQuinTree: tree is full")
|
||||
})
|
||||
|
||||
it("Should not update a leaf if the tree does not exist", async () => {
|
||||
const treeId = ethers.utils.formatBytes32String("none")
|
||||
|
||||
const transaction = contract.updateLeaf(treeId, leaf, [[0, 1, 2, 3]], [0])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("QuinTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not update a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
const leaf = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495618")
|
||||
|
||||
const transaction = contract.updateLeaf(treeId, leaf, [[0, 1, 2, 3]], [0])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("IncrementalQuinTree: leaf must be < SNARK_SCALAR_FIELD")
|
||||
})
|
||||
|
||||
it("Should update a leaf", async () => {
|
||||
const treeId = ethers.utils.formatBytes32String("tree2")
|
||||
const tree = createTree(depth, 0, 5)
|
||||
for (let i = 0; i < 6; i += 1)
|
||||
tree.insert(BigInt(i + 1))
|
||||
|
||||
const leaf = BigInt(1337)
|
||||
tree.update(2, leaf)
|
||||
const { pathIndices, siblings, root } = tree.createProof(2)
|
||||
const transaction = contract.updateLeaf(treeId, leaf, siblings, pathIndices)
|
||||
|
||||
await expect(transaction).to.emit(contract, "LeafUpdated").withArgs(treeId, leaf, root)
|
||||
})
|
||||
|
||||
it("Should not remove a leaf if the tree does not exist", async () => {
|
||||
const treeId = ethers.utils.formatBytes32String("none")
|
||||
|
||||
@@ -114,7 +144,6 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
await contract.insertLeaf(treeId, BigInt(3))
|
||||
|
||||
const { siblings, pathIndices, root } = tree.createProof(0)
|
||||
|
||||
const transaction = contract.removeLeaf(treeId, BigInt(1), siblings, pathIndices)
|
||||
|
||||
await expect(transaction).to.emit(contract, "LeafRemoved").withArgs(treeId, BigInt(1), root)
|
||||
|
||||
Reference in New Issue
Block a user