mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
style: general code format
This commit is contained in:
@@ -15,7 +15,7 @@ contract IncrementalBinaryTreeTest {
|
||||
mapping(bytes32 => IncrementalTreeData) public trees;
|
||||
|
||||
function createTree(bytes32 _id, uint8 _depth) external {
|
||||
require(trees[_id].depth == 0, "BinaryTreeTest: tree already exists");
|
||||
require(trees[_id].depth == 0, "IncrementalBinaryTreeTest: tree already exists");
|
||||
|
||||
trees[_id].init(_depth, 0);
|
||||
|
||||
@@ -23,7 +23,7 @@ contract IncrementalBinaryTreeTest {
|
||||
}
|
||||
|
||||
function insertLeaf(bytes32 _treeId, uint256 _leaf) external {
|
||||
require(trees[_treeId].depth != 0, "BinaryTreeTest: tree does not exist");
|
||||
require(trees[_treeId].depth != 0, "IncrementalBinaryTreeTest: tree does not exist");
|
||||
|
||||
trees[_treeId].insert(_leaf);
|
||||
|
||||
@@ -37,7 +37,7 @@ contract IncrementalBinaryTreeTest {
|
||||
uint256[] calldata _proofSiblings,
|
||||
uint8[] calldata _proofPathIndices
|
||||
) external {
|
||||
require(trees[_treeId].depth != 0, "BinaryTreeTest: tree does not exist");
|
||||
require(trees[_treeId].depth != 0, "IncrementalBinaryTreeTest: tree does not exist");
|
||||
|
||||
trees[_treeId].update(_leaf, _newLeaf, _proofSiblings, _proofPathIndices);
|
||||
|
||||
@@ -50,7 +50,7 @@ contract IncrementalBinaryTreeTest {
|
||||
uint256[] calldata _proofSiblings,
|
||||
uint8[] calldata _proofPathIndices
|
||||
) external {
|
||||
require(trees[_treeId].depth != 0, "BinaryTreeTest: tree does not exist");
|
||||
require(trees[_treeId].depth != 0, "IncrementalBinaryTreeTest: tree does not exist");
|
||||
|
||||
trees[_treeId].remove(_leaf, _proofSiblings, _proofPathIndices);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ contract IncrementalQuinTreeTest {
|
||||
mapping(bytes32 => IncrementalTreeData) public trees;
|
||||
|
||||
function createTree(bytes32 _id, uint8 _depth) external {
|
||||
require(trees[_id].depth == 0, "QuinTreeTest: tree already exists");
|
||||
require(trees[_id].depth == 0, "IncrementalQuinTreeTest: tree already exists");
|
||||
|
||||
trees[_id].init(_depth, 0);
|
||||
|
||||
@@ -23,7 +23,7 @@ contract IncrementalQuinTreeTest {
|
||||
}
|
||||
|
||||
function insertLeaf(bytes32 _treeId, uint256 _leaf) external {
|
||||
require(trees[_treeId].depth != 0, "QuinTreeTest: tree does not exist");
|
||||
require(trees[_treeId].depth != 0, "IncrementalQuinTreeTest: tree does not exist");
|
||||
|
||||
trees[_treeId].insert(_leaf);
|
||||
|
||||
@@ -37,7 +37,7 @@ contract IncrementalQuinTreeTest {
|
||||
uint256[4][] calldata _proofSiblings,
|
||||
uint8[] calldata _proofPathIndices
|
||||
) external {
|
||||
require(trees[_treeId].depth != 0, "QuinTreeTest: tree does not exist");
|
||||
require(trees[_treeId].depth != 0, "IncrementalQuinTreeTest: tree does not exist");
|
||||
|
||||
trees[_treeId].update(_leaf, _newLeaf, _proofSiblings, _proofPathIndices);
|
||||
|
||||
@@ -50,7 +50,7 @@ contract IncrementalQuinTreeTest {
|
||||
uint256[4][] calldata _proofSiblings,
|
||||
uint8[] calldata _proofPathIndices
|
||||
) external {
|
||||
require(trees[_treeId].depth != 0, "QuinTreeTest: tree does not exist");
|
||||
require(trees[_treeId].depth != 0, "IncrementalQuinTreeTest: tree does not exist");
|
||||
|
||||
trees[_treeId].remove(_leaf, _proofSiblings, _proofPathIndices);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
it("Should not create a tree with an existing id", async () => {
|
||||
const transaction = contract.createTree(treeId, depth)
|
||||
|
||||
await expect(transaction).to.be.revertedWith("BinaryTreeTest: tree already exists")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalBinaryTreeTest: tree already exists")
|
||||
})
|
||||
|
||||
it("Should not insert a leaf if the tree does not exist", async () => {
|
||||
@@ -38,7 +38,7 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
|
||||
const transaction = contract.insertLeaf(treeId, leaf)
|
||||
|
||||
await expect(transaction).to.be.revertedWith("BinaryTreeTest: tree does not exist")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalBinaryTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not insert a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
@@ -88,7 +88,7 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
|
||||
const transaction = contract.updateLeaf(treeId, leaf, leaf, [0, 1], [0, 1])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("BinaryTreeTest: tree does not exist")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalBinaryTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not update a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
@@ -99,13 +99,18 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
await expect(transaction).to.be.revertedWith("IncrementalBinaryTree: leaf must be < SNARK_SCALAR_FIELD")
|
||||
})
|
||||
|
||||
it("Should not update a leaf if wrong current leaf is given", async () => {
|
||||
it("Should not update a leaf if the wrong current leaf is given", async () => {
|
||||
const treeId = ethers.utils.formatBytes32String("tree2")
|
||||
const tree = createTree(depth, 0)
|
||||
for (let i = 0; i < 4; i += 1) tree.insert(BigInt(i + 1))
|
||||
|
||||
for (let i = 0; i < 4; i += 1) {
|
||||
tree.insert(BigInt(i + 1))
|
||||
}
|
||||
|
||||
const leaf = BigInt(1337)
|
||||
|
||||
tree.update(2, leaf)
|
||||
|
||||
const { pathIndices, siblings } = tree.createProof(2)
|
||||
const transaction = contract.updateLeaf(
|
||||
treeId,
|
||||
@@ -121,10 +126,15 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
it("Should update a leaf", async () => {
|
||||
const treeId = ethers.utils.formatBytes32String("tree2")
|
||||
const tree = createTree(depth, 0)
|
||||
for (let i = 0; i < 4; i += 1) tree.insert(BigInt(i + 1))
|
||||
|
||||
for (let i = 0; i < 4; i += 1) {
|
||||
tree.insert(BigInt(i + 1))
|
||||
}
|
||||
|
||||
const leaf = BigInt(1337)
|
||||
|
||||
tree.update(2, leaf)
|
||||
|
||||
const { root, pathIndices, siblings } = tree.createProof(2)
|
||||
const transaction = contract.updateLeaf(
|
||||
treeId,
|
||||
@@ -142,7 +152,7 @@ describe("IncrementalBinaryTreeTest", () => {
|
||||
|
||||
const transaction = contract.removeLeaf(treeId, leaf, [0, 1], [0, 1])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("BinaryTreeTest: tree does not exist")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalBinaryTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not remove a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
|
||||
@@ -30,7 +30,7 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
it("Should not create a tree with an existing id", async () => {
|
||||
const transaction = contract.createTree(treeId, depth)
|
||||
|
||||
await expect(transaction).to.be.revertedWith("QuinTreeTest: tree already exists")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalQuinTreeTest: tree already exists")
|
||||
})
|
||||
|
||||
it("Should not insert a leaf if the tree does not exist", async () => {
|
||||
@@ -38,7 +38,7 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
|
||||
const transaction = contract.insertLeaf(treeId, leaf)
|
||||
|
||||
await expect(transaction).to.be.revertedWith("QuinTreeTest: tree does not exist")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalQuinTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not insert a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
@@ -91,7 +91,7 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
|
||||
const transaction = contract.updateLeaf(treeId, leaf, leaf, [[0, 1, 2, 3]], [0])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("QuinTreeTest: tree does not exist")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalQuinTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not update a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
@@ -102,13 +102,18 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
await expect(transaction).to.be.revertedWith("IncrementalQuinTree: leaf must be < SNARK_SCALAR_FIELD")
|
||||
})
|
||||
|
||||
it("Should not update a leaf if wrong current leaf is given", async () => {
|
||||
it("Should not update a leaf if the wrong current leaf is given", 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))
|
||||
|
||||
for (let i = 0; i < 6; i += 1) {
|
||||
tree.insert(BigInt(i + 1))
|
||||
}
|
||||
|
||||
const leaf = BigInt(1337)
|
||||
|
||||
tree.update(2, leaf)
|
||||
|
||||
const { pathIndices, siblings } = tree.createProof(2)
|
||||
const transaction = contract.updateLeaf(treeId, leaf, leaf, siblings, pathIndices)
|
||||
|
||||
@@ -118,10 +123,15 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
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))
|
||||
|
||||
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, BigInt(3), leaf, siblings, pathIndices)
|
||||
|
||||
@@ -133,7 +143,7 @@ describe("IncrementalQuinTreeTest", () => {
|
||||
|
||||
const transaction = contract.removeLeaf(treeId, leaf, [[0, 1, 2, 3]], [0])
|
||||
|
||||
await expect(transaction).to.be.revertedWith("QuinTreeTest: tree does not exist")
|
||||
await expect(transaction).to.be.revertedWith("IncrementalQuinTreeTest: tree does not exist")
|
||||
})
|
||||
|
||||
it("Should not remove a leaf if its value is > SNARK_SCALAR_FIELD", async () => {
|
||||
|
||||
Reference in New Issue
Block a user