mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Unify bad signature error (#1717)
* Unify bad signature message. * Update runtime.
This commit is contained in:
@@ -94,7 +94,7 @@ where
|
||||
let payload = (index, self.function);
|
||||
let signed = context.lookup(signed)?;
|
||||
if !crate::verify_encoded_lazy(&signature, &payload, &signed) {
|
||||
return Err("bad signature in extrinsic")
|
||||
return Err(crate::BAD_SIGNATURE)
|
||||
}
|
||||
CheckedExtrinsic {
|
||||
signed: Some((signed, payload.0)),
|
||||
|
||||
@@ -95,7 +95,7 @@ where
|
||||
signature.verify(payload, &signed)
|
||||
}
|
||||
}) {
|
||||
return Err("bad signature in extrinsic")
|
||||
return Err(crate::BAD_SIGNATURE)
|
||||
}
|
||||
CheckedExtrinsic {
|
||||
signed: Some((signed, (raw_payload.0).0)),
|
||||
@@ -255,7 +255,7 @@ mod tests {
|
||||
fn badly_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, vec![0u8;0], DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, vec![0u8]), Era::immortal());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err(crate::BAD_SIGNATURE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -283,14 +283,14 @@ mod tests {
|
||||
fn too_late_mortal_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, vec![0u8;0], DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, vec![0u8;0], Era::mortal(32, 10), 10u64).encode()), Era::mortal(32, 10));
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err(crate::BAD_SIGNATURE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn too_early_mortal_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, vec![0u8;0], DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, vec![0u8;0], Era::mortal(32, 43), 43u64).encode()), Era::mortal(32, 43));
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err(crate::BAD_SIGNATURE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -95,7 +95,7 @@ where
|
||||
signature.verify(payload, &signed)
|
||||
}
|
||||
}) {
|
||||
return Err("bad signature in extrinsic")
|
||||
return Err(crate::BAD_SIGNATURE)
|
||||
}
|
||||
CheckedExtrinsic {
|
||||
signed: Some((signed, raw_payload.0)),
|
||||
@@ -254,7 +254,7 @@ mod tests {
|
||||
fn badly_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, vec![0u8;0], DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, vec![0u8]), Era::immortal());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err(crate::BAD_SIGNATURE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -282,14 +282,14 @@ mod tests {
|
||||
fn too_late_mortal_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, vec![0u8;0], DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, vec![0u8;0], Era::mortal(32, 10), 10u64).encode()), Era::mortal(32, 10));
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err(crate::BAD_SIGNATURE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn too_early_mortal_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, vec![0u8;0], DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, vec![0u8;0], Era::mortal(32, 43), 43u64).encode()), Era::mortal(32, 43));
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err(crate::BAD_SIGNATURE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -43,6 +43,9 @@ pub mod traits;
|
||||
pub mod generic;
|
||||
pub mod transaction_validity;
|
||||
|
||||
/// A message indicating an invalid signature in extrinsic.
|
||||
pub const BAD_SIGNATURE: &str = "bad signature in extrinsic";
|
||||
|
||||
/// Full block error message.
|
||||
///
|
||||
/// This allows modules to indicate that given transaction is potentially valid
|
||||
|
||||
@@ -104,10 +104,10 @@ impl BlindCheckable for Extrinsic {
|
||||
match self {
|
||||
Extrinsic::AuthoritiesChange(new_auth) => Ok(Extrinsic::AuthoritiesChange(new_auth)),
|
||||
Extrinsic::Transfer(transfer, signature) => {
|
||||
if ::runtime_primitives::verify_encoded_lazy(&signature, &transfer, &transfer.from) {
|
||||
if runtime_primitives::verify_encoded_lazy(&signature, &transfer, &transfer.from) {
|
||||
Ok(Extrinsic::Transfer(transfer, signature))
|
||||
} else {
|
||||
Err("bad signature")
|
||||
Err(runtime_primitives::BAD_SIGNATURE)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -254,7 +254,7 @@ impl<
|
||||
Err("invalid account index") => return TransactionValidity::Unknown(INVALID_INDEX),
|
||||
// Technically a bad signature could also imply an out-of-date account index, but
|
||||
// that's more of an edge case.
|
||||
Err("bad signature") => return TransactionValidity::Invalid(ApplyError::BadSignature as i8),
|
||||
Err(primitives::BAD_SIGNATURE) => return TransactionValidity::Invalid(ApplyError::BadSignature as i8),
|
||||
Err(_) => return TransactionValidity::Invalid(UNKNOWN_ERROR),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user