(testCase common3.TestCase, result *states.PreExecResult, execEnv ExecEnv)
| 321 | } |
| 322 | |
| 323 | func checkExecResult(testCase common3.TestCase, result *states.PreExecResult, execEnv ExecEnv) { |
| 324 | assertEq(result.State, byte(1)) |
| 325 | ret := result.Result.(string) |
| 326 | switch testCase.Method { |
| 327 | case "timestamp": |
| 328 | sink := common.NewZeroCopySink(nil) |
| 329 | sink.WriteUint64(uint64(execEnv.Time)) |
| 330 | assertEq(ret, hex.EncodeToString(sink.Bytes())) |
| 331 | case "block_height": |
| 332 | sink := common.NewZeroCopySink(nil) |
| 333 | sink.WriteUint32(uint32(execEnv.Height)) |
| 334 | assertEq(ret, hex.EncodeToString(sink.Bytes())) |
| 335 | case "self_address", "entry_address": |
| 336 | assertEq(ret, hex.EncodeToString(execEnv.Contract[:])) |
| 337 | case "caller_address": |
| 338 | assertEq(ret, hex.EncodeToString(common.ADDRESS_EMPTY[:])) |
| 339 | case "current_txhash": |
| 340 | hash := execEnv.Tx.Hash() |
| 341 | assertEq(ret, hex.EncodeToString(hash[:])) |
| 342 | case "current_blockhash": |
| 343 | assertEq(ret, hex.EncodeToString(execEnv.BlockHash[:])) |
| 344 | //case "sha256": |
| 345 | // let data :&[u8]= source.read().unwrap(); |
| 346 | // sink.write(runtime::sha256(&data)) |
| 347 | //} |
| 348 | default: |
| 349 | if len(testCase.Expect) != 0 { |
| 350 | expect, err := utils.ParseParams(testCase.Expect) |
| 351 | checkErr(err) |
| 352 | if execEnv.Tx.TxType == types.InvokeNeo { |
| 353 | val := buildNeoVmValueFromExpect(expect) |
| 354 | cv, err := val.ConvertNeoVmValueHexString() |
| 355 | checkErr(err) |
| 356 | assertEq(cv, result.Result) |
| 357 | } else if execEnv.Tx.TxType == types.InvokeWasm { |
| 358 | exp, err := utils2.BuildWasmContractParam(expect) |
| 359 | checkErr(err) |
| 360 | assertEq(ret, hex.EncodeToString(exp)) |
| 361 | } else { |
| 362 | panic("error tx type") |
| 363 | } |
| 364 | } |
| 365 | if len(testCase.Notify) != 0 { |
| 366 | js, _ := json.Marshal(result.Notify) |
| 367 | assertEq(true, strings.Contains(string(js), testCase.Notify)) |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | func buildNeoVmValueFromExpect(expectlist []interface{}) *vmtypes.VmValue { |
| 373 | if len(expectlist) > 1 { |
no test coverage detected