Skip to content

Commit

Permalink
optimize unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
viteshan committed Jul 20, 2022
1 parent 3a8bd37 commit 88b2b12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
21 changes: 4 additions & 17 deletions ledger/chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,6 @@ func TestCheckHash2(t *testing.T) {
func TestChainForkRollBack(t *testing.T) {
c, accountMap, _ := SetUp(t, 3, 100, 2)
curSnapshotBlock := c.GetLatestSnapshotBlock()
fmt.Println(curSnapshotBlock.Height)
TearDown(c)

// height
height := uint64(30)
upgrade.CleanupUpgradeBox()
upgrade.InitUpgradeBox(upgrade.NewEmptyUpgradeBox().AddPoint(1, height))

c, accountMap, _ = SetUp(t, 10, 0, 0)

defer func() {
TearDown(c)
Expand All @@ -343,12 +334,8 @@ func TestChainForkRollBack(t *testing.T) {
}
}()

curSnapshotBlocknew := c.GetLatestSnapshotBlock()

fmt.Println(curSnapshotBlocknew.Height, curSnapshotBlocknew.Height == height-1)
if curSnapshotBlocknew.Height != height-1 {
t.Fatal(fmt.Sprintf("not equal %+v, %d", curSnapshotBlocknew, height-1))
}
upgrade.CleanupUpgradeBox()
upgrade.InitUpgradeBox(upgrade.NewEmptyUpgradeBox().AddPoint(1, curSnapshotBlock.Height+1))

InsertAccountBlocks(nil, c, accountMap, 5)

Expand Down Expand Up @@ -377,8 +364,8 @@ func TestChainForkRollBack(t *testing.T) {
return sc
}
sb := &ledger.SnapshotBlock{
PrevHash: curSnapshotBlocknew.Hash,
Height: curSnapshotBlocknew.Height + 1,
PrevHash: curSnapshotBlock.Hash,
Height: curSnapshotBlock.Height + 1,
Timestamp: &timeNow,
SnapshotContent: createSnaoshotContent(),
}
Expand Down
8 changes: 4 additions & 4 deletions producer/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func TestSnapshot(t *testing.T) {

helper.ErrFailf(t, err, "random account err")

sv := verifier.NewSnapshotVerifier(c, cs)
// sv := verifier.NewSnapshotVerifier(c, cs)
av := verifier.NewVerifier(c).Init(cs, cs.SBPReader(), nil)
p := NewProducer(c, net.Mock(c), coinbase, cs, p1)

p1.Init(net.Mock(c), sv, av, cs.SBPReader().GetPeriodTimeIndex(), cs.SBPReader().GetNodeCount())
p1.Init(net.Mock(c), av, cs.SBPReader())
p.Init()

address := coinbase.Address()
Expand Down Expand Up @@ -94,13 +94,13 @@ func TestProducer_Init(t *testing.T) {
p1, _ := pool.NewPool(c)
coinbase, _ := wallet.RandomAccount()
cs := genConsensus(c, p1, t)
sv := verifier.NewSnapshotVerifier(c, cs)
// sv := verifier.NewSnapshotVerifier(c, cs)
av := verifier.NewVerifier(c).Init(cs, cs.SBPReader(), nil)
p := NewProducer(c, net.Mock(c), coinbase, cs, p1)

c.Start()

p1.Init(net.Mock(c), sv, av, cs.SBPReader().GetPeriodTimeIndex(), cs.SBPReader().GetNodeCount())
p1.Init(net.Mock(c), av, cs.SBPReader())
p.Init()
p1.Start()
p.Start()
Expand Down

0 comments on commit 88b2b12

Please sign in to comment.