mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 04:41:04 +00:00
BlockId removal: runtime-api refactor (#13255)
* BlockId removal: refactor of runtime API It changes the arguments of: - `ApiExt` methods: `has_api`, `has_api_with`, `api_version` - `CallApiAt` method: `runtime_version_at` from: `BlockId<Block>` to: `Block::Hash` It also changes the first argument of all generated runtime API calls from: `BlockId<Block>` to: `Block::Hash` This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292) * BlockId removal: refactor of runtime API - tests - tests adjusted to new runtime API, - some tests migrated from block number to block hash * benchmarking-cli: BlockId(0) migrated to info().genesis_hash `runtime_api.call()` now requires the block hash instead of BlockId::Number. To access the genesis hash widely used in benchmarking engine the Client was constrained to satisfy `sp_blockchain::HeaderBackend<Block>` trait which provides `info().genesis_hash`. * trivial: api.call(BlockId) -> api.call(Hash) - Migrated all `runtime_api.calls` to use Hash - Noteworthy (?): -- `validate_transaction_blocking` in transaction pool, * CallApiAtParams::at changed to Block::Hash * missed doc updated * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * ".git/.scripts/commands/fmt/fmt.sh" * BlockId removal: Benchmark::consumed_weight Little refactor around `Benchmark::consumed_weight`: `BlockId` removed. * at_hash renamed * wrong merge fixed * beefy worker: merged with master * beefy: tests: missing block problem fixed * Apply review suggestion * fix --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
ac13aaeb2f
commit
7a10154188
@@ -36,9 +36,9 @@ use sp_consensus::SelectChain;
|
||||
fn calling_function_with_strat(strat: ExecutionStrategy) {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(strat).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
assert_eq!(runtime_api.benchmark_add_one(&block_id, &1).unwrap(), 2);
|
||||
assert_eq!(runtime_api.benchmark_add_one(best_hash, &1).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -57,9 +57,9 @@ fn calling_native_runtime_signature_changed_function() {
|
||||
.set_execution_strategy(ExecutionStrategy::NativeWhenPossible)
|
||||
.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
assert_eq!(runtime_api.function_signature_changed(&block_id).unwrap(), 1);
|
||||
assert_eq!(runtime_api.function_signature_changed(best_hash).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -68,10 +68,10 @@ fn calling_wasm_runtime_signature_changed_old_function() {
|
||||
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
|
||||
.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
#[allow(deprecated)]
|
||||
let res = runtime_api.function_signature_changed_before_version_2(&block_id).unwrap();
|
||||
let res = runtime_api.function_signature_changed_before_version_2(best_hash).unwrap();
|
||||
assert_eq!(&res, &[1, 2]);
|
||||
}
|
||||
|
||||
@@ -79,16 +79,16 @@ fn calling_wasm_runtime_signature_changed_old_function() {
|
||||
fn calling_with_both_strategy_and_fail_on_wasm_should_return_error() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
assert!(runtime_api.fail_on_wasm(&block_id).is_err());
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
assert!(runtime_api.fail_on_wasm(best_hash).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_with_both_strategy_and_fail_on_native_should_work() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
assert_eq!(runtime_api.fail_on_native(best_hash).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -97,8 +97,8 @@ fn calling_with_native_else_wasm_and_fail_on_wasm_should_work() {
|
||||
.set_execution_strategy(ExecutionStrategy::NativeElseWasm)
|
||||
.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
assert_eq!(runtime_api.fail_on_wasm(&block_id).unwrap(), 1);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
assert_eq!(runtime_api.fail_on_wasm(best_hash).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -107,8 +107,8 @@ fn calling_with_native_else_wasm_and_fail_on_native_should_work() {
|
||||
.set_execution_strategy(ExecutionStrategy::NativeElseWasm)
|
||||
.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
assert_eq!(runtime_api.fail_on_native(best_hash).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -117,18 +117,18 @@ fn use_trie_function() {
|
||||
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
|
||||
.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
assert_eq!(runtime_api.use_trie(&block_id).unwrap(), 2);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
assert_eq!(runtime_api.use_trie(best_hash).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn initialize_block_works() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
runtime_api
|
||||
.initialize_block(
|
||||
&block_id,
|
||||
best_hash,
|
||||
&Header::new(
|
||||
1,
|
||||
Default::default(),
|
||||
@@ -138,7 +138,7 @@ fn initialize_block_works() {
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(runtime_api.get_block_number(&block_id).unwrap(), 1);
|
||||
assert_eq!(runtime_api.get_block_number(best_hash).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -205,10 +205,10 @@ fn call_runtime_api_with_multiple_arguments() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
|
||||
let data = vec![1, 2, 4, 5, 6, 7, 8, 8, 10, 12];
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
client
|
||||
.runtime_api()
|
||||
.test_multiple_arguments(&block_id, data.clone(), data.clone(), data.len() as u32)
|
||||
.test_multiple_arguments(best_hash, data.clone(), data.clone(), data.len() as u32)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -225,8 +225,9 @@ fn disable_logging_works() {
|
||||
|
||||
let client = builder.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(0);
|
||||
runtime_api.do_trace_log(&block_id).expect("Logging should not fail");
|
||||
runtime_api
|
||||
.do_trace_log(client.chain_info().genesis_hash)
|
||||
.expect("Logging should not fail");
|
||||
log::error!("Logging from native works");
|
||||
} else {
|
||||
let executable = std::env::current_exe().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user