From eabdda0d367210fc5e31e24b6f7b1fea1572c581 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Mon, 6 May 2024 16:36:20 +0800 Subject: [PATCH] fix: runtime call not found (#749) * fix: state call not found * fix: code style --- executor/src/task.rs | 15 +++++++++++---- packages/e2e/src/state.test.ts | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/executor/src/task.rs b/executor/src/task.rs index ea2c2f95..83362816 100644 --- a/executor/src/task.rs +++ b/executor/src/task.rs @@ -133,17 +133,24 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result = vec![]; for (call, params) in task.calls { - let mut vm = runtime_call::run(runtime_call::Config { + log::trace!("Calling {}", call); + + let vm = runtime_call::run(runtime_call::Config { virtual_machine: vm_proto.clone(), function_to_call: call.as_str(), parameter: params.into_iter().map(|x| x.0), storage_main_trie_changes, max_log_level: task.runtime_log_level, calculate_trie_changes: false, - }) - .unwrap(); + }); - log::trace!("Calling {}", call); + let mut vm = match vm { + Ok(vm) => vm, + // ignore host_vm_proto since it doesn't provide any info + Err((start_err, _host_vm_proto)) => { + return Ok(TaskResponse::Error(start_err.to_string())); + } + }; let res = loop { vm = match vm { diff --git a/packages/e2e/src/state.test.ts b/packages/e2e/src/state.test.ts index 9a215c88..2b9e315b 100644 --- a/packages/e2e/src/state.test.ts +++ b/packages/e2e/src/state.test.ts @@ -1,8 +1,10 @@ +import { HexString } from '@polkadot/util/types' import { describe, expect, it } from 'vitest' import { readFileSync } from 'node:fs' +import { runTask, taskHandler } from '@acala-network/chopsticks-core' import path from 'node:path' -import { api, check, checkHex, env, mockCallback, setupApi, testingPairs } from './helper.js' +import { api, chain, check, checkHex, env, mockCallback, setupApi, testingPairs } from './helper.js' import networks from './networks.js' setupApi(env.acala) @@ -181,4 +183,21 @@ describe('state rpc', () => { await teardown() }) + + it('handles unknown runtime call', async () => { + const parent = chain.head + const wasm = await parent.wasm + const calls: [string, HexString[]][] = [['unknown_method', ['0x']]] + const result = await runTask( + { + wasm, + calls, + mockSignatureHost: false, + allowUnresolvedImports: false, + runtimeLogLevel: 0, + }, + taskHandler(parent), + ) + expect(result).toMatchObject({ Error: 'Function to start was not found.' }) + }) })