-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(chain): refactor and test chain economics extraction (#298)
Co-authored-by: frrist <[email protected]>
- Loading branch information
Showing
5 changed files
with
122 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package chain | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/filecoin-project/sentinel-visor/testutil" | ||
) | ||
|
||
type MockedChainEconomicsLens struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockedChainEconomicsLens) StateVMCirculatingSupplyInternal(ctx context.Context, key types.TipSetKey) (api.CirculatingSupply, error) { | ||
args := m.Called(ctx, key) | ||
return args.Get(0).(api.CirculatingSupply), args.Error(1) | ||
} | ||
|
||
func TestEconomicsModelExtraction(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
expectedTs := testutil.FakeTipset(t) | ||
expectedCircSupply := api.CirculatingSupply{ | ||
FilVested: abi.NewTokenAmount(1), | ||
FilMined: abi.NewTokenAmount(2), | ||
FilBurnt: abi.NewTokenAmount(3), | ||
FilLocked: abi.NewTokenAmount(4), | ||
FilCirculating: abi.NewTokenAmount(5), | ||
} | ||
|
||
mockedLens := new(MockedChainEconomicsLens) | ||
mockedLens.On("StateVMCirculatingSupplyInternal", ctx, expectedTs.Key()).Return(expectedCircSupply, nil) | ||
|
||
em, err := ExtractChainEconomicsModel(ctx, mockedLens, expectedTs) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, expectedTs.ParentState().String(), em.ParentStateRoot) | ||
assert.EqualValues(t, expectedCircSupply.FilBurnt.String(), em.BurntFil) | ||
assert.EqualValues(t, expectedCircSupply.FilMined.String(), em.MinedFil) | ||
assert.EqualValues(t, expectedCircSupply.FilVested.String(), em.VestedFil) | ||
assert.EqualValues(t, expectedCircSupply.FilLocked.String(), em.LockedFil) | ||
assert.EqualValues(t, expectedCircSupply.FilCirculating.String(), em.CirculatingFil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package testutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/crypto" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
tutils "github.com/filecoin-project/specs-actors/support/testing" | ||
"github.com/ipfs/go-cid" | ||
) | ||
|
||
func FakeTipset(t testing.TB) *types.TipSet { | ||
bh := FakeBlockHeader(t, 1, RandomCid()) | ||
ts, err := types.NewTipSet([]*types.BlockHeader{bh}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return ts | ||
} | ||
|
||
func FakeBlockHeader(t testing.TB, height int64, stateRoot cid.Cid) *types.BlockHeader { | ||
return &types.BlockHeader{ | ||
Miner: tutils.NewIDAddr(t, 123), | ||
Height: abi.ChainEpoch(height), | ||
ParentStateRoot: stateRoot, | ||
Messages: RandomCid(), | ||
ParentMessageReceipts: RandomCid(), | ||
BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS}, | ||
BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS}, | ||
Timestamp: 0, | ||
} | ||
} |