-
Notifications
You must be signed in to change notification settings - Fork 26
/
deployerSimpleSC.go
106 lines (85 loc) · 2.62 KB
/
deployerSimpleSC.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package contracts
import (
"math/big"
"github.com/ElrondNetwork/wasm-vm/arwen/elrondapi"
mock "github.com/ElrondNetwork/wasm-vm/mock/context"
"github.com/ElrondNetwork/wasm-vm/testcommon"
"github.com/stretchr/testify/require"
)
func DeployContractFromSourceMock(instanceMock *mock.InstanceMock, config interface{}) {
instanceMock.AddMockMethod("deployContractFromSource", func() *mock.InstanceMock {
host := instanceMock.Host
instance := mock.GetMockInstance(host)
t := instance.T
arguments := host.Runtime().Arguments()
if len(arguments) < 3 {
host.Runtime().SignalUserError("wrong num of arguments")
return instance
}
sourceContractAddress := arguments[0]
codeMetadata := arguments[1]
gasForInit := big.NewInt(0).SetBytes(arguments[2])
newAddress, err :=
elrondapi.DeployFromSourceContractWithTypedArgs(
host,
sourceContractAddress,
codeMetadata,
big.NewInt(0),
[][]byte{},
gasForInit.Int64(),
)
if err != nil {
host.Runtime().FailExecution(err)
return instance
}
require.NotNil(t, newAddress)
host.Output().Finish(newAddress)
return instance
})
}
// InitMockMethod
func InitMockMethod(instanceMock *mock.InstanceMock, config interface{}) {
testConfig := config.(GasTestConfig)
instanceMock.AddMockMethod("init", testcommon.SimpleWasteGasMockMethod(instanceMock, testConfig.GetGasUsedByChild()))
}
type CallbackTestConfig interface {
CallbackFails() bool
}
// CallbackMockMethodThatCouldFail
func CallbackMockMethodThatCouldFail(instanceMock *mock.InstanceMock, config interface{}) {
testConfig := config.(CallbackTestConfig)
instanceMock.AddMockMethod("callBack", func() *mock.InstanceMock {
host := instanceMock.Host
instance := mock.GetMockInstance(host)
if testConfig.CallbackFails() {
host.Runtime().SignalUserError("fail")
return instance
}
return instance
})
}
func UpdateContractFromSourceMock(instanceMock *mock.InstanceMock, config interface{}) {
instanceMock.AddMockMethod("updateContractFromSource", func() *mock.InstanceMock {
host := instanceMock.Host
instance := mock.GetMockInstance(host)
arguments := host.Runtime().Arguments()
if len(arguments) < 4 {
host.Runtime().SignalUserError("wrong num of arguments")
return instance
}
sourceContractAddress := arguments[0]
destinationContractAddress := arguments[1]
codeMetadata := arguments[2]
gasForInit := big.NewInt(0).SetBytes(arguments[3])
elrondapi.UpgradeFromSourceContractWithTypedArgs(
host,
sourceContractAddress,
destinationContractAddress,
big.NewInt(0).Bytes(),
[][]byte{},
gasForInit.Int64(),
codeMetadata,
)
return instance
})
}