Skip to content

Commit

Permalink
Fix test name
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Sep 18, 2023
1 parent 742d51e commit 8707c24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/lambdaworks/lambdaworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ func (f Felt) ToBigInt() *big.Int {
}

func FeltFromBigInt(n *big.Int) Felt {
// Perform modulo prime
prime, _ := new(big.Int).SetString(CAIRO_PRIME_HEX, 0)
if n.Cmp(prime) != -1 {
n = new(big.Int).Mod(n, prime)
}
bytes := n.Bytes()
var bytes32 [32]byte
copy(bytes32[:], bytes)
Expand Down
8 changes: 8 additions & 0 deletions pkg/lambdaworks/lambdaworks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ func TestFromBigInt(t *testing.T) {
}
}

func TestFromBigIntPrime(t *testing.T) {
expectedFelt := lambdaworks.FeltFromDecString("0")
bigInt, _ := new(big.Int).SetString(lambdaworks.CAIRO_PRIME_HEX, 0)
if !reflect.DeepEqual(lambdaworks.FeltFromBigInt(bigInt), expectedFelt) {
t.Errorf("TestToBigInt failed. Expected: PRIME, Got: %v", lambdaworks.FeltFromBigInt(bigInt))
}
}

func TestToSignedNegative(t *testing.T) {
felt := lambdaworks.FeltFromDecString("-1")
bigInt := felt.ToSigned()
Expand Down

0 comments on commit 8707c24

Please sign in to comment.