|
4 | 4 | "fmt" |
5 | 5 | "testing" |
6 | 6 |
|
| 7 | + "github.com/multiversx/mx-chain-core-go/data" |
7 | 8 | "github.com/multiversx/mx-chain-core-go/data/block" |
8 | 9 | "github.com/multiversx/mx-chain-core-go/marshal/factory" |
9 | 10 | "github.com/stretchr/testify/require" |
@@ -230,6 +231,42 @@ func TestMiniBlockSelectionSession_CreateAndAddMiniBlockFromTransactions(t *test |
230 | 231 | }) |
231 | 232 | } |
232 | 233 |
|
| 234 | +func TestMiniBlocksSelectionSession_RemoveEmptyMiniBlocks(t *testing.T) { |
| 235 | + t.Parallel() |
| 236 | + |
| 237 | + marshaller := &testscommon.MarshallerStub{} |
| 238 | + hasher := &testscommon.HasherStub{} |
| 239 | + |
| 240 | + newMbHeader := func(hash []byte, txCount uint32) *block.MiniBlockHeader { |
| 241 | + return &block.MiniBlockHeader{Hash: hash, SenderShardID: 1, ReceiverShardID: 1, TxCount: txCount, Type: block.TxBlock} |
| 242 | + } |
| 243 | + |
| 244 | + session, _ := NewMiniBlocksSelectionSession(1, marshaller, hasher) |
| 245 | + emptyMb := &block.MiniBlock{TxHashes: nil} |
| 246 | + emptyHash := []byte("emptyHash") |
| 247 | + nonEmptyMb := &block.MiniBlock{TxHashes: [][]byte{[]byte("tx1")}} |
| 248 | + nonEmptyHash := []byte("nonEmptyHash") |
| 249 | + |
| 250 | + session.miniBlocks = block.MiniBlockSlice{emptyMb, nonEmptyMb} |
| 251 | + session.miniBlockHeaderHandlers = []data.MiniBlockHeaderHandler{newMbHeader(emptyHash, 0), newMbHeader(nonEmptyHash, 1)} |
| 252 | + session.miniBlockHashes = [][]byte{emptyHash, nonEmptyHash} |
| 253 | + session.miniBlockHashesUnique[string(emptyHash)] = struct{}{} |
| 254 | + session.miniBlockHashesUnique[string(nonEmptyHash)] = struct{}{} |
| 255 | + |
| 256 | + session.RemoveEmptyMiniBlocks() |
| 257 | + |
| 258 | + require.Len(t, session.GetMiniBlocks(), 1) |
| 259 | + require.Len(t, session.GetMiniBlockHeaderHandlers(), 1) |
| 260 | + require.Len(t, session.GetMiniBlockHashes(), 1) |
| 261 | + require.Equal(t, nonEmptyMb, session.GetMiniBlocks()[0]) |
| 262 | + require.Equal(t, nonEmptyHash, session.GetMiniBlockHashes()[0]) |
| 263 | + |
| 264 | + _, exists := session.miniBlockHashesUnique[string(emptyHash)] |
| 265 | + require.False(t, exists) |
| 266 | + _, exists = session.miniBlockHashesUnique[string(nonEmptyHash)] |
| 267 | + require.True(t, exists) |
| 268 | +} |
| 269 | + |
233 | 270 | func TestMiniBlocksSelectionSession_AddReferencedMetaBlock(t *testing.T) { |
234 | 271 | t.Parallel() |
235 | 272 |
|
|
0 commit comments