mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 18:57:57 +00:00
Make substrate generic (#169)
* Some initial work on RPC and client * Rephrase as params * More work on traitifying substrate. * Traitify in_mem.rs * traitify client.rs * Make new primitives (mainly traits) build again. * Many (superficial) build fixes throughout. * Fix remaining build issues up to bft interface. * Make bft primitives be generic. * Switch out MisBehaviorReport for generic version. * Merge Hashing into Header. * Update runtime for new generics (with Hashing). * Update demo runtime. * Make runtime compile. * Build fixes for runtime * Remove old modules. * port substrate-bft to use generic substrate types * port client * port substrate-test-runtime * mostly port test-runtime to get compiling for std * Ensure `AccountId` has a `Default`. * Fix type deps. * finish porting * initialize test_runtime from genesis correctly * remove commented code * maybe unsigned signatures * runtimes compile * port over most of network * serialization for generic types * fix comment * remove some unnecessary trait bounds * network compiles * tests compile for sync * fix deserialization * temporarily remove deserialize derives * workarounds for serde issues for deriving deserialization * get demo-runtime compiling on std * port extrinsic-pool * primitives reshuffling * get network compiling again * remove debugging file * runtime tests now passing * port client-db * start to port over substrate-rpc * mostly port over PolkadotApi * test_runtime follows normal conventions * substrate runtime tests pass * deal with inherent extrinsics correctly in polkadot-api * port transaction-pool * port polkadot-consensus * port substrate-rpc * everything compiles * tests compile * fix grumbles * test-runtime uses its own transfer type * switch to master branch of jsonrpc * fix network tests and some warnings * all tests pass locally * [ci-skip] add another comment about issue * remove some curlies
This commit is contained in:
committed by
Robert Habermeier
parent
4e844760a3
commit
b94cf078af
@@ -42,7 +42,7 @@ mod tests {
|
||||
use super::Executor;
|
||||
use substrate_executor::WasmExecutor;
|
||||
use codec::{Slicable, Joiner};
|
||||
use keyring::Keyring::{self, Alice, Bob};
|
||||
use keyring::Keyring;
|
||||
use runtime_support::{Hashable, StorageValue, StorageMap};
|
||||
use state_machine::{CodeExecutor, TestExternalities};
|
||||
use primitives::twox_128;
|
||||
@@ -63,13 +63,21 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
fn alice() -> Hash {
|
||||
Keyring::Alice.to_raw_public().into()
|
||||
}
|
||||
|
||||
fn bob() -> Hash {
|
||||
Keyring::Bob.to_raw_public().into()
|
||||
}
|
||||
|
||||
fn xt() -> UncheckedExtrinsic {
|
||||
let extrinsic = Extrinsic {
|
||||
signed: Alice.into(),
|
||||
signed: alice(),
|
||||
index: 0,
|
||||
function: Call::Staking(staking::Call::transfer::<Concrete>(Bob.into(), 69)),
|
||||
function: Call::Staking(staking::Call::transfer::<Concrete>(bob(), 69)),
|
||||
};
|
||||
let signature = Keyring::from_raw_public(extrinsic.signed).unwrap()
|
||||
let signature = Keyring::from_raw_public(extrinsic.signed.0).unwrap()
|
||||
.sign(&extrinsic.encode()).into();
|
||||
|
||||
UncheckedExtrinsic { extrinsic, signature }
|
||||
@@ -82,7 +90,7 @@ mod tests {
|
||||
#[test]
|
||||
fn panic_execution_with_foreign_code_gives_error() {
|
||||
let mut t: TestExternalities = map![
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
|
||||
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
|
||||
@@ -97,7 +105,7 @@ mod tests {
|
||||
#[test]
|
||||
fn panic_execution_with_native_equivalent_code_gives_error() {
|
||||
let mut t: TestExternalities = map![
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
|
||||
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
|
||||
@@ -112,7 +120,7 @@ mod tests {
|
||||
#[test]
|
||||
fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
let mut t: TestExternalities = map![
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
|
||||
@@ -124,15 +132,15 @@ mod tests {
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
assert_eq!(Staking::balance(&Alice), 42);
|
||||
assert_eq!(Staking::balance(&Bob), 69);
|
||||
assert_eq!(Staking::balance(&alice()), 42);
|
||||
assert_eq!(Staking::balance(&bob()), 69);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn successful_execution_with_foreign_code_gives_ok() {
|
||||
let mut t: TestExternalities = map![
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
|
||||
@@ -144,26 +152,26 @@ mod tests {
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
assert_eq!(Staking::balance(&Alice), 42);
|
||||
assert_eq!(Staking::balance(&Bob), 69);
|
||||
assert_eq!(Staking::balance(&alice()), 42);
|
||||
assert_eq!(Staking::balance(&bob()), 69);
|
||||
});
|
||||
}
|
||||
|
||||
fn new_test_ext() -> TestExternalities {
|
||||
use keyring::Keyring::*;
|
||||
let three = [3u8; 32];
|
||||
let three = [3u8; 32].into();
|
||||
GenesisConfig {
|
||||
consensus: Some(Default::default()),
|
||||
system: Some(Default::default()),
|
||||
session: Some(SessionConfig {
|
||||
session_length: 2,
|
||||
validators: vec![One.into(), Two.into(), three],
|
||||
validators: vec![One.to_raw_public().into(), Two.to_raw_public().into(), three],
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
sessions_per_era: 2,
|
||||
current_era: 0,
|
||||
balances: vec![(Alice.into(), 111)],
|
||||
intentions: vec![Alice.into(), Bob.into(), Charlie.into()],
|
||||
balances: vec![(alice(), 111)],
|
||||
intentions: vec![alice(), bob(), Charlie.to_raw_public().into()],
|
||||
validator_count: 3,
|
||||
bonding_duration: 0,
|
||||
transaction_base_fee: 1,
|
||||
@@ -178,7 +186,7 @@ mod tests {
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
let extrinsics = extrinsics.into_iter().map(|extrinsic| {
|
||||
let signature = Pair::from(Keyring::from_public(Public::from_raw(extrinsic.signed)).unwrap())
|
||||
let signature = Pair::from(Keyring::from_public(Public::from_raw(extrinsic.signed.0)).unwrap())
|
||||
.sign(&extrinsic.encode()).into();
|
||||
|
||||
UncheckedExtrinsic { extrinsic, signature }
|
||||
@@ -204,9 +212,9 @@ mod tests {
|
||||
[69u8; 32].into(),
|
||||
hex!("76b0393b4958d3cb98bb51d9f4edb316af48485142b8721e94c3b52c75ec3243").into(),
|
||||
vec![Extrinsic {
|
||||
signed: Alice.into(),
|
||||
signed: alice(),
|
||||
index: 0,
|
||||
function: Call::Staking(staking::Call::transfer(Bob.into(), 69)),
|
||||
function: Call::Staking(staking::Call::transfer(bob(), 69)),
|
||||
}]
|
||||
)
|
||||
}
|
||||
@@ -218,14 +226,14 @@ mod tests {
|
||||
hex!("8ae9828a5988459d35fb428086170dead660176ee0766e89bc1a4b48153d4e88").into(),
|
||||
vec![
|
||||
Extrinsic {
|
||||
signed: Bob.into(),
|
||||
signed: bob(),
|
||||
index: 0,
|
||||
function: Call::Staking(staking::Call::transfer(Alice.into(), 5)),
|
||||
function: Call::Staking(staking::Call::transfer(alice(), 5)),
|
||||
},
|
||||
Extrinsic {
|
||||
signed: Alice.into(),
|
||||
signed: alice(),
|
||||
index: 1,
|
||||
function: Call::Staking(staking::Call::transfer(Bob.into(), 15)),
|
||||
function: Call::Staking(staking::Call::transfer(bob(), 15)),
|
||||
}
|
||||
]
|
||||
)
|
||||
@@ -238,15 +246,15 @@ mod tests {
|
||||
Executor::new().call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap();
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
assert_eq!(Staking::balance(&Alice), 41);
|
||||
assert_eq!(Staking::balance(&Bob), 69);
|
||||
assert_eq!(Staking::balance(&alice()), 41);
|
||||
assert_eq!(Staking::balance(&bob()), 69);
|
||||
});
|
||||
|
||||
Executor::new().call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap();
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
assert_eq!(Staking::balance(&Alice), 30);
|
||||
assert_eq!(Staking::balance(&Bob), 78);
|
||||
assert_eq!(Staking::balance(&alice()), 30);
|
||||
assert_eq!(Staking::balance(&bob()), 78);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -257,22 +265,22 @@ mod tests {
|
||||
WasmExecutor.call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap();
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
assert_eq!(Staking::balance(&Alice), 41);
|
||||
assert_eq!(Staking::balance(&Bob), 69);
|
||||
assert_eq!(Staking::balance(&alice()), 41);
|
||||
assert_eq!(Staking::balance(&bob()), 69);
|
||||
});
|
||||
|
||||
WasmExecutor.call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap();
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
assert_eq!(Staking::balance(&Alice), 30);
|
||||
assert_eq!(Staking::balance(&Bob), 78);
|
||||
assert_eq!(Staking::balance(&alice()), 30);
|
||||
assert_eq!(Staking::balance(&bob()), 78);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_execution_gives_error() {
|
||||
let mut t: TestExternalities = map![
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
|
||||
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
|
||||
@@ -288,7 +296,7 @@ mod tests {
|
||||
#[test]
|
||||
fn successful_execution_gives_ok() {
|
||||
let mut t: TestExternalities = map![
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
|
||||
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
|
||||
@@ -301,8 +309,8 @@ mod tests {
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
assert_eq!(Staking::balance(&Alice), 42);
|
||||
assert_eq!(Staking::balance(&Bob), 69);
|
||||
assert_eq!(Staking::balance(&alice()), 42);
|
||||
assert_eq!(Staking::balance(&bob()), 69);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user