Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crypto][test] Backwards compatibility test for address generation #1628

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion sui_types/src/unit_tests/base_types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![allow(clippy::blacklisted_name)]
use super::*;
use crate::crypto::AuthoritySignature;
use crate::crypto::{get_key_pair_from_bytes, AuthoritySignature, KeyPair};

use move_binary_format::file_format;

Expand Down Expand Up @@ -309,3 +309,34 @@ fn test_move_package_size_for_gas_metering() {
// Make sure to adjust `object_size_for_gas_metering()` to include those changes.
assert_eq!(size + 5, serialized.len());
}

// A sample address in hex generated by the current address derivation algorithm.
#[cfg(test)]
const SAMPLE_ADDRESS: &str = "ee0437cf625b77af4d12bff98af1a88332b00638";

// Derive a sample address and public key tuple from KeyPair bytes.
fn derive_sample_address() -> (SuiAddress, KeyPair) {
let (address, pub_key) = get_key_pair_from_bytes(&[
10, 112, 5, 142, 174, 127, 187, 146, 251, 68, 22, 191, 128, 68, 84, 13, 102, 71, 77, 57,
92, 154, 128, 240, 158, 45, 13, 123, 57, 21, 194, 214, 189, 215, 127, 86, 129, 189, 1, 4,
90, 106, 17, 10, 123, 200, 40, 18, 34, 173, 240, 91, 213, 72, 183, 249, 213, 210, 39, 181,
105, 254, 59, 163,
]);
(address, pub_key)
}

// Required to capture address derivation algorithm updates that break some tests and deployments.
#[test]
fn test_address_backwards_compatibility() {
use hex;
let (address, _) = derive_sample_address();
assert_eq!(
address.to_vec(),
hex::decode(SAMPLE_ADDRESS).expect("Decoding failed"),
"If this test broke, then the algorithm for deriving addresses from public keys has \
changed. If this was intentional, please compute a new sample address in hex format \
from `derive_sample_address` and update the SAMPLE_ADDRESS const above with the new \
derived address hex value. Note that existing deployments (i.e. devnet) might \
also require updates if they use fixed values generated by the old algorithm."
);
}