github.com/iotexproject/iotex-core@v1.14.1-rc1/blockindex/index_test.go (about) 1 package blockindex 2 3 import ( 4 "encoding/hex" 5 "math/big" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestActionIndex(t *testing.T) { 12 require := require.New(t) 13 14 ad := []*actionIndex{ 15 {1048000}, 16 {1048001}, 17 } 18 19 for i := range ad { 20 s := ad[i].Serialize() 21 bd2 := &actionIndex{} 22 require.NoError(bd2.Deserialize(s)) 23 require.Equal(ad[i], bd2) 24 } 25 } 26 27 func TestBlockIndex(t *testing.T) { 28 require := require.New(t) 29 30 h, _ := hex.DecodeString("d1ff0e7fe2a54600a171d3bcc9e222c656d584b3a0e7b33373e634de3f8cd010") 31 bd := []*blockIndex{ 32 { 33 h, 1048000, big.NewInt(1048000), 34 }, 35 { 36 nil, 1048000, big.NewInt(1048000), 37 }, 38 { 39 h, 1048000, big.NewInt(0), 40 }, 41 } 42 43 for i := range bd { 44 s := bd[i].Serialize() 45 bd2 := &blockIndex{} 46 require.NoError(bd2.Deserialize(s)) 47 require.Equal(bd[i], bd2) 48 } 49 }