|
@@ -48,6 +48,31 @@ pub mod declare_program {
|
|
|
|
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ pub fn event_utils(_ctx: Context<Utils>) -> Result<()> {
|
|
|
|
+ use external::utils::Event;
|
|
|
|
+
|
|
|
|
+ // Empty
|
|
|
|
+ if Event::try_from_bytes(&[]).is_ok() {
|
|
|
|
+ return Err(ProgramError::Custom(0).into());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const DISC: &[u8] =
|
|
|
|
+ &<external::events::MyEvent as anchor_lang::Discriminator>::DISCRIMINATOR;
|
|
|
|
+
|
|
|
|
+ // Correct discriminator but invalid data
|
|
|
|
+ if Event::try_from_bytes(DISC).is_ok() {
|
|
|
|
+ return Err(ProgramError::Custom(1).into());
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // Correct discriminator and valid data
|
|
|
|
+ match Event::try_from_bytes(&[DISC, &[1, 0, 0, 0]].concat()) {
|
|
|
|
+ Ok(Event::MyEvent(my_event)) => require_eq!(my_event.value, 1),
|
|
|
|
+ Err(e) => return Err(e.into()),
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Ok(())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#[derive(Accounts)]
|
|
#[derive(Accounts)]
|
|
@@ -57,3 +82,8 @@ pub struct Cpi<'info> {
|
|
pub cpi_my_account: Account<'info, external::accounts::MyAccount>,
|
|
pub cpi_my_account: Account<'info, external::accounts::MyAccount>,
|
|
pub external_program: Program<'info, External>,
|
|
pub external_program: Program<'info, External>,
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+#[derive(Accounts)]
|
|
|
|
+pub struct Utils<'info> {
|
|
|
|
+ pub authority: Signer<'info>,
|
|
|
|
+}
|