Skip to content

Commit

Permalink
Add Go tests for empty inputs in Mina account FFI
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Sep 19, 2024
1 parent 6b14da0 commit a979e1f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions operator/mina_account/mina_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,42 @@ func TestMinaStateProofVerifies(t *testing.T) {
t.Errorf("proof did not verify")
}
}

func TestEmptyMinaStateProofDoesNotVerify(t *testing.T) {
fmt.Println(os.Getwd())
proofBuffer := make([]byte, mina_account.MAX_PROOF_SIZE)

pubInputFile, err := os.Open("../../scripts/test_files/mina_account/mina_account.pub")
if err != nil {
t.Errorf("could not open mina account pub inputs file")
}
pubInputBuffer := make([]byte, mina_account.MAX_PUB_INPUT_SIZE)
pubInputLen, err := pubInputFile.Read(pubInputBuffer)
if err != nil {
t.Errorf("could not read bytes from mina account pub inputs hash")
}

if mina_account.VerifyAccountInclusion(([mina_account.MAX_PROOF_SIZE]byte)(proofBuffer), mina_account.MAX_PROOF_SIZE, ([mina_account.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), uint(pubInputLen)) {
t.Errorf("Empty proof should not verify but it did")
}
}

func TestMinaStateProofWithEmptyPubInputDoesNotVerify(t *testing.T) {
fmt.Println(os.Getwd())
proofFile, err := os.Open("../../scripts/test_files/mina_account/mina_account.proof")
if err != nil {
t.Errorf("could not open mina account proof file")
}

proofBuffer := make([]byte, mina_account.MAX_PROOF_SIZE)
proofLen, err := proofFile.Read(proofBuffer)
if err != nil {
t.Errorf("could not read bytes from mina account proof file")
}

pubInputBuffer := make([]byte, mina_account.MAX_PUB_INPUT_SIZE)

if mina_account.VerifyAccountInclusion(([mina_account.MAX_PROOF_SIZE]byte)(proofBuffer), uint(proofLen), ([mina_account.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), mina_account.MAX_PUB_INPUT_SIZE) {
t.Errorf("proof with empty public input should not verify but id did")
}
}

0 comments on commit a979e1f

Please sign in to comment.