missing tests

This commit is contained in:
Lucas Menéndez
2024-11-18 10:16:06 +01:00
parent 5c73e593c7
commit f9dbfaa82c
2 changed files with 42 additions and 0 deletions

28
ff_test.go Normal file
View File

@@ -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)
}
}

View File

@@ -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")
}