Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into merge-rc-1-7-into-feat-sovereign-25-mar…
Browse files Browse the repository at this point in the history
…ch-2024
  • Loading branch information
mariusmihaic committed Mar 25, 2024
2 parents 97ee507 + b07a6b9 commit 24fb7f0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
14 changes: 13 additions & 1 deletion data/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var _ = data.HeaderHandler(&Header{})
var _ = data.ShardHeaderHandler(&Header{})

// MiniBlockSlice should be used when referring to subset of mini blocks that is not
// necessarily representing a full block body
//
// necessarily representing a full block body
type MiniBlockSlice []*MiniBlock

// MiniblockAndHash holds the info related to a miniblock and its hash
Expand Down Expand Up @@ -274,6 +275,17 @@ func (h *Header) ShallowClone() data.HeaderHandler {
return &headerCopy
}

// SetBlockBodyTypeInt32 sets the blockBodyType in the header
func (h *Header) SetBlockBodyTypeInt32(blockBodyType int32) error {
if h == nil {
return data.ErrNilPointerReceiver
}

h.BlockBodyType = Type(blockBodyType)

return nil
}

// IsInterfaceNil returns true if there is no value under the interface
func (h *Header) IsInterfaceNil() bool {
return h == nil
Expand Down
9 changes: 9 additions & 0 deletions data/block/blockV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,15 @@ func (hv2 *HeaderV2) ShallowClone() data.HeaderHandler {
return &headerCopy
}

// SetBlockBodyTypeInt32 sets the blockBodyType in the header
func (hv2 *HeaderV2) SetBlockBodyTypeInt32(blockBodyType int32) error {
if hv2 == nil {
return data.ErrNilPointerReceiver
}

return hv2.Header.SetBlockBodyTypeInt32(blockBodyType)
}

// IsInterfaceNil returns true if there is no value under the interface
func (hv2 *HeaderV2) IsInterfaceNil() bool {
return hv2 == nil
Expand Down
26 changes: 26 additions & 0 deletions data/block/blockV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,29 @@ func TestHeaderV2_HasScheduledMiniBlocks(t *testing.T) {

require.False(t, shardBlock.HasScheduledMiniBlocks())
}

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

t.Run("nil header should error", func(t *testing.T) {
t.Parallel()

var header *block.HeaderV2
err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock))
require.Equal(t, data.ErrNilPointerReceiver, err)
})
t.Run("should work", func(t *testing.T) {
t.Parallel()

header := &block.HeaderV2{
Header: &block.Header{},
}
err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock))
require.Nil(t, err)
require.Equal(t, int32(block.ReceiptBlock), header.GetBlockBodyTypeInt32())

err = header.SetBlockBodyTypeInt32(int32(block.TxBlock))
require.Nil(t, err)
require.Equal(t, int32(block.TxBlock), header.GetBlockBodyTypeInt32())
})
}
24 changes: 24 additions & 0 deletions data/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,27 @@ func TestMiniBlockHeader_GetMiniBlockHeaderReservedShouldErrWhenReservedFieldIsN
assert.Nil(t, mbhr)
assert.Equal(t, data.ErrNilReservedField, err)
}

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

t.Run("nil header should error", func(t *testing.T) {
t.Parallel()

var header *block.Header
err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock))
require.Equal(t, data.ErrNilPointerReceiver, err)
})
t.Run("should work", func(t *testing.T) {
t.Parallel()

header := &block.Header{}
err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock))
require.Nil(t, err)
require.Equal(t, block.ReceiptBlock, header.BlockBodyType)

err = header.SetBlockBodyTypeInt32(int32(block.TxBlock))
require.Nil(t, err)
require.Equal(t, block.TxBlock, header.BlockBodyType)
})
}
1 change: 1 addition & 0 deletions data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type ShardHeaderHandler interface {
GetBlockBodyTypeInt32() int32
SetMetaBlockHashes(hashes [][]byte) error
MapMiniBlockHashesToShards() map[string]uint32
SetBlockBodyTypeInt32(blockBodyType int32) error
}

// MetaHeaderHandler defines getters and setters for the meta block header
Expand Down

0 comments on commit 24fb7f0

Please sign in to comment.