descro resolvers extension
This commit is contained in:
83
programs/descro_ext_resolvers/tests/test_update.rs
Normal file
83
programs/descro_ext_resolvers/tests/test_update.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
mod common;
|
||||
use common::*;
|
||||
use descro_ext_resolvers::ResolverType;
|
||||
use solana_keypair::Keypair;
|
||||
use solana_signer::Signer;
|
||||
|
||||
fn register_default(svm: &mut litesvm::LiteSVM, authority: &Keypair) {
|
||||
send(
|
||||
svm,
|
||||
ix_register(
|
||||
&authority.pubkey(),
|
||||
ResolverType::CentralAuthority,
|
||||
"Original Name",
|
||||
"Original description",
|
||||
100,
|
||||
authority.pubkey(),
|
||||
"ipfs://original",
|
||||
),
|
||||
authority,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_changes_metadata() {
|
||||
let (mut svm, authority) = setup();
|
||||
register_default(&mut svm, &authority);
|
||||
|
||||
send(
|
||||
&mut svm,
|
||||
ix_update(&authority.pubkey(), "New Name", "New description", 200, "ipfs://new"),
|
||||
&authority,
|
||||
);
|
||||
|
||||
let entry = read_entry(&svm, &authority.pubkey());
|
||||
assert_eq!(entry.name, "New Name");
|
||||
assert_eq!(entry.description, "New description");
|
||||
assert_eq!(entry.fee_bps, 200);
|
||||
assert_eq!(entry.metadata_uri, "ipfs://new");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_different_authority_cannot_modify_entry() {
|
||||
let (mut svm, authority) = setup();
|
||||
let other = Keypair::new();
|
||||
svm.airdrop(&other.pubkey(), 1_000_000_000).unwrap();
|
||||
register_default(&mut svm, &authority);
|
||||
|
||||
// `other` signs but claims to BE the authority → seeds derive other's (non-existent) PDA
|
||||
// → account has no data → Anchor rejects the uninitialized account
|
||||
assert!(!try_send(
|
||||
&mut svm,
|
||||
ix_update(&other.pubkey(), "Hacked", "", 0, ""),
|
||||
&other,
|
||||
));
|
||||
|
||||
// `authority`'s entry is unchanged
|
||||
let entry = read_entry(&svm, &authority.pubkey());
|
||||
assert_eq!(entry.name, "Original Name");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_empty_name_fails() {
|
||||
let (mut svm, authority) = setup();
|
||||
register_default(&mut svm, &authority);
|
||||
|
||||
assert!(!try_send(
|
||||
&mut svm,
|
||||
ix_update(&authority.pubkey(), "", "", 0, ""),
|
||||
&authority,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_invalid_fee_bps_fails() {
|
||||
let (mut svm, authority) = setup();
|
||||
register_default(&mut svm, &authority);
|
||||
|
||||
assert!(!try_send(
|
||||
&mut svm,
|
||||
ix_update(&authority.pubkey(), "Name", "", 10_001, ""),
|
||||
&authority,
|
||||
));
|
||||
}
|
||||
Reference in New Issue
Block a user