Skip to content

Commit 5b07b6f

Browse files
committed
Add tests
1 parent b5251c8 commit 5b07b6f

File tree

1 file changed

+62
-12
lines changed

1 file changed

+62
-12
lines changed

econ/terminate_test.go

+62-12
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func TestEstimateTerminationPenalty2(t *testing.T) {
331331
}
332332
}
333333

334-
var BLOCK_HEIGHT = abi.ChainEpoch(4198539)
334+
var BLOCK_HEIGHT = big.NewInt(4198539)
335335

336336
type baseFiTest struct {
337337
*BaseFi
@@ -420,7 +420,7 @@ func TestMinerFi(t *testing.T) {
420420
}
421421
defer closer()
422422

423-
ts, err := lapi.ChainGetTipSetByHeight(context.Background(), BLOCK_HEIGHT, types.EmptyTSK)
423+
ts, err := lapi.ChainGetTipSetByHeight(context.Background(), abi.ChainEpoch(BLOCK_HEIGHT.Int64()), types.EmptyTSK)
424424
if err != nil {
425425
t.Fatal(err)
426426
}
@@ -485,10 +485,11 @@ type agentFiTest struct {
485485
var agentTests = []struct {
486486
name string
487487
agent string
488+
block *big.Int
488489
want agentFiTest
489490
}{
490491
// agent 59
491-
{"agent many miners", "0x64Ea1aD49A78B6A6878c4975566b8953b1Ef1e79", agentFiTest{
492+
{"agent many miners", "0x64Ea1aD49A78B6A6878c4975566b8953b1Ef1e79", BLOCK_HEIGHT, agentFiTest{
492493
AgentFi: &AgentFi{
493494
BaseFi: BaseFi{
494495
Balance: bigFromStr("2090733730144435384596917"),
@@ -514,7 +515,7 @@ var agentTests = []struct {
514515
leverageRatio: 0.5743316423053819,
515516
}},
516517
// agent 27
517-
{"agent no miners", "0xDBa96B0FDbc87C7eEb641Ee37EAFC55B355079E4", agentFiTest{
518+
{"agent no miners", "0xDBa96B0FDbc87C7eEb641Ee37EAFC55B355079E4", BLOCK_HEIGHT, agentFiTest{
518519
AgentFi: EmptyAgentFi(),
519520
balance: big.NewInt(0),
520521
maxBorrowAndSeal: big.NewInt(0),
@@ -526,7 +527,7 @@ var agentTests = []struct {
526527
leverageRatio: 0,
527528
}},
528529
// agent 2
529-
{"agent single miner", "0xf0F1ceCCF78D411EeD9Ca190ca7F157140cCB2d3", agentFiTest{
530+
{"agent single miner", "0xf0F1ceCCF78D411EeD9Ca190ca7F157140cCB2d3", BLOCK_HEIGHT, agentFiTest{
530531
AgentFi: &AgentFi{
531532
BaseFi: BaseFi{
532533
Balance: bigFromStr("133252309755096579751"),
@@ -552,7 +553,7 @@ var agentTests = []struct {
552553
leverageRatio: 0.016656085317377764,
553554
}},
554555
// agent 91
555-
{"agent miner with fee debt", "0xFF65F5f3D309fEA7aA2d4cB2727E918FAb0aE7F7", agentFiTest{
556+
{"agent miner with fee debt", "0xFF65F5f3D309fEA7aA2d4cB2727E918FAb0aE7F7", BLOCK_HEIGHT, agentFiTest{
556557
AgentFi: &AgentFi{
557558
BaseFi: BaseFi{
558559
Balance: bigFromStr("0"),
@@ -577,6 +578,56 @@ var agentTests = []struct {
577578
marginCall: bigFromStr("0"),
578579
leverageRatio: 0,
579580
}},
581+
{"agent with balance no miners", "0xf0F1ceCCF78D411EeD9Ca190ca7F157140cCB2d3", big.NewInt(4238800), agentFiTest{
582+
AgentFi: &AgentFi{
583+
BaseFi: BaseFi{
584+
Balance: bigFromStr("3454284493328524959"),
585+
AvailableBalance: bigFromStr("3454284493328524959"),
586+
LockedRewards: bigFromStr("0"),
587+
InitialPledge: bigFromStr("0"),
588+
FeeDebt: bigFromStr("0"),
589+
TerminationFee: bigFromStr("0"),
590+
LiveSectors: big.NewInt(0),
591+
FaultySectors: big.NewInt(0),
592+
},
593+
Liability: Liability{
594+
Principal: bigFromStr("0"),
595+
Interest: bigFromStr("0"),
596+
},
597+
},
598+
maxBorrowAndSeal: bigFromStr("10362853479985574877"),
599+
maxBorrowAndWithdraw: bigFromStr("2590713369996393720"),
600+
liquidationValue: bigFromStr("3454284493328524959"),
601+
borrowLimit: bigFromStr("10362853479985574877"),
602+
withdrawLimit: bigFromStr("3454284493328524959"),
603+
marginCall: bigFromStr("0"),
604+
leverageRatio: 0,
605+
}},
606+
{"agent with balance no miners with principal", "0xf0F1ceCCF78D411EeD9Ca190ca7F157140cCB2d3", big.NewInt(4238810), agentFiTest{
607+
AgentFi: &AgentFi{
608+
BaseFi: BaseFi{
609+
Balance: bigFromStr("4454284493328524959"),
610+
AvailableBalance: bigFromStr("4454284493328524959"),
611+
LockedRewards: bigFromStr("0"),
612+
InitialPledge: bigFromStr("0"),
613+
FeeDebt: bigFromStr("0"),
614+
TerminationFee: bigFromStr("0"),
615+
LiveSectors: big.NewInt(0),
616+
FaultySectors: big.NewInt(0),
617+
},
618+
Liability: Liability{
619+
Principal: bigFromStr("1000000000000000000"),
620+
Interest: bigFromStr("0"),
621+
},
622+
},
623+
maxBorrowAndSeal: bigFromStr("10362852195738999537"),
624+
maxBorrowAndWithdraw: bigFromStr("2340712941914201940"),
625+
liquidationValue: bigFromStr("4454284493328524959"),
626+
borrowLimit: bigFromStr("9362851767656807757"),
627+
withdrawLimit: bigFromStr("3120950589218935919"),
628+
marginCall: bigFromStr("1176471091861402094"),
629+
leverageRatio: 0.22450304410954403,
630+
}},
580631
}
581632

582633
func TestEstimateTermationFeeAgent(t *testing.T) {
@@ -591,14 +642,13 @@ func TestEstimateTermationFeeAgent(t *testing.T) {
591642
}
592643
defer closer()
593644

594-
ts, err := lapi.ChainGetTipSetByHeight(context.Background(), BLOCK_HEIGHT, types.EmptyTSK)
595-
if err != nil {
596-
t.Fatal(err)
597-
}
598-
599645
for _, tt := range agentTests {
600646
testname := fmt.Sprintf("%s:%s", tt.name, tt.agent)
601647
t.Run(testname, func(t *testing.T) {
648+
ts, err := lapi.ChainGetTipSetByHeight(context.Background(), abi.ChainEpoch(tt.block.Uint64()), types.EmptyTSK)
649+
if err != nil {
650+
t.Fatal(err)
651+
}
602652

603653
agent := common.HexToAddress(tt.agent)
604654

@@ -632,7 +682,7 @@ func assertAgentFiEqual(t *testing.T, expected *agentFiTest, actual *AgentFi) {
632682
t.Fatalf("Expected principal: %v, actual: %v", expected.Principal, actual.Principal)
633683
}
634684
if expected.Balance.Cmp(actual.Balance) != 0 {
635-
t.Fatalf("Expected balance: %v, actual: %v", expected.balance, actual.Balance)
685+
t.Fatalf("Expected balance: %v, actual: %v", expected.Balance, actual.Balance)
636686
}
637687
if expected.FaultySectors.Cmp(actual.FaultySectors) != 0 {
638688
t.Fatalf("Expected faulty sectors: %v, actual: %v", expected.FaultySectors, actual.FaultySectors)

0 commit comments

Comments
 (0)