Skip to content

Commit

Permalink
data: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdoAdoAdo committed Mar 16, 2022
1 parent 8c03fe3 commit b5ee1f2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions data/block/blockV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,3 +1194,26 @@ func TestHeaderV2_SetAdditionalDataShouldWork(t *testing.T) {
require.Equal(t, gasRefunded, shardBlock.GetScheduledGasRefunded())
require.Equal(t, gasProvided, shardBlock.GetScheduledGasProvided())
}

func TestHeaderV2_HasScheduledMiniBlocks(t *testing.T) {
t.Parallel()

mbh := &block.MiniBlockHeader{}
_ = mbh.SetProcessingType(int32(block.Scheduled))

shardBlock := &block.HeaderV2{
Header: &block.Header{
MiniBlockHeaders: []block.MiniBlockHeader{*mbh},
},
}
require.True(t, shardBlock.HasScheduledMiniBlocks())

_ = mbh.SetProcessingType(int32(block.Normal))
shardBlock = &block.HeaderV2{
Header: &block.Header{
MiniBlockHeaders: []block.MiniBlockHeader{*mbh},
},
}

require.False(t, shardBlock.HasScheduledMiniBlocks())
}
17 changes: 17 additions & 0 deletions data/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,20 @@ func TestHeader_GetAdditionalData(t *testing.T) {
additionalData := h.GetAdditionalData()
assert.Nil(t, additionalData)
}

func TestHeader_HasScheduledMiniBlocks(t *testing.T) {
t.Parallel()

h := &block.Header{}
require.False(t, h.HasScheduledMiniBlocks())

mbHeader := &block.MiniBlockHeader{}
_ = mbHeader.SetProcessingType(int32(block.Normal))
h.MiniBlockHeaders = []block.MiniBlockHeader{*mbHeader}
require.False(t, h.HasScheduledMiniBlocks())

// not suppoerted for v1 header, so it should return false
_ = mbHeader.SetProcessingType(int32(block.Scheduled))
h.MiniBlockHeaders = []block.MiniBlockHeader{*mbHeader}
require.False(t, h.HasScheduledMiniBlocks())
}
17 changes: 17 additions & 0 deletions data/block/metaBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,20 @@ func TestMetaBlock_SetAdditionalDataShouldDoNothing(t *testing.T) {
err := metaBlock.SetAdditionalData(&headerVersionData.AdditionalData{})
require.Nil(t, err)
}

func TestMetaBlock_HasScheduledMiniBlocks(t *testing.T) {
t.Parallel()

metaBlock := &block.MetaBlock{}
require.False(t, metaBlock.HasScheduledMiniBlocks())

mbHeader := &block.MiniBlockHeader{}
_ = mbHeader.SetProcessingType(int32(block.Normal))
metaBlock.MiniBlockHeaders = []block.MiniBlockHeader{*mbHeader}
require.False(t, metaBlock.HasScheduledMiniBlocks())

_ = mbHeader.SetProcessingType(int32(block.Scheduled))
metaBlock.MiniBlockHeaders = []block.MiniBlockHeader{*mbHeader}

require.True(t, metaBlock.HasScheduledMiniBlocks())
}

0 comments on commit b5ee1f2

Please sign in to comment.