@@ -3,6 +3,7 @@ package simulate
33import (
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+
167246func 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