Skip to content
Merged
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
7 changes: 4 additions & 3 deletions factory/processing/txSimulatorProcessComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/multiversx/mx-chain-go/process/coordinator"
"github.com/multiversx/mx-chain-go/process/factory/shard"
"github.com/multiversx/mx-chain-go/process/smartContract"
"github.com/multiversx/mx-chain-go/process/smartContract/processProxy"
"github.com/multiversx/mx-chain-go/process/smartContract/scrCommon"
"github.com/multiversx/mx-chain-go/process/transaction"
"github.com/multiversx/mx-chain-go/process/transactionEvaluator"
Expand Down Expand Up @@ -377,7 +378,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
IsGenesisProcessing: false,
}

scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs)
scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(scProcArgs, pcf.coreData.EpochNotifier())
if err != nil {
return args, nil, nil, nil, err
}
Expand All @@ -389,7 +390,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
Marshalizer: pcf.coreData.InternalMarshalizer(),
SignMarshalizer: pcf.coreData.TxMarshalizer(),
ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(),
ScProcessor: scProcessor,
ScProcessor: scProcessorProxy,
TxFeeHandler: txFeeHandler,
TxTypeHandler: txTypeHandler,
EconomicsFee: pcf.coreData.EconomicsData(),
Expand All @@ -412,5 +413,5 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
args.TransactionProcessor = txProcessor
args.IntermediateProcContainer = intermediateProcessorsContainer

return args, vmContainerFactory, txTypeHandler, scProcessor, nil
return args, vmContainerFactory, txTypeHandler, scProcessorProxy, nil
}
79 changes: 79 additions & 0 deletions integrationTests/chainSimulator/simulate/simulate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package simulate
import (
"encoding/hex"
"math/big"
"strings"
"testing"
"time"

Expand All @@ -13,6 +14,7 @@ import (
"github.com/multiversx/mx-chain-go/node/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components/api"
"github.com/multiversx/mx-chain-go/node/chainSimulator/configs"
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
"github.com/stretchr/testify/require"
)

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

func TestRelayedV3(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}

roundDurationInMillis := uint64(6000)
roundsPerEpochOpt := core.OptionalUint64{
HasValue: true,
Value: 20,
}

cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
NumOfShards: 3,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: roundDurationInMillis,
RoundsPerEpoch: roundsPerEpochOpt,
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 3,
MetaChainMinNodes: 3,
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.SCProcessorV2EnableEpoch = 2
},
})
require.NoError(t, err)
require.NotNil(t, cs)

err = cs.ForceChangeOfEpoch()
require.NoError(t, err)

initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10))

sender, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0))
require.NoError(t, err)

err = cs.SetStateMultiple([]*dtos.AddressState{
{
Address: sender.Bech32,
Balance: "0",
Pairs: map[string]string{
"454c524f4e446573647453484f572d633961633237": "12040002d820",
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hex-encoded key-value pair for account state is a magic string that reduces test readability. Consider using constants or helper functions to make the ESDT token identifier and balance values more explicit.

Suggested change
"454c524f4e446573647453484f572d633961633237": "12040002d820",
hexEncode(esdtTokenIdentifier): esdtTokenBalanceHex,

Copilot uses AI. Check for mistakes.
},
},
})
require.NoError(t, err)

receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0))
require.NoError(t, err)

relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
require.NoError(t, err)

err = cs.GenerateBlocks(1)
require.NoError(t, err)

dataTx := "ESDTTransfer@53484f572d633961633237@3e80@5061796d656e7420746f20504f5334@317820564f444b41204d495820323530204d4c20782033322e3030202b20317820574849534b59204d495820323530204d4c20782033322e3030202b203178204a4147455220434f4c4120323530204d4c20782033322e3030202b2031782047494e20544f4e494320323530204d4c20782033322e3030202b2031782043554241204c49425245203235304d4c20782033322e3030"
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hex-encoded transaction data is a magic string that makes the test difficult to understand and maintain. Consider defining this as a constant with a descriptive name or extracting it to a helper function that builds the ESDT transfer data.

Suggested change
dataTx := "ESDTTransfer@53484f572d633961633237@3e80@5061796d656e7420746f20504f5334@317820564f444b41204d495820323530204d4c20782033322e3030202b20317820574849534b59204d495820323530204d4c20782033322e3030202b203178204a4147455220434f4c4120323530204d4c20782033322e3030202b2031782047494e20544f4e494320323530204d4c20782033322e3030202b2031782043554241204c49425245203235304d4c20782033322e3030"
dataTx := buildESDTTransferData(
"SHOW-c9ac27", // Token identifier (hex: 53484f572d633961633237)
"3e80", // Amount (hex, 16000 decimal)
"Payment to POS4", // Payment data (hex: 5061796d656e7420746f20504f5334)
"1x VODKA MIX 250 ML x 32.00 + 1x WHISKY MIX 250 ML x 32.00 + 1x JAGER COLA 250 ML x 32.00 + 1x GIN TONIC 250 ML x 32.00 + 1x CUBA LIBRE 250ML x 32.00", // Comment (hex: 317820564f444b41204d495820323530204d4c20782033322e3030202b20317820574849534b59204d495820323530204d4c20782033322e3030202b203178204a4147455220434f4c4120323530204d4c20782033322e3030202b2031782047494e20544f4e494320323530204d4c20782033322e3030202b2031782043554241204c49425245203235304d4c20782033322e3030
)

Copilot uses AI. Check for mistakes.
tx := generateTransaction(sender.Bytes, 0, receiver.Bytes, big.NewInt(0), dataTx, 0)
tx.RelayerAddr = relayer.Bytes

cost, err := cs.GetNodeHandler(0).GetFacadeHandler().ComputeTransactionGasLimit(tx)
require.NoError(t, err)
require.Equal(t, uint64(0), cost.GasUnits)
require.True(t, strings.Contains(cost.ReturnMessage, "insufficient funds"))

err = cs.ForceChangeOfEpoch()
require.NoError(t, err)

cost, err = cs.GetNodeHandler(0).GetFacadeHandler().ComputeTransactionGasLimit(tx)
require.NoError(t, err)
require.Equal(t, uint64(855001), cost.GasUnits)
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected gas units value (855001) is a magic number that makes the test brittle and unclear. Consider defining this as a named constant or adding a comment explaining how this value was determined.

Suggested change
require.Equal(t, uint64(855001), cost.GasUnits)
require.Equal(t, uint64(expectedGasUnitsAfterEpochChange), cost.GasUnits)

Copilot uses AI. Check for mistakes.
require.Equal(t, "", cost.ReturnMessage)
}

func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction {
return &transaction.Transaction{
Nonce: nonce,
Expand Down
Loading