add solana_name_id, reassociate names with modules, modularize id tests (#4580)

This commit is contained in:
Rob Walker
2019-06-06 19:27:49 -07:00
committed by GitHub
parent 191483f4ee
commit fd9fd43e83
20 changed files with 199 additions and 194 deletions

View File

@@ -88,6 +88,41 @@ pub fn read_pubkey(infile: &str) -> Result<Pubkey, Box<error::Error>> {
Ok(Pubkey::from_str(&printable)?)
}
#[macro_export]
macro_rules! solana_id(
($id:ident) => (
pub fn check_id(id: &$crate::pubkey::Pubkey) -> bool {
id.as_ref() == $id
}
pub fn id() -> $crate::pubkey::Pubkey {
$crate::pubkey::Pubkey::new(&$id)
}
#[cfg(test)]
#[test]
fn test_id() {
assert!(check_id(&id()));
}
)
);
#[macro_export]
macro_rules! solana_name_id(
($id:ident, $name:expr) => (
$crate::solana_id!($id);
#[cfg(test)]
#[test]
fn test_name_id() {
assert_eq!(id().to_string(), $name);
}
)
);
#[cfg(test)]
mod tests {
use super::*;