github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/reward/testing.go (about)

     1  package reward
     2  
     3  import (
     4  	"github.com/filecoin-project/go-state-types/abi"
     5  	"github.com/filecoin-project/go-state-types/big"
     6  	"github.com/filecoin-project/specs-actors/v4/actors/builtin"
     7  	"github.com/filecoin-project/specs-actors/v4/actors/util/adt"
     8  )
     9  
    10  type StateSummary struct{}
    11  
    12  var FIL = big.NewInt(1e18)
    13  var StorageMiningAllocationCheck = big.Mul(big.NewInt(1_100_000_000), FIL)
    14  
    15  func CheckStateInvariants(st *State, store adt.Store, priorEpoch abi.ChainEpoch, balance abi.TokenAmount) (*StateSummary, *builtin.MessageAccumulator) {
    16  	acc := &builtin.MessageAccumulator{}
    17  
    18  	// Can't assert equality because anyone can send funds to reward actor (and already have on mainnet)
    19  	acc.Require(big.Add(st.TotalStoragePowerReward, balance).GreaterThanEqual(StorageMiningAllocationCheck), "reward given %v + reward left %v < storage mining allocation %v", st.TotalStoragePowerReward, balance, StorageMiningAllocationCheck)
    20  
    21  	acc.Require(st.Epoch == priorEpoch+1, "reward state epoch %d does not match priorEpoch+1 %d", st.Epoch, priorEpoch+1)
    22  	acc.Require(st.EffectiveNetworkTime <= st.Epoch, "effective network time greater than state epoch")
    23  
    24  	acc.Require(st.CumsumRealized.LessThanEqual(st.CumsumBaseline), "cumsum realized > cumsum baseline")
    25  	acc.Require(st.CumsumRealized.GreaterThanEqual(big.Zero()), "cumsum realized < 0")
    26  	acc.Require(st.EffectiveBaselinePower.LessThanEqual(st.ThisEpochBaselinePower), "effective baseline power > baseline power")
    27  
    28  	return &StateSummary{}, acc
    29  }