From 445db3c2e54ea4da4670665813a1e57d35319c32 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Wed, 14 Feb 2024 10:17:56 -0500 Subject: [PATCH] prototyp: ToBigInt fix --- lib/prototyp/bigint.go | 3 ++- lib/prototyp/bigint_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/prototyp/bigint.go b/lib/prototyp/bigint.go index 53246f94..c5373d3f 100644 --- a/lib/prototyp/bigint.go +++ b/lib/prototyp/bigint.go @@ -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 { diff --git a/lib/prototyp/bigint_test.go b/lib/prototyp/bigint_test.go index 66a7a446..3861b293 100644 --- a/lib/prototyp/bigint_test.go +++ b/lib/prototyp/bigint_test.go @@ -2,6 +2,7 @@ package prototyp import ( "encoding/json" + "fmt" "math/big" "testing" @@ -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()) }