diff --git a/ff_test.go b/ff_test.go new file mode 100644 index 0000000..9b0b05e --- /dev/null +++ b/ff_test.go @@ -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) + } +} diff --git a/hash_test.go b/hash_test.go index da0d629..43aec20 100644 --- a/hash_test.go +++ b/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") +}