Skip to content

Commit

Permalink
Merge pull request #4535 from ElrondNetwork/remove-unnecessary-reset-…
Browse files Browse the repository at this point in the history
…calls

Remove unnecessary gasComputation.Reset call
  • Loading branch information
iulianpascalau authored Oct 2, 2022
2 parents 78a0427 + 3789e9d commit 3b2f905
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
1 change: 0 additions & 1 deletion process/block/preprocess/basePreProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ func (bpp *basePreProcess) updateGasConsumedWithGasRefundedAndGasPenalized(
func (bpp *basePreProcess) handleProcessTransactionInit(preProcessorExecutionInfoHandler process.PreProcessorExecutionInfoHandler, txHash []byte) int {
snapshot := bpp.accounts.JournalLen()
preProcessorExecutionInfoHandler.InitProcessedTxsResults(txHash)
bpp.gasHandler.Reset(txHash)
return snapshot
}

Expand Down
47 changes: 47 additions & 0 deletions process/block/preprocess/basePreProcess_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package preprocess

import (
"bytes"
"testing"

"github.com/ElrondNetwork/elrond-go/testscommon"
"github.com/ElrondNetwork/elrond-go/testscommon/state"
"github.com/stretchr/testify/assert"
)

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

txHash := []byte("tx hash")
initProcessedTxsCalled := false

preProcessorExecutionInfoHandler := &testscommon.PreProcessorExecutionInfoHandlerMock{
InitProcessedTxsResultsCalled: func(key []byte) {
if !bytes.Equal(key, txHash) {
return
}

initProcessedTxsCalled = true
},
}

journalLen := 262845
bp := &basePreProcess{
accounts: &state.AccountsStub{
JournalLenCalled: func() int {
return journalLen
},
},
gasTracker: gasTracker{
gasHandler: &testscommon.GasHandlerStub{
ResetCalled: func(hash []byte) {
assert.Fail(t, "should have not called gasComputation.Reset")
},
},
},
}

recoveredJournalLen := bp.handleProcessTransactionInit(preProcessorExecutionInfoHandler, txHash)
assert.Equal(t, journalLen, recoveredJournalLen)
assert.True(t, initProcessedTxsCalled)
}

0 comments on commit 3b2f905

Please sign in to comment.