Skip to content

Commit

Permalink
fix: runtime call not found (#749)
Browse files Browse the repository at this point in the history
* fix: state call not found

* fix: code style
  • Loading branch information
qiweiii committed May 6, 2024
1 parent d5e7ebc commit eabdda0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
15 changes: 11 additions & 4 deletions executor/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,24 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
let mut runtime_logs: Vec<LogInfo> = 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 {
Expand Down
21 changes: 20 additions & 1 deletion packages/e2e/src/state.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.' })
})
})

0 comments on commit eabdda0

Please sign in to comment.