From cd0d2fd791f9a71bfe9f62e253cf3ef6f2816804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 4 Feb 2020 12:39:56 +0100 Subject: [PATCH] Fix flaky messed signature test (#4819) When messing with the signature, we need to make sure that we acutally mess-up the signature. As the generated private/public key is random, the signature is random as well. It can happen that `bytes[0] == bytes[2]` which makes the test fail. We fix this problem by just inverting the bytes at `0` and `2`. --- substrate/primitives/core/src/sr25519.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/primitives/core/src/sr25519.rs b/substrate/primitives/core/src/sr25519.rs index d98aa19e1d..3495f32872 100644 --- a/substrate/primitives/core/src/sr25519.rs +++ b/substrate/primitives/core/src/sr25519.rs @@ -735,7 +735,8 @@ mod test { let public = pair.public(); let message = b"Signed payload"; let Signature(mut bytes) = pair.sign(&message[..]); - bytes[0] = bytes[2]; + bytes[0] = !bytes[0]; + bytes[2] = !bytes[2]; let signature = Signature(bytes); assert!(!Pair::verify(&signature, &message[..], &public)); }