[test] fix unit test error

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1270/head
Leo Chen 5 years ago
parent 4e9c939795
commit 9702431033
  1. 6
      core/core_test.go
  2. 16
      internal/configs/sharding/shardingconfig_test.go

@ -11,7 +11,7 @@ import (
func TestIsEpochBlock(t *testing.T) { func TestIsEpochBlock(t *testing.T) {
block1 := types.NewBlock(&types.Header{Number: big.NewInt(10)}, nil, nil) block1 := types.NewBlock(&types.Header{Number: big.NewInt(10)}, nil, nil)
block2 := types.NewBlock(&types.Header{Number: big.NewInt(0)}, nil, nil) block2 := types.NewBlock(&types.Header{Number: big.NewInt(0)}, nil, nil)
block3 := types.NewBlock(&types.Header{Number: big.NewInt(327680)}, nil, nil) block3 := types.NewBlock(&types.Header{Number: big.NewInt(344064)}, nil, nil)
block4 := types.NewBlock(&types.Header{Number: big.NewInt(77)}, nil, nil) block4 := types.NewBlock(&types.Header{Number: big.NewInt(77)}, nil, nil)
block5 := types.NewBlock(&types.Header{Number: big.NewInt(78)}, nil, nil) block5 := types.NewBlock(&types.Header{Number: big.NewInt(78)}, nil, nil)
block6 := types.NewBlock(&types.Header{Number: big.NewInt(188)}, nil, nil) block6 := types.NewBlock(&types.Header{Number: big.NewInt(188)}, nil, nil)
@ -57,11 +57,11 @@ func TestIsEpochBlock(t *testing.T) {
true, true,
}, },
} }
for _, test := range tests { for i, test := range tests {
ShardingSchedule = test.schedule ShardingSchedule = test.schedule
r := IsEpochBlock(test.block) r := IsEpochBlock(test.block)
if r != test.expected { if r != test.expected {
t.Errorf("expected: %v, got: %v\n", test.expected, r) t.Errorf("index: %v, expected: %v, got: %v\n", i, test.expected, r)
} }
} }
} }

@ -51,22 +51,30 @@ func TestCalcEpochNumber(t *testing.T) {
}, },
{ {
327680, 327680,
big.NewInt(1), big.NewInt(0),
}, },
{ {
344064, 344064,
big.NewInt(2), big.NewInt(1),
}, },
{ {
344063, 344063,
big.NewInt(0),
},
{
344065,
big.NewInt(1), big.NewInt(1),
}, },
{
360448,
big.NewInt(2),
},
} }
for _, test := range tests { for i, test := range tests {
ep := MainnetSchedule.CalcEpochNumber(test.block) ep := MainnetSchedule.CalcEpochNumber(test.block)
if ep.Cmp(test.epoch) != 0 { if ep.Cmp(test.epoch) != 0 {
t.Errorf("CalcEpochNumber error: got %v, expect %v\n", ep, test.epoch) t.Errorf("CalcEpochNumber error: index %v, got %v, expect %v\n", i, ep, test.epoch)
} }
} }
} }

Loading…
Cancel
Save