Merge pull request #1 from steveklabnik/master

Fix unused imports and add a gitignore
This commit is contained in:
Dawid Ciężarkiewicz 2014-08-04 17:04:33 -07:00
commit 2c2a98a153
2 changed files with 125 additions and 118 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
Cargo.lock

View File

@ -4,14 +4,12 @@
#![crate_name = "bitcoin-secp256k1-rs"]
#![comment = "Bindings and wrapper functions for bitcoin secp256k1 library."]
#![feature(phase)]
#![feature(globs)] // for tests only
extern crate libc;
extern crate sync;
use std::rand;
use std::rand::Rng;
use libc::{c_int, c_uchar};
use sync::one::{Once, ONCE_INIT};
@ -252,8 +250,16 @@ impl Secp256k1 {
}
}
#[test]
fn invalid_pubkey() {
#[cfg(test)]
mod test {
use std::rand;
use std::rand::Rng;
use super::*;
#[test]
fn invalid_pubkey() {
let s = Secp256k1::new();
let mut msg = Vec::from_elem(32, 0u8);
@ -263,10 +269,10 @@ fn invalid_pubkey() {
rand::task_rng().fill_bytes(msg.as_mut_slice());
assert_eq!(s.verify(msg.as_mut_slice(), sig.as_slice(), &pubkey), Err(InvalidPublicKey));
}
}
#[test]
fn valid_pubkey_uncompressed() {
#[test]
fn valid_pubkey_uncompressed() {
let s = Secp256k1::new();
let seckey = [0u8, ..32];
@ -278,10 +284,10 @@ fn valid_pubkey_uncompressed() {
rand::task_rng().fill_bytes(msg.as_mut_slice());
assert_eq!(s.verify(msg.as_mut_slice(), sig.as_slice(), &pubkey), Err(InvalidSignature));
}
}
#[test]
fn valid_pubkey_compressed() {
#[test]
fn valid_pubkey_compressed() {
let s = Secp256k1::new();
let seckey = [0u8, ..32];
@ -293,10 +299,10 @@ fn valid_pubkey_compressed() {
rand::task_rng().fill_bytes(msg.as_mut_slice());
assert_eq!(s.verify(msg.as_mut_slice(), sig.as_slice(), &pubkey), Err(InvalidSignature));
}
}
#[test]
fn sign() {
#[test]
fn sign() {
let s = Secp256k1::new();
let mut msg = [0u8, ..32];
@ -308,10 +314,10 @@ fn sign() {
rand::task_rng().fill_bytes(seckey);
s.sign(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
}
}
#[test]
fn sign_and_verify() {
#[test]
fn sign_and_verify() {
let s = Secp256k1::new();
let mut msg = Vec::from_elem(32, 0u8);
@ -328,10 +334,10 @@ fn sign_and_verify() {
s.sign(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
assert_eq!(s.verify(msg.as_slice(), sig.as_slice(), &pubkey), Ok(true));
}
}
#[test]
fn sign_and_verify_fail() {
#[test]
fn sign_and_verify_fail() {
let s = Secp256k1::new();
let mut msg = Vec::from_elem(32, 0u8);
@ -348,10 +354,10 @@ fn sign_and_verify_fail() {
rand::task_rng().fill_bytes(msg.as_mut_slice());
assert_eq!(s.verify(msg.as_slice(), sig.as_slice(), &pubkey), Ok(false));
}
}
#[test]
fn sign_compact_with_recovery() {
#[test]
fn sign_compact_with_recovery() {
let s = Secp256k1::new();
let mut msg = [0u8, ..32];
@ -368,6 +374,5 @@ fn sign_compact_with_recovery() {
let recid = s.sign_compact(sig.as_mut_slice(), msg.as_slice(), &seckey, &nonce).unwrap();
assert_eq!(s.recover_compact(msg.as_slice(), sig.as_slice(), &mut pubkey, recid), Ok(()));
}
}