Skip to content

Commit

Permalink
bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Mar 6, 2023
1 parent 88a5873 commit ae9c133
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions outport/process/transactionsfee/transactionsFeeProcessor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package transactionsfee

import (
"bytes"
"math/big"

"github.com/multiversx/mx-chain-core-go/core"
Expand Down Expand Up @@ -184,6 +185,11 @@ func (tep *transactionsFeeProcessor) prepareScrsNoTx(transactionsAndScrs *transa
continue
}

isForInitialTxSender := bytes.Equal(scr.RcvAddr, txFromStorage.SndAddr)
if !isForInitialTxSender {
continue
}

gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txFromStorage, scr.Value)

scrHandler.SetGasUsed(gasUsed)
Expand Down
47 changes: 47 additions & 0 deletions outport/process/transactionsfee/transactionsFeeProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestPutFeeAndGasUsedScrNoTx(t *testing.T) {
initialTx := &transaction.Transaction{
GasLimit: 30000000,
GasPrice: 1000000000,
SndAddr: []byte("erd1k7j6ewjsla4zsgv8v6f6fe3dvrkgv3d0d9jerczw45hzedhyed8sh2u34u"),
}
txBytes, _ := arg.Marshaller.Marshal(initialTx)

Expand Down Expand Up @@ -388,3 +389,49 @@ func TestPutFeeAndGasUsedScrWithRefundNoTx(t *testing.T) {
require.Equal(t, uint64(0), scr.GetGasUsed())
require.True(t, wasCalled)
}

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

txHash := []byte("tx")
scrWithRefund := []byte("scrWithRefund")

refundValueBig, _ := big.NewInt(0).SetString("226498540000000", 10)

scr := outportcore.NewTransactionHandlerWithGasAndFee(&smartContractResult.SmartContractResult{
Nonce: 3,
SndAddr: []byte("erd1qqqqqqqqqqqqqpgq3dswlnnlkfd3gqrcv3dhzgnvh8ryf27g5rfsecnn2s"),
RcvAddr: []byte("erd1k7j6ewjsla4zsgv8v6f6fe3dvrkgv3d0d9jerczw45hzedhyed8sh2u34u"),
PrevTxHash: []byte("f639cb7a0231191e04ec19dcb1359bd93a03fe8dc4a28a80d00835c5d1c988f8"),
OriginalTxHash: txHash,
Value: refundValueBig,
Data: []byte(""),
}, 0, big.NewInt(0))

pool := &outportcore.Pool{
Scrs: map[string]coreData.TransactionHandlerWithGasUsedAndFee{
"wrong": outportcore.NewTransactionHandlerWithGasAndFee(&transaction.Transaction{}, 0, big.NewInt(0)),
string(scrWithRefund): scr,
},
}

arg := prepareMockArg()

initialTx := &transaction.Transaction{
GasLimit: 30_000_000,
GasPrice: 1000000000,
SndAddr: []byte("erd1dglncxk6sl9a3xumj78n6z2xux4ghp5c92cstv5zsn56tjgtdwpsk46qrs"),
}
txBytes, _ := arg.Marshaller.Marshal(initialTx)

_ = arg.TransactionsStorer.Put(txHash, txBytes)

txsFeeProc, err := NewTransactionsFeeProcessor(arg)
require.NotNil(t, txsFeeProc)
require.Nil(t, err)

err = txsFeeProc.PutFeeAndGasUsed(pool)
require.Nil(t, err)
require.Equal(t, big.NewInt(0), scr.GetFee())
require.Equal(t, uint64(0), scr.GetGasUsed())
}

0 comments on commit ae9c133

Please sign in to comment.