Skip to content

Commit

Permalink
revises the test docs and resolves linter bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
staheri14 committed Jun 29, 2023
1 parent d319f06 commit 1bf8b75
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,39 +709,40 @@ func TestIsEmptyProofOverlapAbsenceProof(t *testing.T) {
}
}

func Test_ShortAbsenceProof(t *testing.T) {
// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace can correctly verify short namespace absence proofs
func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) {
// create a Merkle tree with 8 leaves
tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 7, 8, 9)
qNS := []byte{5} // does not belong to the tree
root, err := tree.Root()
assert.NoError(t, err)

// N_0_8 Tree Root
// / \
// / \
// N_0_4 N_4_8 Non-Leaf Nodes
// / \ / \
// / \ / \
// N_0_2 N_2_4 N_4_6 N_6_8 Non-Leaf Nodes
// / \ / \ / \ / \
// N_0_1 N_1_2 N_2_3 N_3_4 N_4_5 N_5_6 N_6_7 N_7_8 Leaf Hashes
// 1 2 3 4 6 7 8 9 Leaf namespaces
// 0 1 2 3 4 5 6 7 Leaf indexes
// Node_0_8 Tree Root
// / \
// / \
// Node_0_4 Node_4_8 Non-Leaf Node
// / \ / \
// / \ / \
// Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node
// / \ / \ / \ / \
// Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash
// 1 2 3 4 6 7 8 9 Leaf namespace
// 0 1 2 3 4 5 6 7 Leaf index

// nodes needed for the full absence proof of qNS
N_4_5 := tree.leafHashes[4]
N_5_6 := tree.leafHashes[5]
N_6_8, err := tree.computeRoot(6, 8)
Node_4_5 := tree.leafHashes[4]

Check warning on line 733 in proof_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: don't use underscores in Go names; var Node_4_5 should be Node4_5 (revive)
Node_5_6 := tree.leafHashes[5]

Check warning on line 734 in proof_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: don't use underscores in Go names; var Node_5_6 should be Node5_6 (revive)
Node_6_8, err := tree.computeRoot(6, 8)

Check warning on line 735 in proof_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: don't use underscores in Go names; var Node_6_8 should be Node6_8 (revive)
assert.NoError(t, err)
N_0_4, err := tree.computeRoot(0, 4)
Node_0_4, err := tree.computeRoot(0, 4)

Check warning on line 737 in proof_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: don't use underscores in Go names; var Node_0_4 should be Node0_4 (revive)
assert.NoError(t, err)

// nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of N_4_5
N_4_6, err := tree.computeRoot(4, 6)
// nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node_4_5
Node_4_6, err := tree.computeRoot(4, 6)

Check warning on line 741 in proof_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: don't use underscores in Go names; var Node_4_6 should be Node4_6 (revive)
assert.NoError(t, err)

// nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of N_4_5
N_4_8, err := tree.computeRoot(4, 8)
// nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node_4_5
Node_4_8, err := tree.computeRoot(4, 8)

Check warning on line 745 in proof_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: don't use underscores in Go names; var Node_4_8 should be Node4_8 (revive)
assert.NoError(t, err)

tests := []struct {
Expand All @@ -755,25 +756,25 @@ func Test_ShortAbsenceProof(t *testing.T) {
{
name: "valid full absence proof",
qNID: qNS,
leafHash: N_4_5,
nodes: [][]byte{N_0_4, N_5_6, N_6_8},
start: 4, // N_4_5 is at index position 4 (from left to right) at its respective level
leafHash: Node_4_5,
nodes: [][]byte{Node_0_4, Node_5_6, Node_6_8},
start: 4, // Node_4_5 is at index position 4 (from left to right) at its respective level
end: 5,
},
{
name: "valid short absence proof: one level higher",
qNID: qNS,
leafHash: N_4_6,
nodes: [][]byte{N_0_4, N_6_8},
start: 2, // N_4_6 is at index position 2 (from left to right) at its respective level
leafHash: Node_4_6,
nodes: [][]byte{Node_0_4, Node_6_8},
start: 2, // Node_4_6 is at index position 2 (from left to right) at its respective level
end: 3,
},
{
name: "valid short absence proof: two levels higher",
qNID: qNS,
leafHash: N_4_8,
nodes: [][]byte{N_0_4},
start: 1, // N_4_8 is at index position 1 (from left to right) at its respective level
leafHash: Node_4_8,
nodes: [][]byte{Node_0_4},
start: 1, // Node_4_8 is at index position 1 (from left to right) at its respective level
end: 2,
},
}
Expand Down

0 comments on commit 1bf8b75

Please sign in to comment.