2019-07-25 22:15:33 +00:00
|
|
|
package gen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-08-30 07:05:21 +00:00
|
|
|
func testGeneration(t testing.TB, n int, msgs int) {
|
2019-07-25 22:15:33 +00:00
|
|
|
g, err := NewGenerator()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-08-30 07:05:21 +00:00
|
|
|
g.msgsPerBlock = msgs
|
|
|
|
|
2019-09-06 20:03:28 +00:00
|
|
|
var height int
|
2019-07-26 12:28:29 +00:00
|
|
|
for i := 0; i < n; i++ {
|
2019-09-03 04:36:07 +00:00
|
|
|
mts, err := g.NextTipSet()
|
2019-07-25 22:15:33 +00:00
|
|
|
if err != nil {
|
2019-07-26 12:19:27 +00:00
|
|
|
t.Fatalf("error at H:%d, %s", i, err)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
2019-09-06 20:03:28 +00:00
|
|
|
|
|
|
|
ts := mts.TipSet.TipSet()
|
|
|
|
if ts.Height() != uint64(height+len(ts.Blocks()[0].Tickets)) {
|
|
|
|
t.Fatal("wrong height", ts.Height(), i, len(ts.Blocks()[0].Tickets), len(ts.Blocks()))
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
2019-09-06 20:03:28 +00:00
|
|
|
height += len(ts.Blocks()[0].Tickets)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
2019-07-26 12:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestChainGeneration(t *testing.T) {
|
2019-08-30 07:05:21 +00:00
|
|
|
testGeneration(t, 10, 20)
|
2019-07-26 12:28:29 +00:00
|
|
|
}
|
2019-07-25 22:15:33 +00:00
|
|
|
|
2019-07-26 12:28:29 +00:00
|
|
|
func BenchmarkChainGeneration(b *testing.B) {
|
2019-08-30 07:05:21 +00:00
|
|
|
b.Run("0-messages", func(b *testing.B) {
|
|
|
|
testGeneration(b, b.N, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
b.Run("10-messages", func(b *testing.B) {
|
|
|
|
testGeneration(b, b.N, 10)
|
|
|
|
})
|
|
|
|
|
|
|
|
b.Run("100-messages", func(b *testing.B) {
|
|
|
|
testGeneration(b, b.N, 100)
|
|
|
|
})
|
|
|
|
|
|
|
|
b.Run("1000-messages", func(b *testing.B) {
|
|
|
|
testGeneration(b, b.N, 1000)
|
|
|
|
})
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|