|
| 1 | +#![no_std] |
| 2 | + |
| 3 | +use subxt_signer::{ecdsa, eth, sr25519}; |
| 4 | + |
| 5 | +// Run the tests by calling: |
| 6 | +// |
| 7 | +// ```text |
| 8 | +// cargo test |
| 9 | +// ``` |
| 10 | +// |
| 11 | +// These are independent of any other package to ensure that nothing |
| 12 | +// else enabled the same feature flag that subxt-signer needs to work ok |
| 13 | +// (subxt seems to, for instance). |
| 14 | + |
| 15 | +#[test] |
| 16 | +fn sr25519_signing_works() { |
| 17 | + let alice = sr25519::dev::alice(); |
| 18 | + |
| 19 | + // There's some non-determinism in the signing, so this ensures that |
| 20 | + // the rand stuff is configured properly to run ok in wasm. |
| 21 | + let signature = alice.sign(b"Hello there"); |
| 22 | + assert!(sr25519::verify( |
| 23 | + &signature, |
| 24 | + b"Hello there", |
| 25 | + &alice.public_key() |
| 26 | + )); |
| 27 | +} |
| 28 | + |
| 29 | +#[test] |
| 30 | +fn ecdsa_signing_works() { |
| 31 | + let alice = ecdsa::dev::alice(); |
| 32 | + |
| 33 | + // There's some non-determinism in the signing, so this ensures that |
| 34 | + // the rand stuff is configured properly to run ok in wasm. |
| 35 | + let signature = alice.sign(b"Hello there"); |
| 36 | + assert!(ecdsa::verify( |
| 37 | + &signature, |
| 38 | + b"Hello there", |
| 39 | + &alice.public_key() |
| 40 | + )); |
| 41 | +} |
| 42 | + |
| 43 | +#[test] |
| 44 | +fn eth_signing_works() { |
| 45 | + let alice = eth::dev::alith(); |
| 46 | + |
| 47 | + // There's some non-determinism in the signing, so this ensures that |
| 48 | + // the rand stuff is configured properly to run ok in wasm. |
| 49 | + let signature = alice.sign(b"Hello there"); |
| 50 | + assert!(eth::verify(&signature, b"Hello there", &alice.public_key())); |
| 51 | +} |
0 commit comments