mirror of
https://github.com/vocdoni/arbo.git
synced 2026-01-07 21:14:02 -05:00
missing tests
This commit is contained in:
28
ff_test.go
Normal file
28
ff_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
14
hash_test.go
14
hash_test.go
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user