Update schnorrkel with versioning (#5358)

* use versioning for deprecated api, remove deprecated api from regular verification

* Update primitives/core/src/sr25519.rs

* add test to transaction pool

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Nikolay Volf
2020-03-24 10:05:57 -07:00
committed by GitHub
parent 6beb6acbd5
commit 27fe4206ed
5 changed files with 81 additions and 19 deletions
@@ -20,15 +20,16 @@ use futures::executor::block_on;
use txpool::{self, Pool};
use sp_runtime::{
generic::BlockId,
transaction_validity::ValidTransaction,
transaction_validity::{ValidTransaction, InvalidTransaction},
};
use substrate_test_runtime_client::{
runtime::{Block, Hash, Index, Header, Extrinsic},
runtime::{Block, Hash, Index, Header, Extrinsic, Transfer},
AccountKeyring::*,
};
use substrate_test_runtime_transaction_pool::{TestApi, uxt};
use crate::revalidation::BACKGROUND_REVALIDATION_INTERVAL;
use futures::task::Poll;
use codec::Encode;
fn pool() -> Pool<TestApi> {
Pool::new(Default::default(), TestApi::with_alice_nonce(209).into())
@@ -653,4 +654,37 @@ fn ready_set_should_eventually_resolve_when_block_update_arrives() {
assert_eq!(data.len(), 1);
}
}
}
}
#[test]
fn should_not_accept_old_signatures() {
use std::convert::TryFrom;
let client = Arc::new(substrate_test_runtime_client::new());
let pool = Arc::new(
BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client))).0
);
let transfer = Transfer {
from: Alice.into(),
to: Bob.into(),
nonce: 0,
amount: 1,
};
let _bytes: sp_core::sr25519::Signature = transfer.using_encoded(|e| Alice.sign(e)).into();
// generated with schnorrkel 0.1.1 from `_bytes`
let old_singature = sp_core::sr25519::Signature::try_from(&hex::decode(
"c427eb672e8c441c86d31f1a81b22b43102058e9ce237cabe9897ea5099ffd426cd1c6a1f4f2869c3df57901d36bedcb295657adb3a4355add86ed234eb83108"
).expect("hex invalid")[..]).expect("signature construction failed");
let xt = Extrinsic::Transfer { transfer, signature: old_singature, exhaust_resources_when_not_first: false };
assert_matches::assert_matches!(
block_on(pool.submit_one(&BlockId::number(0), xt.clone())),
Err(error::Error::Pool(
sp_transaction_pool::error::Error::InvalidTransaction(InvalidTransaction::BadProof)
)),
"Should be invalid transactiono with bad proof",
);
}