Skip to content
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

Merge master into feat refactor eeh 2023.09.18 #780

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
129c15e
implementation of back transfer and ignoring payable checks
sasurobert Jul 4, 2023
ed376fc
revert changes as transfers were added to the wrong stack place
sasurobert Jul 5, 2023
b0b2339
implement get back transfers from vmOutput after executeOnDest is fin…
sasurobert Jul 5, 2023
0bb5c16
implement get back transfers from vmOutput after executeOnDest is fin…
sasurobert Jul 5, 2023
520d435
implement get back transfers from vmOutput after executeOnDest is fin…
sasurobert Jul 5, 2023
6ce97f8
vm hook code generator fixes
andrei-marinica Jul 5, 2023
69b1c41
generated new VM hook: managedGetBackTransfers
andrei-marinica Jul 5, 2023
6c16b54
small refactor
sasurobert Jul 6, 2023
824a4e9
Merge remote-tracking branch 'origin/enable-transfer-back-no-payable-…
sasurobert Jul 6, 2023
21691ff
cross shard async fix
sasurobert Jul 6, 2023
24bb614
back transfer tests
matei-p Jul 10, 2023
e3916e0
adding parent address
sasurobert Jul 10, 2023
750fb2d
test fies
matei-p Jul 10, 2023
401f896
Merge branch 'enable-transfer-back-no-payable-check' of https://githu…
matei-p Jul 10, 2023
b264877
new proto
matei-p Jul 10, 2023
591a773
adding parent address
sasurobert Jul 10, 2023
903ba84
constant revert
sasurobert Jul 10, 2023
7c39607
adding parent address in init state
sasurobert Jul 10, 2023
d0a092d
trying to get parent
sasurobert Jul 11, 2023
c2be3ca
trying to get parent
sasurobert Jul 11, 2023
36c3ad3
finished implementation, simplified.
sasurobert Jul 11, 2023
26f74c7
saving legacy async call storage
sasurobert Jul 12, 2023
be100dc
delete legacy asyncs.
sasurobert Jul 12, 2023
c2cafd6
enabled DeleteUserName builtin func in tests
andrei-marinica Aug 23, 2023
c759a9c
allowing to specify enable epoch flags in tests
andrei-marinica Aug 23, 2023
8affd9c
temp ignoring test big_float_operator_checks.scen.json
andrei-marinica Aug 23, 2023
0f5f756
test fix
andrei-marinica Aug 24, 2023
e5aeed6
Add validation against input.GasProvided for RunSmartContractCall()
camilbancioiu Aug 29, 2023
bcc3179
Add validation against input.GasProvided for RunSmartContractCreate()
camilbancioiu Aug 29, 2023
93d2fd1
Undo changed minExecutionTimeout
camilbancioiu Aug 29, 2023
014d975
Merge branch 'master' into mandos-55
andrei-marinica Aug 29, 2023
0b82381
Remove validation against gasProvided = 0; fix tests
camilbancioiu Aug 29, 2023
936257b
Fix linter issues
camilbancioiu Aug 29, 2023
041635a
Merge branch 'master' into limit-max-gasProvided
camilbancioiu Aug 29, 2023
fec068f
Merge pull request #770 from multiversx/mandos-55
andrei-marinica Aug 29, 2023
e89617f
EI generator - hook names in Rust, cleanup
andrei-marinica Aug 29, 2023
5da0dd1
Merge branch 'master' into limit-max-gasProvided
camilbancioiu Aug 29, 2023
e8582a4
vm hook code generator fixes
andrei-marinica Aug 29, 2023
543e7ff
Merge pull request #776 from multiversx/ei-export
andrei-marinica Aug 29, 2023
28d3cd3
Merge branch 'master' into limit-max-gasProvided
sasurobert Aug 30, 2023
65d9f7f
Merge branch 'master' into enable-transfer-back-no-payable-check
andrei-marinica Aug 30, 2023
54599cf
Merge pull request #775 from multiversx/limit-max-gasProvided
camilbancioiu Aug 30, 2023
89ad73f
fix after merge
sasurobert Aug 30, 2023
06294ed
Merge branch 'master' into enable-transfer-back-no-payable-check
sasurobert Aug 30, 2023
e2b9f05
typo
andrei-marinica Aug 30, 2023
9b2c554
Merge branch 'enable-transfer-back-no-payable-check' of github.com:El…
andrei-marinica Aug 30, 2023
69e712b
Merge pull request #754 from multiversx/enable-transfer-back-no-payab…
sasurobert Aug 30, 2023
8ec02e4
making fixes on log events standard
sasurobert Sep 8, 2023
014d0c6
making fixes on log events standard
sasurobert Sep 11, 2023
110b264
making fixes on log events standard
sasurobert Sep 11, 2023
90d8365
fixed scenario event log testing after merge
andrei-marinica Sep 11, 2023
0bd0a54
Merge pull request #777 from multiversx/log-todos
sasurobert Sep 12, 2023
823f1dc
Merge branch 'master' into logEvents-fixes
andrei-marinica Sep 12, 2023
fc943b5
event log scenario test fixes
andrei-marinica Sep 12, 2023
970066d
Merge branch 'master' into logEvents-fixes
sasurobert Sep 12, 2023
ac3ccce
Merge remote-tracking branch 'origin/logEvents-fixes' into logEvents-…
sasurobert Sep 12, 2023
e15ab11
event log scenario test fixes
andrei-marinica Sep 12, 2023
bea2eb1
event log scenario test fixes
andrei-marinica Sep 12, 2023
3a61cde
Merge branch 'logEvents-fixes' of github.com:ElrondNetwork/arwen-wasm…
andrei-marinica Sep 12, 2023
a5202fb
fixes after review. plus reintroduce gas code.
sasurobert Sep 12, 2023
b816043
fixes after review. plus reintroduce gas code.
sasurobert Sep 12, 2023
28f05e5
revert callType - scprocessor needs to know about directCall
sasurobert Sep 12, 2023
f8a0d0f
revert callType - scprocessor needs to know about directCall
sasurobert Sep 12, 2023
46dd1c9
setting the arguments
sasurobert Sep 12, 2023
a047c8e
fixed tests
sasurobert Sep 12, 2023
8bc981a
Merge pull request #778 from multiversx/logEvents-fixes
sasurobert Sep 13, 2023
ad57760
fixed transferAndExecute log for eGLD transfer
sasurobert Sep 13, 2023
aeb845f
constants everywhere
sasurobert Sep 13, 2023
41c60e3
Merge pull request #779 from multiversx/forgotten-complete-call
sasurobert Sep 14, 2023
3ad8e30
Merge branch 'master' of https://github.com/multiversx/mx-chain-vm-go…
sstanculeanu Sep 18, 2023
afab2d8
updated mx-chain-vm-common-go + updated EnableEpochsHandlerStubAllFlags
sstanculeanu Sep 18, 2023
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
1 change: 1 addition & 0 deletions executor/vmHooks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions executor/wrapper/wrapperVMHooks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/gogo/protobuf v1.3.2
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.2.15-0.20230828081708-1d1190bec635
github.com/multiversx/mx-chain-core-go v1.2.17-0.20230918144211-8728c8a6e2d5
github.com/multiversx/mx-chain-crypto-go v1.2.8
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-scenario-go v1.2.1
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20230901130135-4d211b1a41d2
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20230918144414-73020ec780b7
github.com/multiversx/mx-components-big-int v1.0.0
github.com/pelletier/go-toml v1.9.3
github.com/stretchr/testify v1.8.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-core-go v1.2.15-0.20230828081708-1d1190bec635 h1:BtuOBkYy3heZYLaqRys94rPwEiQq/HKHYRL8RXAq46A=
github.com/multiversx/mx-chain-core-go v1.2.15-0.20230828081708-1d1190bec635/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-core-go v1.2.17-0.20230918144211-8728c8a6e2d5 h1:j20zxnqhffqW35Cek5yvRYYANE+ws4XMB2G4t4o4aOs=
github.com/multiversx/mx-chain-core-go v1.2.17-0.20230918144211-8728c8a6e2d5/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU=
github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8=
github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY=
github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk=
github.com/multiversx/mx-chain-scenario-go v1.2.1 h1:9eC6VcOEAKRRKZ7EbSWPLzCdNIMWwuNBtAZlgR4cSMA=
github.com/multiversx/mx-chain-scenario-go v1.2.1/go.mod h1:EuZY7DpNFHVNSxJR8dKE1z2I8gBYfEFFPSwNUOXptqE=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20230901130135-4d211b1a41d2 h1:5ZyyNUvyV4QLIjz/tHgqSDC99FmF3H2q2p3NajOTkVc=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20230901130135-4d211b1a41d2/go.mod h1:uDaefuPXa9p0sb+wrUk16J0z+U324Hh894Y5oVXeVdI=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20230918144414-73020ec780b7 h1:MBABPvX640D6NkmuIaEhM8v/WLdSDRRIfEjilQX2NO0=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20230918144414-73020ec780b7/go.mod h1:VtmaxMU7FtRdTLLcLd0D01vcTm0drVYvaJ0U88ikr38=
github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8=
github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/json/scenariosAdderLog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ GetPointsUsed: 135352
GetPointsUsed: 135352
Reset: true
SetPointsUsed: 0
SetGasLimit: 18446744073708343115
SetGasLimit: 9223372036853567307
SetBreakpointValue: 0
HasFunction(getSum): true
CallFunction(getSum):
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/json/scenariosContracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package vmjsonintegrationtest

import (
"testing"

worldhook "github.com/multiversx/mx-chain-vm-go/mock/world"
)

func TestRustAdder(t *testing.T) {
Expand Down Expand Up @@ -69,6 +71,7 @@ func TestDnsContract(t *testing.T) {

ScenariosTest(t).
Folder("dns").
WithEnableEpochsHandler(worldhook.EnableEpochsHandlerStubNoFlags()).
Run().
CheckNoError()
}
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/json/scenariosExecutorLogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vmjsonintegrationtest
import (
"testing"

worldhook "github.com/multiversx/mx-chain-vm-go/mock/world"
"github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor"
"github.com/multiversx/mx-chain-vm-go/wasmer"
"github.com/multiversx/mx-chain-vm-go/wasmer2"
Expand Down Expand Up @@ -223,6 +224,7 @@ func TestDnsContractLog(t *testing.T) {

expected := ScenariosTest(t).
Folder("dns").
WithEnableEpochsHandler(worldhook.EnableEpochsHandlerStubNoFlags()).
WithExecutorFactory(wasmer.ExecutorFactory()).
WithExecutorLogs().
Run().
Expand All @@ -231,6 +233,7 @@ func TestDnsContractLog(t *testing.T) {

ScenariosTest(t).
Folder("dns").
WithEnableEpochsHandler(worldhook.EnableEpochsHandlerStubNoFlags()).
WithExecutorFactory(wasmer2.ExecutorFactory()).
WithExecutorLogs().
Run().
Expand Down
36 changes: 23 additions & 13 deletions integrationTests/json/scenariosTestCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
logger "github.com/multiversx/mx-chain-logger-go"
mc "github.com/multiversx/mx-chain-scenario-go/controller"
vmi "github.com/multiversx/mx-chain-vm-common-go"
"github.com/multiversx/mx-chain-vm-go/executor"
executorwrapper "github.com/multiversx/mx-chain-vm-go/executor/wrapper"
worldhook "github.com/multiversx/mx-chain-vm-go/mock/world"
am "github.com/multiversx/mx-chain-vm-go/scenarioexec"
"github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor"
"github.com/stretchr/testify/require"
Expand All @@ -33,23 +35,25 @@ func getTestRoot() string {

// ScenariosTestBuilder defines the Scenarios builder component
type ScenariosTestBuilder struct {
t *testing.T
folder string
singleFile string
exclusions []string
executorLogger executorwrapper.ExecutorLogger
executorFactory executor.ExecutorAbstractFactory
currentError error
t *testing.T
folder string
singleFile string
exclusions []string
executorLogger executorwrapper.ExecutorLogger
executorFactory executor.ExecutorAbstractFactory
enableEpochsHandler vmi.EnableEpochsHandler
currentError error
}

// ScenariosTest will create a new ScenariosTestBuilder instance
func ScenariosTest(t *testing.T) *ScenariosTestBuilder {
return &ScenariosTestBuilder{
t: t,
folder: "",
singleFile: "",
executorLogger: nil,
executorFactory: nil,
t: t,
folder: "",
singleFile: "",
executorLogger: nil,
executorFactory: nil,
enableEpochsHandler: worldhook.EnableEpochsHandlerStubAllFlags(),
}
}

Expand Down Expand Up @@ -89,6 +93,12 @@ func (mtb *ScenariosTestBuilder) WithExecutorFactory(executorFactory executor.Ex
return mtb
}

// WithEnableEpochsHandler overrides the epoch flags
func (mtb *ScenariosTestBuilder) WithEnableEpochsHandler(enableEpochsHandler vmi.EnableEpochsHandler) *ScenariosTestBuilder {
mtb.enableEpochsHandler = enableEpochsHandler
return mtb
}

// Run will start the testing process
func (mtb *ScenariosTestBuilder) Run() *ScenariosTestBuilder {
executor, err := am.NewVMTestExecutor()
Expand All @@ -98,7 +108,7 @@ func (mtb *ScenariosTestBuilder) Run() *ScenariosTestBuilder {
if check.IfNil(mtb.executorFactory) {
mtb.executorFactory = testexecutor.NewDefaultTestExecutorFactory(mtb.t)
}

executor.World.EnableEpochsHandler = mtb.enableEpochsHandler
executor.OverrideVMExecutor = mtb.executorFactory
if mtb.executorLogger != nil {
executor.OverrideVMExecutor = executorwrapper.NewWrappedExecutorFactory(
Expand Down
1 change: 1 addition & 0 deletions mock/context/executorMockFunc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion mock/context/outputContextMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func (o *OutputContextMock) DeleteFirstReturnData() {
// WriteLog mocked method
func (o *OutputContextMock) WriteLog(_ []byte, _ [][]byte, _ [][]byte) {}

// WriteLogWithIdentifier mocked method
func (o *OutputContextMock) WriteLogWithIdentifier(_ []byte, _ [][]byte, _ [][]byte, _ []byte) {
}

// TransferValueOnly mocked method
func (o *OutputContextMock) TransferValueOnly(_ []byte, _ []byte, _ *big.Int, _ bool) error {
return o.TransferResult
Expand All @@ -177,7 +181,7 @@ func (o *OutputContextMock) Transfer(_ []byte, _ []byte, _ uint64, _ uint64, _ *
}

// TransferESDT mocked method
func (o *OutputContextMock) TransferESDT(transfersArgs *vmhost.ESDTTransfersArgs, _ *vmcommon.ContractCallInput) (uint64, error) {
func (o *OutputContextMock) TransferESDT(_ *vmhost.ESDTTransfersArgs, _ *vmcommon.ContractCallInput) (uint64, error) {
return 0, nil
}

Expand Down
8 changes: 8 additions & 0 deletions mock/context/outputContextStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type OutputContextStub struct {
GetOutputAccountCalled func(address []byte) (*vmcommon.OutputAccount, bool)
DeleteOutputAccountCalled func(address []byte)
WriteLogCalled func(address []byte, topics [][]byte, data [][]byte)
WriteLogWithIdentifierCalled func(address []byte, topics [][]byte, data [][]byte, identifier []byte)
TransferCalled func(destination []byte, sender []byte, gasLimit uint64, gasLocked uint64, value *big.Int, asyncData []byte, input []byte) error
TransferESDTCalled func(transfersArgs *vmhost.ESDTTransfersArgs, input *vmcommon.ContractCallInput) (uint64, error)
GetRefundCalled func() uint64
Expand Down Expand Up @@ -144,6 +145,13 @@ func (o *OutputContextStub) WriteLog(address []byte, topics [][]byte, data [][]b
}
}

// WriteLogWithIdentifier mocked method
func (o *OutputContextStub) WriteLogWithIdentifier(address []byte, topics [][]byte, data [][]byte, identifier []byte) {
if o.WriteLogWithIdentifierCalled != nil {
o.WriteLogWithIdentifierCalled(address, topics, data, identifier)
}
}

// TransferValueOnly mocked method
func (o *OutputContextStub) TransferValueOnly(destination []byte, sender []byte, value *big.Int, checkPayable bool) error {
if o.TransferValueOnlyCalled != nil {
Expand Down
134 changes: 134 additions & 0 deletions mock/contracts/backTransferSC.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package contracts

import (
"bytes"
"fmt"
"math/big"

"github.com/multiversx/mx-chain-core-go/data/vm"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/multiversx/mx-chain-vm-common-go/txDataBuilder"
mock "github.com/multiversx/mx-chain-vm-go/mock/context"
test "github.com/multiversx/mx-chain-vm-go/testcommon"
"github.com/multiversx/mx-chain-vm-go/vmhost"
"github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks"
)

// BackTransfer_ParentCallsChild is an exposed mock contract method
func BackTransfer_ParentCallsChild(instanceMock *mock.InstanceMock, config interface{}) {
instanceMock.AddMockMethod("callChild", func() *mock.InstanceMock {
host := instanceMock.Host
instance := mock.GetMockInstance(host)

storedResult := []byte("ok")

testConfig := config.(*test.TestConfig)
input := test.DefaultTestContractCallInput()
input.GasProvided = testConfig.GasProvidedToChild
input.CallerAddr = testConfig.ParentAddress
input.RecipientAddr = testConfig.ChildAddress
input.Function = "childFunction"
returnValue := ExecuteOnDestContextInMockContracts(host, input)
if returnValue != 0 {
host.Runtime().FailExecution(fmt.Errorf("return value %d", returnValue))
}
managedTypes := host.ManagedTypes()

arguments := host.Runtime().Arguments()
if len(arguments) > 0 {
checkBackTransfers := arguments[0]
if checkBackTransfers[0] == 1 {
esdtTransfers, egld := managedTypes.GetBackTransfers()
if len(esdtTransfers) != 1 {
host.Runtime().FailExecution(fmt.Errorf("found esdt transfers %d", len(esdtTransfers)))
storedResult = []byte("err")
}
if !bytes.Equal(test.ESDTTestTokenName, esdtTransfers[0].ESDTTokenName) {
host.Runtime().FailExecution(fmt.Errorf("invalid token name %s", string(esdtTransfers[0].ESDTTokenName)))
storedResult = []byte("err")
}
if big.NewInt(0).SetUint64(testConfig.ESDTTokensToTransfer).Cmp(esdtTransfers[0].ESDTValue) != 0 {
host.Runtime().FailExecution(fmt.Errorf("invalid token value %d", esdtTransfers[0].ESDTValue.Uint64()))
storedResult = []byte("err")
}
if egld.Cmp(big.NewInt(testConfig.TransferFromChildToParent)) != 0 {
host.Runtime().FailExecution(fmt.Errorf("invalid egld value %d", egld))
storedResult = []byte("err")
}
}
}

_, err := host.Storage().SetStorage(test.ParentKeyA, storedResult)
if err != nil {
host.Runtime().FailExecution(err)
}

return instance
})
}

// BackTransfer_ChildMakesAsync is an exposed mock contract method
func BackTransfer_ChildMakesAsync(instanceMock *mock.InstanceMock, config interface{}) {
instanceMock.AddMockMethod("childFunction", func() *mock.InstanceMock {
host := instanceMock.Host
instance := mock.GetMockInstance(host)
testConfig := config.(*test.TestConfig)

callData := txDataBuilder.NewBuilder()
callData.Func("wasteGas")
callData.Int64(0)

err := host.Async().RegisterAsyncCall("testGroup", &vmhost.AsyncCall{
Status: vmhost.AsyncCallPending,
Destination: testConfig.NephewAddress,
Data: callData.ToBytes(),
ValueBytes: big.NewInt(0).Bytes(),
SuccessCallback: testConfig.SuccessCallback,
ErrorCallback: testConfig.ErrorCallback,
GasLimit: uint64(300),
GasLocked: testConfig.GasToLock,
CallbackClosure: nil,
})
if err != nil {
host.Runtime().FailExecution(err)
}
return instance
})
}

// BackTransfer_ChildCallback is an exposed mock contract method
func BackTransfer_ChildCallback(instanceMock *mock.InstanceMock, config interface{}) {
instanceMock.AddMockMethod("myCallback", func() *mock.InstanceMock {
host := instanceMock.Host
instance := mock.GetMockInstance(host)
testConfig := config.(*test.TestConfig)

valueBytes := big.NewInt(testConfig.TransferFromChildToParent).Bytes()
err := host.Output().Transfer(
testConfig.ParentAddress,
testConfig.ChildAddress, 0, 0, big.NewInt(0).SetBytes(valueBytes), nil, []byte{}, vm.DirectCall)
if err != nil {
host.Runtime().FailExecution(err)
}

transfer := &vmcommon.ESDTTransfer{
ESDTValue: big.NewInt(int64(testConfig.ESDTTokensToTransfer)),
ESDTTokenName: test.ESDTTestTokenName,
ESDTTokenType: 0,
ESDTTokenNonce: 0,
}

ret := vmhooks.TransferESDTNFTExecuteWithTypedArgs(
host,
testConfig.ParentAddress,
[]*vmcommon.ESDTTransfer{transfer},
int64(testConfig.GasProvidedToChild),
nil,
nil)
if ret != 0 {
host.Runtime().FailExecution(fmt.Errorf("Transfer ESDT failed"))
}

return instance
})
}
Loading