Skip to content

Commit

Permalink
prototyp: ToBigInt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Feb 14, 2024
1 parent bab0730 commit 445db3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/prototyp/bigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func ToBigInt(b *big.Int) BigInt {
if b == nil {
return BigInt{}
}
return BigInt(*b)
c := big.NewInt(0).Set(b)
return BigInt(*c)
}

func ToBigIntArray(bs []*big.Int) []BigInt {
Expand Down
8 changes: 8 additions & 0 deletions lib/prototyp/bigint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prototyp

import (
"encoding/json"
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -68,5 +69,12 @@ func TestBigIntInvalidInput(t *testing.T) {
// if invalid, it will parse out the number
b = NewBigIntFromHexString("/0xaBc-$$2Efg")
assert.Equal(t, int64(0xaBc2Ef), b.Int64())
}

func TestBigIntCopy(t *testing.T) {
a := ToBigInt(big.NewInt(1))
b := ToBigInt(a.Int())
a.Sub(big.NewInt(1))
fmt.Println(a.String())
fmt.Println(b.String())
}

0 comments on commit 445db3c

Please sign in to comment.