Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions programs/wordcel/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
4 changes: 4 additions & 0 deletions programs/wordcel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ pub mod wordcel {
Ok(())
}

pub fn close_post(_ctx: Context<ClosePost>) -> Result<()> {
Ok(())
}

pub fn comment(
ctx: Context<Comment>,
metadata_uri: String,
Expand Down
19 changes: 18 additions & 1 deletion tests/wordcel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
});
});

Expand Down