Skip to content

Commit

Permalink
SFT-3631: Add integration tests for firmware-image.
Browse files Browse the repository at this point in the history
* firmware/Cargo.toml (dev-dependencies): Add foundation-test-vectors.
* firmware/tests/test-vectors.rs: New tests.
  • Loading branch information
jeandudey committed May 16, 2024
1 parent e4cedb4 commit b1e4f3f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ hex = { workspace = true, optional = true }
nom = { workspace = true }
secp256k1 = { workspace = true }
anyhow = { workspace = true, optional = true }

[dev-dependencies]
foundation-test-vectors = { workspace = true, features = ["firmware"] }
63 changes: 63 additions & 0 deletions firmware/tests/test-vectors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: © 2024 Foundation Devices, Inc. <hello@foundationdevices.com>
// SPDX-License-Identifier: GPL-3.0-or-later

use foundation_firmware::{header, VerifyHeaderError};
use foundation_test_vectors::firmware::{
INVALID_MAGIC, INVALID_MAX_LENGTH, INVALID_MIN_LENGTH, INVALID_PUBLIC_KEY1,
INVALID_PUBLIC_KEY2, INVALID_TIMESTAMP, VALID_HEADER,
};
use nom::Finish;

#[test]
pub fn valid_header() {
let (_, header) = header(VALID_HEADER).finish().unwrap();
header.verify().unwrap();
}

#[test]
pub fn invalid_magic() {
let (_, header) = header(INVALID_MAGIC).finish().unwrap();
assert_eq!(header.verify(), Err(VerifyHeaderError::UnknownMagic(0)));
}

#[test]
pub fn invalid_min_length() {
let (_, header) = header(INVALID_MIN_LENGTH).finish().unwrap();
assert_eq!(
header.verify(),
Err(VerifyHeaderError::FirmwareTooSmall(2047))
);
}

#[test]
pub fn invalid_max_length() {
let (_, header) = header(INVALID_MAX_LENGTH).finish().unwrap();
assert_eq!(
header.verify(),
Err(VerifyHeaderError::FirmwareTooBig(1834753))
);
}

#[test]
pub fn invalid_public_key1() {
let (_, header) = header(INVALID_PUBLIC_KEY1).finish().unwrap();
assert_eq!(
header.verify(),
Err(VerifyHeaderError::InvalidPublicKey1Index(5))
);
}

#[test]
pub fn invalid_public_key2() {
let (_, header) = header(INVALID_PUBLIC_KEY2).finish().unwrap();
assert_eq!(
header.verify(),
Err(VerifyHeaderError::InvalidPublicKey2Index(5))
);
}

#[test]
pub fn invalid_timestamp() {
let (_, header) = header(INVALID_TIMESTAMP).finish().unwrap();
assert_eq!(header.verify(), Err(VerifyHeaderError::InvalidTimestamp));
}

0 comments on commit b1e4f3f

Please sign in to comment.