-
Notifications
You must be signed in to change notification settings - Fork 26
/
asyncChildSCRecursive.go
48 lines (38 loc) · 1.6 KB
/
asyncChildSCRecursive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package contracts
import (
"math/big"
mock "github.com/ElrondNetwork/wasm-vm/mock/context"
test "github.com/ElrondNetwork/wasm-vm/testcommon"
"github.com/ElrondNetwork/elrond-vm-common/txDataBuilder"
"github.com/stretchr/testify/require"
)
// RecursiveAsyncCallRecursiveChildMock is an exposed mock contract method
func RecursiveAsyncCallRecursiveChildMock(instanceMock *mock.InstanceMock, config interface{}) {
testConfig := config.(*AsyncCallBaseTestConfig)
instanceMock.AddMockMethod("recursiveAsyncCall", func() *mock.InstanceMock {
host := instanceMock.Host
instance := mock.GetMockInstance(host)
t := instance.T
arguments := host.Runtime().Arguments()
host.Metering().UseGas(testConfig.GasUsedByChild)
recursiveChildCalls := big.NewInt(0).SetBytes(arguments[0]).Uint64()
recursiveChildCalls = recursiveChildCalls - 1
if recursiveChildCalls == 0 {
return instance
}
destination := host.Runtime().GetContextAddress()
function := string("recursiveAsyncCall")
value := big.NewInt(testConfig.TransferFromParentToChild).Bytes()
callData := txDataBuilder.NewBuilder()
callData.Func(function)
callData.BigInt(big.NewInt(int64(recursiveChildCalls)))
err := host.Runtime().ExecuteAsyncCall(destination, callData.ToBytes(), value)
require.Nil(t, err)
return instance
})
}
// CallBackRecursiveChildMock is an exposed mock contract method
func CallBackRecursiveChildMock(instanceMock *mock.InstanceMock, config interface{}) {
testConfig := config.(*AsyncCallBaseTestConfig)
instanceMock.AddMockMethod("callBack", test.SimpleWasteGasMockMethod(instanceMock, testConfig.GasUsedByCallback))
}