Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2382,9 +2382,9 @@ func (mp *metaProcessor) getCurrentlyAccumulatedFees(metaHdr data.MetaHeaderHand
return big.NewInt(0), big.NewInt(0), nil
}

lastExecResult, err := common.GetLastBaseExecutionResultHandler(metaHdr)
if err != nil {
return nil, nil, err
lastExecResult := mp.blockChain.GetLastExecutionResult()
if check.IfNil(lastExecResult) {
return big.NewInt(0), big.NewInt(0), nil
}

lastMetaExecResult, ok := lastExecResult.(data.BaseMetaExecutionResultHandler)
Expand Down
125 changes: 101 additions & 24 deletions process/block/metablockProposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3839,7 +3839,9 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
blockchainMock := &testscommon.ChainHandlerMock{}
err := blockchainMock.SetGenesisHeader(&block.Header{})
require.Nil(t, err)
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{})
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
})
dataComponents.BlockChain = blockchainMock

arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)
Expand All @@ -3864,7 +3866,9 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
blockchainMock := &testscommon.ChainHandlerMock{}
err := blockchainMock.SetGenesisHeader(&block.Header{})
require.Nil(t, err)
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{})
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
})
dataComponents.BlockChain = blockchainMock

arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)
Expand Down Expand Up @@ -3901,7 +3905,12 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
blockchainMock := &testscommon.ChainHandlerMock{}
err := blockchainMock.SetGenesisHeader(&block.Header{})
require.Nil(t, err)
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{})
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
},
})
dataComponents.BlockChain = blockchainMock

arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)
Expand Down Expand Up @@ -3942,7 +3951,12 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
blockchainMock := &testscommon.ChainHandlerMock{}
err := blockchainMock.SetGenesisHeader(&block.Header{})
require.Nil(t, err)
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{})
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
},
})
dataComponents.BlockChain = blockchainMock

arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)
Expand Down Expand Up @@ -3984,7 +3998,9 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
blockchainMock := &testscommon.ChainHandlerMock{}
err = blockchainMock.SetGenesisHeader(&block.Header{})
require.Nil(t, err)
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{})
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
})
dataComponents.BlockChain = blockchainMock

arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)
Expand Down Expand Up @@ -4013,7 +4029,12 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
blockchainMock := &testscommon.ChainHandlerMock{}
err := blockchainMock.SetGenesisHeader(&block.Header{})
require.Nil(t, err)
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{})
blockchainMock.SetLastExecutionResult(&block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
},
})
dataComponents.BlockChain = blockchainMock

arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)
Expand Down Expand Up @@ -4303,6 +4324,15 @@ func TestMetaProcessor_collectExecutionResults(t *testing.T) {
coreComponents, dataComponents, boostrapComponents, statusComponents := createMockComponentHolders()
arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)

dataComponents.BlockChain = &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
}
},
}

txCoordinatorMock := createTxCoordinatorMock()
arguments.TxCoordinator = &txCoordinatorMock

Expand Down Expand Up @@ -4369,6 +4399,15 @@ func TestMetaProcessor_collectExecutionResultsEpochStartProposal(t *testing.T) {
t.Parallel()

coreComponents, dataComponents, boostrapComponents, statusComponents := createMockComponentHolders()
dataComponents.BlockChain = &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
}
},
}

arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)

arguments.TxCoordinator = &testscommon.TransactionCoordinatorMock{}
Expand Down Expand Up @@ -4556,7 +4595,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4593,7 +4634,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaBlockV3{}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4621,7 +4664,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4650,7 +4695,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaBlockV3{}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4678,7 +4725,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaBlockV3{}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4707,7 +4756,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaBlockV3{}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4736,7 +4787,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaBlockV3{}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4765,7 +4818,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaBlockV3{}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}

Expand Down Expand Up @@ -4794,7 +4849,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaBlockV3{}
},
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
}
arguments := createMockMetaArguments(coreComponents, dataComponents, boostrapComponents, statusComponents)
Expand All @@ -4819,7 +4876,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
coreComponents, dataComponents, boostrapComponents, statusComponents := createMockComponentHolders()
dataComponents.BlockChain = &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.MetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
}
},
GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler {
return &block.MetaBlockV3{}
Expand Down Expand Up @@ -4850,7 +4909,12 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
coreComponents, dataComponents, boostrapComponents, statusComponents := createMockComponentHolders()
dataComponents.BlockChain = &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.MetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
},
}
},
GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler {
return &defaultMetaBlockV3
Expand Down Expand Up @@ -4897,7 +4961,12 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
coreComponents, dataComponents, boostrapComponents, statusComponents := createMockComponentHolders()
dataComponents.BlockChain = &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.MetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
},
}
},
GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler {
return &defaultMetaBlockV3
Expand Down Expand Up @@ -4926,7 +4995,12 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {

dataComponents.BlockChain = &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.MetaExecutionResult{}
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
},
}
},
GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler {
return &block.MetaBlockV3{}
Expand Down Expand Up @@ -4954,7 +5028,10 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
dataComponents.BlockChain = &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.MetaExecutionResult{
ExecutionResult: &block.BaseMetaExecutionResult{},
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
},
}
},
GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler {
Expand Down Expand Up @@ -4983,8 +5060,8 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
Nonce: 1,
LastExecutionResult: &block.MetaExecutionResultInfo{
ExecutionResult: &block.BaseMetaExecutionResult{
DevFeesInEpoch: big.NewInt(1),
AccumulatedFeesInEpoch: big.NewInt(1),
DevFeesInEpoch: big.NewInt(1), // fees not taken from header
AccumulatedFeesInEpoch: big.NewInt(1), // fees not taken from header
},
},
}, []byte("headerHash"), &block.Body{
Expand All @@ -5003,8 +5080,8 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
require.True(t, ok)

require.Equal(t, receiptHash, metaExecutionResult.ReceiptsHash)
require.Equal(t, big.NewInt(1), metaExecutionResult.ExecutionResult.DevFeesInEpoch)
require.Equal(t, big.NewInt(1), metaExecutionResult.ExecutionResult.AccumulatedFeesInEpoch)
require.Equal(t, big.NewInt(10), metaExecutionResult.ExecutionResult.DevFeesInEpoch)
require.Equal(t, big.NewInt(10), metaExecutionResult.ExecutionResult.AccumulatedFeesInEpoch)
require.Equal(t, 0, len(metaExecutionResult.MiniBlockHeaders))
require.Equal(t, uint64(0), metaExecutionResult.GetExecutedTxCount())
})
Expand Down
48 changes: 24 additions & 24 deletions process/block/metablock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4793,45 +4793,45 @@ func Test_getCurrentlyAccumulatedFees(t *testing.T) {
require.Equal(t, big.NewInt(0), currentlyAccumulatedFeesInEpoch)
})

t.Run("should propagate the error in case of nil last execution result", func(t *testing.T) {
t.Run("should return err in case of nil last execution result", func(t *testing.T) {
t.Parallel()

mp, err := processBlock.ConstructPartialMetaBlockProcessorForTest(map[string]interface{}{})
mp, err := processBlock.ConstructPartialMetaBlockProcessorForTest(map[string]interface{}{
"blockChain": &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return nil
},
},
})
require.NoError(t, err)

metaBlock := &block.MetaBlockV3{}
currentlyAccumulatedFeesInEpoch, currentDevFeesInEpoch, err := mp.GetCurrentlyAccumulatedFees(metaBlock)
require.Nil(t, currentlyAccumulatedFeesInEpoch)
require.Nil(t, currentDevFeesInEpoch)
require.Equal(t, common.ErrNilLastExecutionResultHandler, err)
})

t.Run("should propagate the error in case of nil base execution result", func(t *testing.T) {
t.Parallel()

mp, err := processBlock.ConstructPartialMetaBlockProcessorForTest(map[string]interface{}{})
require.NoError(t, err)

metaBlock := &block.MetaBlockV3{
LastExecutionResult: &block.MetaExecutionResultInfo{},
}
currentlyAccumulatedFeesInEpoch, currentDevFeesInEpoch, err := mp.GetCurrentlyAccumulatedFees(metaBlock)
require.Nil(t, currentlyAccumulatedFeesInEpoch)
require.Nil(t, currentDevFeesInEpoch)
require.Equal(t, common.ErrNilBaseExecutionResult, err)
require.Equal(t, big.NewInt(0), currentlyAccumulatedFeesInEpoch)
require.Equal(t, big.NewInt(0), currentDevFeesInEpoch)
require.Nil(t, err)
})

t.Run("should return accumulated fees for v3", func(t *testing.T) {
t.Run("should return accumulated fees for v3 from last executed block", func(t *testing.T) {
t.Parallel()

mp, err := processBlock.ConstructPartialMetaBlockProcessorForTest(map[string]interface{}{})
mp, err := processBlock.ConstructPartialMetaBlockProcessorForTest(map[string]interface{}{
"blockChain": &testscommon.ChainHandlerStub{
GetLastExecutionResultCalled: func() data.BaseExecutionResultHandler {
return &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
}
},
},
})
require.NoError(t, err)

metaBlock := &block.MetaBlockV3{
LastExecutionResult: &block.MetaExecutionResultInfo{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(10),
AccumulatedFeesInEpoch: big.NewInt(12),
DevFeesInEpoch: big.NewInt(12),
},
},
}
Expand Down
Loading