(code []byte)
| 123 | } |
| 124 | |
| 125 | func ExactTestCase(code []byte) [][]common3.TestCase { |
| 126 | m, err := wasm.ReadModule(bytes.NewReader(code), func(name string) (*wasm.Module, error) { |
| 127 | switch name { |
| 128 | case "env": |
| 129 | return wasmvm.NewHostModule(), nil |
| 130 | } |
| 131 | return nil, fmt.Errorf("module %q unknown", name) |
| 132 | }) |
| 133 | checkErr(err) |
| 134 | |
| 135 | compiled, err := exec.CompileModule(m) |
| 136 | checkErr(err) |
| 137 | |
| 138 | vm, err := exec.NewVMWithCompiled(compiled, 10*1024*1024) |
| 139 | checkErr(err) |
| 140 | |
| 141 | param := common.NewZeroCopySink(nil) |
| 142 | param.WriteString(testcaseMethod) |
| 143 | host := &wasmvm.Runtime{Input: param.Bytes()} |
| 144 | vm.HostData = host |
| 145 | vm.RecoverPanic = true |
| 146 | envGasLimit := uint64(100000000000000) |
| 147 | envExecStep := uint64(100000000000000) |
| 148 | vm.ExecMetrics = &exec.Gas{GasLimit: &envGasLimit, GasPrice: 0, GasFactor: 5, ExecStep: &envExecStep} |
| 149 | vm.CallStackDepth = 1024 |
| 150 | |
| 151 | entry := compiled.RawModule.Export.Entries["invoke"] |
| 152 | index := int64(entry.Index) |
| 153 | _, err = vm.ExecCode(index) |
| 154 | checkErr(err) |
| 155 | |
| 156 | var testCase [][]common3.TestCase |
| 157 | source := common.NewZeroCopySource(host.Output) |
| 158 | jsonCase, _, _, _ := source.NextString() |
| 159 | |
| 160 | if len(jsonCase) == 0 { |
| 161 | panic("failed to get testcase data from contract") |
| 162 | } |
| 163 | |
| 164 | err = json.Unmarshal([]byte(jsonCase), &testCase) |
| 165 | checkErr(err) |
| 166 | |
| 167 | return testCase |
| 168 | } |
| 169 | |
| 170 | func LoadContracts(dir string) (map[string][]byte, error) { |
| 171 | contracts := make(map[string][]byte) |
no test coverage detected