github.com/ethersphere/bee/v2@v2.2.0/pkg/bigint/bigint_test.go (about)

     1  // Copyright 2021 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package bigint_test
     6  
     7  import (
     8  	"encoding/json"
     9  	"math"
    10  	"math/big"
    11  	"reflect"
    12  	"testing"
    13  
    14  	"github.com/ethersphere/bee/v2/pkg/bigint"
    15  )
    16  
    17  func TestMarshaling(t *testing.T) {
    18  	t.Parallel()
    19  
    20  	mar, err := json.Marshal(struct {
    21  		Bg *bigint.BigInt
    22  	}{
    23  		Bg: bigint.Wrap(new(big.Int).Mul(big.NewInt(math.MaxInt64), big.NewInt(math.MaxInt64))),
    24  	})
    25  	if err != nil {
    26  		t.Errorf("Marshaling failed: %v", err)
    27  	}
    28  	if !reflect.DeepEqual(mar, []byte("{\"Bg\":\"85070591730234615847396907784232501249\"}")) {
    29  		t.Error("Wrongly marshaled data")
    30  	}
    31  }