Skip to content

Commit

Permalink
missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Nov 18, 2024
1 parent 5c73e59 commit f9dbfaa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package arbo

import (
"math/big"
"testing"
)

func TestBigToFF(t *testing.T) {
baseField := BN254BaseField
iv := new(big.Int).Sub(baseField, big.NewInt(1))
// test with iv < baseField (the result should be iv)
z := BigToFF(baseField, iv)
if z.Cmp(iv) != 0 {
t.Fatalf("BigToFF failed: %v != %v", z, iv)
}
// test with iv > baseField (the result should be iv % baseField)
iv = new(big.Int).Add(baseField, big.NewInt(1))
z = BigToFF(baseField, iv)
if z.Cmp(big.NewInt(1)) != 0 {
t.Fatalf("BigToFF failed: %v != 0", z)
}
// test with iv == baseField (the result should be 0)
iv = baseField
z = BigToFF(baseField, iv)
if z.Cmp(big.NewInt(0)) != 0 {
t.Fatalf("BigToFF failed: %v != 0", z)
}
}
14 changes: 14 additions & 0 deletions hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ func TestHashBlake2b(t *testing.T) {
qt.Equals,
"928b20366943e2afd11ebc0eae2e53a93bf177a4fcf35bcc64d503704e65e202")
}

func TestHashMiMC(t *testing.T) {
// MiMC hash
HashFunction := &HashMiMC_BLS12_377{}
b := []byte("test")
h, err := HashFunction.Hash(b)
if err != nil {
t.Fatal(err)
}
c := qt.New(t)
c.Assert(hex.EncodeToString(h),
qt.Equals,
"f881f34991492d823e02565c778b824bac5eacef6340b70ee90a8966a2e63900")
}

0 comments on commit f9dbfaa

Please sign in to comment.