use light_sdk::{AnchorDiscriminator, LightDiscriminator};
#[derive(LightDiscriminator)]
pub struct LightFormatAccount;
#[derive(AnchorDiscriminator)]
pub struct AnchorFormatAccount;
#[derive(LightDiscriminator)]
pub struct TestAccount;
#[derive(AnchorDiscriminator)]
pub struct TestAccountAnchor;
#[test]
fn test_light_discriminator_format() {
const EXPECTED: [u8; 8] = [249, 48, 95, 140, 134, 45, 33, 195];
assert_eq!(
LightFormatAccount::LIGHT_DISCRIMINATOR,
EXPECTED,
"LightDiscriminator should use SHA256(name) format"
);
}
#[test]
fn test_anchor_discriminator_format() {
const EXPECTED: [u8; 8] = [242, 59, 127, 54, 56, 102, 184, 199];
assert_eq!(
AnchorFormatAccount::LIGHT_DISCRIMINATOR,
EXPECTED,
"AnchorDiscriminator should use SHA256(account:name) format"
);
}
#[test]
fn test_discriminators_are_different() {
let light_discriminator = TestAccount::LIGHT_DISCRIMINATOR;
let anchor_discriminator = TestAccountAnchor::LIGHT_DISCRIMINATOR;
assert_ne!(
light_discriminator, anchor_discriminator,
"Light and Anchor discriminators should produce different values"
);
}
#[test]
fn test_discriminator_trait_methods() {
assert_eq!(
LightFormatAccount::discriminator(),
LightFormatAccount::LIGHT_DISCRIMINATOR,
"discriminator() method should return LIGHT_DISCRIMINATOR constant"
);
assert_eq!(
AnchorFormatAccount::discriminator(),
AnchorFormatAccount::LIGHT_DISCRIMINATOR,
"discriminator() method should return LIGHT_DISCRIMINATOR constant"
);
}
#[test]
fn test_discriminator_slice() {
assert_eq!(
LightFormatAccount::LIGHT_DISCRIMINATOR_SLICE,
&LightFormatAccount::LIGHT_DISCRIMINATOR,
"LIGHT_DISCRIMINATOR_SLICE should be a slice of LIGHT_DISCRIMINATOR"
);
assert_eq!(
AnchorFormatAccount::LIGHT_DISCRIMINATOR_SLICE,
&AnchorFormatAccount::LIGHT_DISCRIMINATOR,
"LIGHT_DISCRIMINATOR_SLICE should be a slice of LIGHT_DISCRIMINATOR"
);
}