Skip to content

Commit bd0267e

Browse files
authored
Merge pull request #7169 from multiversx/fix-tx-cost-endpoint-sc-processor-proxy
Fixes tx cost endpoint
2 parents 32b3365 + f424599 commit bd0267e

File tree

2 files changed

+83
-3
lines changed

2 files changed

+83
-3
lines changed

factory/processing/txSimulatorProcessComponents.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/multiversx/mx-chain-go/process/coordinator"
1414
"github.com/multiversx/mx-chain-go/process/factory/shard"
1515
"github.com/multiversx/mx-chain-go/process/smartContract"
16+
"github.com/multiversx/mx-chain-go/process/smartContract/processProxy"
1617
"github.com/multiversx/mx-chain-go/process/smartContract/scrCommon"
1718
"github.com/multiversx/mx-chain-go/process/transaction"
1819
"github.com/multiversx/mx-chain-go/process/transactionEvaluator"
@@ -377,7 +378,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
377378
IsGenesisProcessing: false,
378379
}
379380

380-
scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs)
381+
scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(scProcArgs, pcf.coreData.EpochNotifier())
381382
if err != nil {
382383
return args, nil, nil, nil, err
383384
}
@@ -389,7 +390,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
389390
Marshalizer: pcf.coreData.InternalMarshalizer(),
390391
SignMarshalizer: pcf.coreData.TxMarshalizer(),
391392
ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(),
392-
ScProcessor: scProcessor,
393+
ScProcessor: scProcessorProxy,
393394
TxFeeHandler: txFeeHandler,
394395
TxTypeHandler: txTypeHandler,
395396
EconomicsFee: pcf.coreData.EconomicsData(),
@@ -412,5 +413,5 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
412413
args.TransactionProcessor = txProcessor
413414
args.IntermediateProcContainer = intermediateProcessorsContainer
414415

415-
return args, vmContainerFactory, txTypeHandler, scProcessor, nil
416+
return args, vmContainerFactory, txTypeHandler, scProcessorProxy, nil
416417
}

integrationTests/chainSimulator/simulate/simulate_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package simulate
33
import (
44
"encoding/hex"
55
"math/big"
6+
"strings"
67
"testing"
78
"time"
89

@@ -13,6 +14,7 @@ import (
1314
"github.com/multiversx/mx-chain-go/node/chainSimulator"
1415
"github.com/multiversx/mx-chain-go/node/chainSimulator/components/api"
1516
"github.com/multiversx/mx-chain-go/node/chainSimulator/configs"
17+
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
1618
"github.com/stretchr/testify/require"
1719
)
1820

@@ -164,6 +166,83 @@ func TestSimulateIntraShardTxWithGuardian(t *testing.T) {
164166
require.Equal(t, "failed transaction, gas consumed: insufficient funds", cost.ReturnMessage)
165167
}
166168

169+
func TestRelayedV3(t *testing.T) {
170+
if testing.Short() {
171+
t.Skip("this is not a short test")
172+
}
173+
174+
roundDurationInMillis := uint64(6000)
175+
roundsPerEpochOpt := core.OptionalUint64{
176+
HasValue: true,
177+
Value: 20,
178+
}
179+
180+
cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{
181+
BypassTxSignatureCheck: true,
182+
TempDir: t.TempDir(),
183+
PathToInitialConfig: defaultPathToInitialConfig,
184+
NumOfShards: 3,
185+
GenesisTimestamp: time.Now().Unix(),
186+
RoundDurationInMillis: roundDurationInMillis,
187+
RoundsPerEpoch: roundsPerEpochOpt,
188+
ApiInterface: api.NewNoApiInterface(),
189+
MinNodesPerShard: 3,
190+
MetaChainMinNodes: 3,
191+
NumNodesWaitingListMeta: 3,
192+
NumNodesWaitingListShard: 3,
193+
AlterConfigsFunction: func(cfg *config.Configs) {
194+
cfg.EpochConfig.EnableEpochs.SCProcessorV2EnableEpoch = 2
195+
},
196+
})
197+
require.NoError(t, err)
198+
require.NotNil(t, cs)
199+
200+
err = cs.ForceChangeOfEpoch()
201+
require.NoError(t, err)
202+
203+
initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10))
204+
205+
sender, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0))
206+
require.NoError(t, err)
207+
208+
err = cs.SetStateMultiple([]*dtos.AddressState{
209+
{
210+
Address: sender.Bech32,
211+
Balance: "0",
212+
Pairs: map[string]string{
213+
"454c524f4e446573647453484f572d633961633237": "12040002d820",
214+
},
215+
},
216+
})
217+
require.NoError(t, err)
218+
219+
receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0))
220+
require.NoError(t, err)
221+
222+
relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
223+
require.NoError(t, err)
224+
225+
err = cs.GenerateBlocks(1)
226+
require.NoError(t, err)
227+
228+
dataTx := "ESDTTransfer@53484f572d633961633237@3e80@5061796d656e7420746f20504f5334@317820564f444b41204d495820323530204d4c20782033322e3030202b20317820574849534b59204d495820323530204d4c20782033322e3030202b203178204a4147455220434f4c4120323530204d4c20782033322e3030202b2031782047494e20544f4e494320323530204d4c20782033322e3030202b2031782043554241204c49425245203235304d4c20782033322e3030"
229+
tx := generateTransaction(sender.Bytes, 0, receiver.Bytes, big.NewInt(0), dataTx, 0)
230+
tx.RelayerAddr = relayer.Bytes
231+
232+
cost, err := cs.GetNodeHandler(0).GetFacadeHandler().ComputeTransactionGasLimit(tx)
233+
require.NoError(t, err)
234+
require.Equal(t, uint64(0), cost.GasUnits)
235+
require.True(t, strings.Contains(cost.ReturnMessage, "insufficient funds"))
236+
237+
err = cs.ForceChangeOfEpoch()
238+
require.NoError(t, err)
239+
240+
cost, err = cs.GetNodeHandler(0).GetFacadeHandler().ComputeTransactionGasLimit(tx)
241+
require.NoError(t, err)
242+
require.Equal(t, uint64(855001), cost.GasUnits)
243+
require.Equal(t, "", cost.ReturnMessage)
244+
}
245+
167246
func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction {
168247
return &transaction.Transaction{
169248
Nonce: nonce,

0 commit comments

Comments
 (0)