github.com/aergoio/aergo@v1.3.1/chain/stat_test.go (about) 1 package chain 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 "time" 8 9 "github.com/aergoio/aergo/types" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 var block = types.NewBlock(nil, nil, nil, nil, nil, 0) 14 15 func TestChainStatReorgClone(t *testing.T) { 16 var chk = assert.New(t) 17 18 stats := newStats() 19 i := ReorgStat 20 21 r := stats.clone(i) 22 chk.NotNil(r) 23 b, err := json.Marshal(r) 24 chk.Nil(err) 25 fmt.Println(string(b)) 26 27 stats.updateEvent(i, time.Second*10, block, block, block) 28 stats.updateEvent(i, time.Second*10, block, block, block) 29 stats.updateEvent(i, time.Second*10, block, block, block) 30 r = stats.clone(i) 31 chk.NotNil(r) 32 b, err = json.Marshal(r) 33 chk.Nil(err) 34 fmt.Println(string(b)) 35 } 36 37 func TestChainStatJSON(t *testing.T) { 38 var chk = assert.New(t) 39 40 stats := newStats() 41 i := ReorgStat 42 stats.updateEvent(i, time.Second*10, block, block, block) 43 stats.updateEvent(i, time.Second*10, block, block, block) 44 stats.updateEvent(i, time.Second*10, block, block, block) 45 46 s := stats.JSON() 47 chk.NotZero(len(s)) 48 fmt.Println(s) 49 }