Skip to content

Commit

Permalink
Merge pull request #288 from multiversx/fix-genesis-flag
Browse files Browse the repository at this point in the history
Fix genesis flags
  • Loading branch information
iulianpascalau authored Mar 7, 2024
2 parents 6a356c6 + 011c96a commit b07a6b9
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 @@ -278,6 +279,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 @@ -401,6 +401,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 @@ -95,6 +95,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 b07a6b9

Please sign in to comment.