From fef464f8ccf4bbbe4578c964c661d29488a42280 Mon Sep 17 00:00:00 2001 From: abishekk92 Date: Tue, 12 Jul 2022 20:08:22 +0530 Subject: [PATCH] add: delete post --- programs/wordcel/src/instructions.rs | 29 ++++++++++++++++++++++++++++ programs/wordcel/src/lib.rs | 4 ++++ tests/wordcel.spec.ts | 19 +++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/programs/wordcel/src/instructions.rs b/programs/wordcel/src/instructions.rs index f168810..e8bcef0 100644 --- a/programs/wordcel/src/instructions.rs +++ b/programs/wordcel/src/instructions.rs @@ -90,6 +90,35 @@ pub struct UpdatePost<'info> { pub system_program: Program<'info, System>, } +#[derive(Accounts)] +pub struct ClosePost<'info> { + #[account( + has_one = authority, + seeds = [ + b"profile".as_ref(), + &profile.random_hash + ], + bump = profile.bump + )] + // Checks if the original profile was supplied and if the profile authority is the signer + pub profile: Account<'info, Profile>, + #[account( + mut, + has_one = profile, + seeds = [ + b"post".as_ref(), + &post.random_hash + ], + bump = post.bump, + close = authority + )] + // Checks if a post was supplied and it is part of the supplied profile. + pub post: Account<'info, Post>, + #[account(mut)] + pub authority: Signer<'info>, + pub system_program: Program<'info, System>, +} + #[derive(Accounts)] #[instruction(metadata_uri: String, random_hash: [u8;32])] pub struct Comment<'info> { diff --git a/programs/wordcel/src/lib.rs b/programs/wordcel/src/lib.rs index 1584ee9..c77891f 100644 --- a/programs/wordcel/src/lib.rs +++ b/programs/wordcel/src/lib.rs @@ -65,6 +65,10 @@ pub mod wordcel { Ok(()) } + pub fn close_post(_ctx: Context) -> Result<()> { + Ok(()) + } + pub fn comment( ctx: Context, metadata_uri: String, diff --git a/tests/wordcel.spec.ts b/tests/wordcel.spec.ts index bef1ee8..b71d00d 100644 --- a/tests/wordcel.spec.ts +++ b/tests/wordcel.spec.ts @@ -165,7 +165,24 @@ describe("wordcel", async () => { .rpc(); const post = await program.account.post.fetch(postAccount); expect(post.metadataUri).to.equal(metadataUri); - onePostAccount = postAccount; + }); + + it("should delete a post", async () => { + await program.methods + .closePost() + .accounts({ + post: onePostAccount, + profile: profileAccount, + authority: user, + systemProgram: SystemProgram.programId, + }) + .rpc(); + try { + await program.account.post.fetch(onePostAccount); + } catch (error) { + expect(error).to.be.an("error"); + expect(error.toString()).to.contain("Error: Account does not exist"); + } }); });