@@ -15,18 +15,28 @@ import (
15
15
16
16
var testSalt = sha256 .Sum256 ([]byte ("a1" ))
17
17
18
- func GetHelloWorldContract ( ) []byte {
19
- contractFile := path .Join (GetCurrentDirectory (), "../../../../../wasms/test_hello_world .wasm" )
18
+ func getTestContract ( name string ) []byte {
19
+ contractFile := path .Join (GetCurrentDirectory (), "../../../../../wasms/test_" + name + " .wasm" )
20
20
ret , err := os .ReadFile (contractFile )
21
21
if err != nil {
22
22
str := fmt .Sprintf (
23
- "unable to read test_hello_world.wasm (%v) please run `make build-test-wasms` at the project root directory" ,
24
- err )
23
+ "unable to read %s.wasm (%v) please run `make build-test-wasms` at the project root directory" ,
24
+ name ,
25
+ err ,
26
+ )
25
27
panic (str )
26
28
}
27
29
return ret
28
30
}
29
31
32
+ func GetHelloWorldContract () []byte {
33
+ return getTestContract ("hello_world" )
34
+ }
35
+
36
+ func GetNoArgConstructorContract () []byte {
37
+ return getTestContract ("no_arg_constructor" )
38
+ }
39
+
30
40
func CreateInvokeHostOperation (sourceAccount string , contractID xdr.Hash , method string , args ... xdr.ScVal ) * txnbuild.InvokeHostFunction {
31
41
return & txnbuild.InvokeHostFunction {
32
42
HostFunction : xdr.HostFunction {
@@ -116,3 +126,39 @@ func createCreateContractOperation(sourceAccount string, salt xdr.Uint256, contr
116
126
SourceAccount : sourceAccount ,
117
127
}
118
128
}
129
+
130
+ func CreateCreateNoArgConstructorContractOperation (sourceAccount string ) * txnbuild.InvokeHostFunction {
131
+ contractHash := xdr .Hash (sha256 .Sum256 (GetNoArgConstructorContract ()))
132
+ salt := xdr .Uint256 (testSalt )
133
+ return createCreateContractV2Operation (sourceAccount , salt , contractHash )
134
+ }
135
+
136
+ func createCreateContractV2Operation (
137
+ sourceAccount string , salt xdr.Uint256 , contractHash xdr.Hash ,
138
+ ) * txnbuild.InvokeHostFunction {
139
+ sourceAccountID := xdr .MustAddress (sourceAccount )
140
+ return & txnbuild.InvokeHostFunction {
141
+ HostFunction : xdr.HostFunction {
142
+ Type : xdr .HostFunctionTypeHostFunctionTypeCreateContractV2 ,
143
+ CreateContractV2 : & xdr.CreateContractArgsV2 {
144
+ ContractIdPreimage : xdr.ContractIdPreimage {
145
+ Type : xdr .ContractIdPreimageTypeContractIdPreimageFromAddress ,
146
+ FromAddress : & xdr.ContractIdPreimageFromAddress {
147
+ Address : xdr.ScAddress {
148
+ Type : xdr .ScAddressTypeScAddressTypeAccount ,
149
+ AccountId : & sourceAccountID ,
150
+ },
151
+ Salt : salt ,
152
+ },
153
+ },
154
+ Executable : xdr.ContractExecutable {
155
+ Type : xdr .ContractExecutableTypeContractExecutableWasm ,
156
+ WasmHash : & contractHash ,
157
+ },
158
+ ConstructorArgs : nil ,
159
+ },
160
+ },
161
+ Auth : []xdr.SorobanAuthorizationEntry {},
162
+ SourceAccount : sourceAccount ,
163
+ }
164
+ }
0 commit comments