Skip to content

Commit 1cdeb23

Browse files
committed
unit tests and fixes
1 parent 0d25c5c commit 1cdeb23

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

process/elasticproc/block/blockProcessor.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ func (bp *blockProcessor) prepareExecutionResults(obh *outport.OutportBlockWithH
170170
}
171171

172172
func (bp *blockProcessor) prepareExecutionResult(baseExecutionResult coreData.BaseExecutionResultHandler, obh *outport.OutportBlockWithHeader) *data.ExecutionResult {
173-
miniblocksHashes := bp.getEncodedMBSHashes(obh.BlockData.Body, obh.BlockData.IntraShardMiniBlocks)
174-
175173
executionResultsHash := hex.EncodeToString(baseExecutionResult.GetHeaderHash())
176174
executionResult := &data.ExecutionResult{
177175
UUID: converters.GenerateBase64UUID(),
@@ -181,7 +179,6 @@ func (bp *blockProcessor) prepareExecutionResult(baseExecutionResult coreData.Ba
181179
Nonce: baseExecutionResult.GetHeaderNonce(),
182180
Round: baseExecutionResult.GetHeaderRound(),
183181
Epoch: baseExecutionResult.GetHeaderEpoch(),
184-
MiniBlocksHashes: miniblocksHashes,
185182
GasUsed: baseExecutionResult.GetGasUsed(),
186183
}
187184

@@ -191,14 +188,16 @@ func (bp *blockProcessor) prepareExecutionResult(baseExecutionResult coreData.Ba
191188
return executionResult
192189
}
193190

191+
executionResult.MiniBlocksHashes = bp.getEncodedMBSHashes(executionResultData.Body, executionResultData.IntraShardMiniBlocks)
192+
194193
switch t := baseExecutionResult.(type) {
195194
case *nodeBlock.MetaExecutionResult:
196-
executionResult.MiniBlocksDetails = prepareMiniBlockDetails(t.GetMiniBlockHeadersHandlers(), executionResultData.Body, obh.TransactionPool)
195+
executionResult.MiniBlocksDetails = prepareMiniBlockDetails(t.GetMiniBlockHeadersHandlers(), executionResultData.Body, executionResultData.TransactionPool)
197196
executionResult.AccumulatedFees = t.AccumulatedFees.String()
198197
executionResult.DeveloperFees = t.DeveloperFees.String()
199198
executionResult.TxCount = t.ExecutedTxCount
200199
case *nodeBlock.ExecutionResult:
201-
executionResult.MiniBlocksDetails = prepareMiniBlockDetails(t.GetMiniBlockHeadersHandlers(), executionResultData.Body, obh.TransactionPool)
200+
executionResult.MiniBlocksDetails = prepareMiniBlockDetails(t.GetMiniBlockHeadersHandlers(), executionResultData.Body, executionResultData.TransactionPool)
202201
executionResult.AccumulatedFees = t.AccumulatedFees.String()
203202
executionResult.DeveloperFees = t.DeveloperFees.String()
204203
executionResult.TxCount = t.ExecutedTxCount

process/elasticproc/block/blockProcessor_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,93 @@ func TestBlockProcessor_PrepareBlockForDBMiniBlocksDetails(t *testing.T) {
561561
},
562562
}, blockResults.Block)
563563
}
564+
565+
func TestPrepareExecutionResult(t *testing.T) {
566+
t.Parallel()
567+
568+
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})
569+
570+
executionResultHeaderHash := []byte("h1")
571+
mb1Hash := []byte("mb1")
572+
txHash := []byte("tx1")
573+
574+
outportBlockWithHeader := &outport.OutportBlockWithHeader{
575+
Header: &dataBlock.HeaderV3{
576+
ExecutionResults: []*dataBlock.ExecutionResult{
577+
{
578+
BaseExecutionResult: &dataBlock.BaseExecutionResult{
579+
HeaderHash: executionResultHeaderHash,
580+
HeaderNonce: 1,
581+
HeaderRound: 2,
582+
HeaderEpoch: 3,
583+
},
584+
MiniBlockHeaders: []dataBlock.MiniBlockHeader{
585+
{
586+
Hash: mb1Hash,
587+
SenderShardID: 0,
588+
ReceiverShardID: 0,
589+
Type: dataBlock.TxBlock,
590+
TxCount: 1,
591+
},
592+
},
593+
AccumulatedFees: big.NewInt(1),
594+
DeveloperFees: big.NewInt(2),
595+
},
596+
},
597+
},
598+
OutportBlock: &outport.OutportBlock{
599+
BlockData: &outport.BlockData{
600+
Results: map[string]*outport.ExecutionResultData{
601+
hex.EncodeToString(executionResultHeaderHash): {
602+
Body: &dataBlock.Body{
603+
MiniBlocks: []*dataBlock.MiniBlock{
604+
{
605+
SenderShardID: 0,
606+
ReceiverShardID: 0,
607+
Type: dataBlock.TxBlock,
608+
TxHashes: [][]byte{txHash},
609+
},
610+
},
611+
},
612+
TransactionPool: &outport.TransactionPool{
613+
Transactions: map[string]*outport.TxInfo{
614+
hex.EncodeToString(txHash): {
615+
Transaction: &transaction.Transaction{},
616+
ExecutionOrder: 2,
617+
},
618+
},
619+
},
620+
},
621+
},
622+
},
623+
},
624+
}
625+
626+
results, err := bp.prepareExecutionResults(outportBlockWithHeader)
627+
require.Nil(t, err)
628+
require.Len(t, results, 1)
629+
results[0].UUID = ""
630+
require.Equal(t, &data.ExecutionResult{
631+
Hash: "6831",
632+
RootHash: "",
633+
NotarizedInBlockHash: "",
634+
AccumulatedFees: "1",
635+
DeveloperFees: "2",
636+
TxCount: 0,
637+
GasUsed: 0,
638+
Nonce: 1,
639+
Round: 2,
640+
Epoch: 3,
641+
MiniBlocksHashes: []string{"2dae16da63bc04a18cf7609e0a79d7867b11463660dbab048b044b8434bf0a82"},
642+
MiniBlocksDetails: []*data.MiniBlocksDetails{
643+
{
644+
IndexLastProcessedTx: 0,
645+
IndexFirstProcessedTx: 0,
646+
Type: dataBlock.TxBlock.String(),
647+
ProcessingType: dataBlock.Normal.String(),
648+
TxsHashes: []string{hex.EncodeToString(txHash)},
649+
ExecutionOrderTxsIndices: []int{2},
650+
},
651+
},
652+
}, results[0])
653+
}

0 commit comments

Comments
 (0)