-
Notifications
You must be signed in to change notification settings - Fork 215
Fixes tx cost endpoint #7169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes tx cost endpoint #7169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ package simulate | |||||||||||||||
| import ( | ||||||||||||||||
| "encoding/hex" | ||||||||||||||||
| "math/big" | ||||||||||||||||
| "strings" | ||||||||||||||||
| "testing" | ||||||||||||||||
| "time" | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -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" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -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", | ||||||||||||||||
| }, | ||||||||||||||||
| }, | ||||||||||||||||
| }) | ||||||||||||||||
| 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" | ||||||||||||||||
|
||||||||||||||||
| 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
AI
Aug 5, 2025
There was a problem hiding this comment.
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.
| require.Equal(t, uint64(855001), cost.GasUnits) | |
| require.Equal(t, uint64(expectedGasUnitsAfterEpochChange), cost.GasUnits) |
There was a problem hiding this comment.
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.