github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/miner/expiration_queue_internal_test.go (about) 1 package miner 2 3 import ( 4 "testing" 5 6 "github.com/filecoin-project/go-state-types/abi" 7 "github.com/filecoin-project/go-state-types/big" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestExpirations(t *testing.T) { 13 quant := QuantSpec{unit: 10, offset: 3} 14 sectors := []*SectorOnChainInfo{ 15 testSector(7, 1, 0, 0, 0), 16 testSector(8, 2, 0, 0, 0), 17 testSector(14, 3, 0, 0, 0), 18 testSector(13, 4, 0, 0, 0), 19 } 20 result := groupNewSectorsByDeclaredExpiration(2048, sectors, quant) 21 expected := []*sectorEpochSet{{ 22 epoch: 13, 23 sectors: []uint64{1, 2, 4}, 24 power: NewPowerPair(big.NewIntUnsigned(2048*3), big.NewIntUnsigned(2048*3)), 25 pledge: big.Zero(), 26 }, { 27 epoch: 23, 28 sectors: []uint64{3}, 29 power: NewPowerPair(big.NewIntUnsigned(2048), big.NewIntUnsigned(2048)), 30 pledge: big.Zero(), 31 }} 32 require.Equal(t, len(expected), len(result)) 33 for i, ex := range expected { 34 assertSectorSet(t, ex, &result[i]) 35 } 36 } 37 38 func TestExpirationsEmpty(t *testing.T) { 39 sectors := []*SectorOnChainInfo{} 40 result := groupNewSectorsByDeclaredExpiration(2048, sectors, NoQuantization) 41 expected := []sectorEpochSet{} 42 require.Equal(t, expected, result) 43 } 44 45 func assertSectorSet(t *testing.T, expected, actual *sectorEpochSet) { 46 assert.Equal(t, expected.epoch, actual.epoch) 47 assert.Equal(t, expected.sectors, actual.sectors) 48 assert.True(t, expected.power.Equals(actual.power), "expected %v, actual %v", expected.power, actual.power) 49 assert.True(t, expected.pledge.Equals(actual.pledge), "expected %v, actual %v", expected.pledge, actual.pledge) 50 } 51 52 func testSector(expiration, number, weight, vweight, pledge int64) *SectorOnChainInfo { 53 return &SectorOnChainInfo{ 54 Expiration: abi.ChainEpoch(expiration), 55 SectorNumber: abi.SectorNumber(number), 56 DealWeight: big.NewInt(weight), 57 VerifiedDealWeight: big.NewInt(vweight), 58 InitialPledge: abi.NewTokenAmount(pledge), 59 } 60 }