github.com/ethersphere/bee/v2@v2.2.0/pkg/postage/testing/chainstate.go (about)

     1  // Copyright 2020 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 testing
     6  
     7  import (
     8  	"math/rand"
     9  	"testing"
    10  
    11  	"github.com/ethersphere/bee/v2/pkg/postage"
    12  )
    13  
    14  // NewChainState will create a new ChainState with random values.
    15  func NewChainState() *postage.ChainState {
    16  	return &postage.ChainState{
    17  		Block:        rand.Uint64(),
    18  		CurrentPrice: NewBigInt(),
    19  		TotalAmount:  NewBigInt(),
    20  	}
    21  }
    22  
    23  // CompareChainState is a test helper that compares two ChainStates and fails
    24  // the test if they are not exactly equal.
    25  // Fails on first difference and returns a descriptive comparison.
    26  func CompareChainState(t *testing.T, want, got *postage.ChainState) {
    27  	t.Helper()
    28  
    29  	if want.Block != got.Block {
    30  		t.Fatalf("block: want %v, got %v", want.Block, got.Block)
    31  	}
    32  	if want.CurrentPrice.Cmp(got.CurrentPrice) != 0 {
    33  		t.Fatalf("price: want %v, got %v", want.CurrentPrice, got.CurrentPrice)
    34  	}
    35  	if want.TotalAmount.Cmp(got.TotalAmount) != 0 {
    36  		t.Fatalf("total: want %v, got %v", want.TotalAmount, got.TotalAmount)
    37  	}
    38  }