Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit 662bd92

Browse files
committed
add: delete post
1 parent b592810 commit 662bd92

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

programs/wordcel/src/instructions.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,35 @@ pub struct UpdatePost<'info> {
9090
pub system_program: Program<'info, System>,
9191
}
9292

93+
#[derive(Accounts)]
94+
pub struct ClosePost<'info> {
95+
#[account(
96+
has_one = authority,
97+
seeds = [
98+
b"profile".as_ref(),
99+
&profile.random_hash
100+
],
101+
bump = profile.bump
102+
)]
103+
// Checks if the original profile was supplied and if the profile authority is the signer
104+
pub profile: Account<'info, Profile>,
105+
#[account(
106+
mut,
107+
has_one = profile,
108+
seeds = [
109+
b"post".as_ref(),
110+
&post.random_hash
111+
],
112+
bump = post.bump,
113+
close = authority
114+
)]
115+
// Checks if a post was supplied and it is part of the supplied profile.
116+
pub post: Account<'info, Post>,
117+
#[account(mut)]
118+
pub authority: Signer<'info>,
119+
pub system_program: Program<'info, System>,
120+
}
121+
93122
#[derive(Accounts)]
94123
#[instruction(metadata_uri: String, random_hash: [u8;32])]
95124
pub struct Comment<'info> {

programs/wordcel/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ pub mod wordcel {
5353
Ok(())
5454
}
5555

56+
pub fn close_post(_ctx: Context<ClosePost>) -> Result<()> {
57+
Ok(())
58+
}
59+
5660
pub fn comment(
5761
ctx: Context<Comment>,
5862
metadata_uri: String,

tests/wordcel.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as anchor from '@project-serum/anchor';
22
import {Program} from '@project-serum/anchor';
33
import {Wordcel} from '../target/types/wordcel';
44
import {expect} from 'chai';
5-
import {PublicKey} from '@solana/web3.js';
5+
import {PublicKey, Keypair} from '@solana/web3.js';
66
import randombytes from 'randombytes';
77
import {getInviteAccount, invitationProgram} from './utils/invite';
88
import {airdrop} from './utils';
@@ -118,7 +118,22 @@ describe('wordcel', async () => {
118118
}).rpc();
119119
const post = await program.account.post.fetch(postAccount);
120120
expect(post.metadataUri).to.equal(metadataUri);
121-
onePostAccount = postAccount;
121+
});
122+
123+
it("should delete a post", async () => {
124+
await program.methods.closePost().accounts({
125+
post: onePostAccount,
126+
profile: profileAccount,
127+
authority: user,
128+
systemProgram: SystemProgram.programId,
129+
}).rpc();
130+
try {
131+
await program.account.post.fetch(onePostAccount);
132+
133+
} catch (error) {
134+
expect(error).to.be.an('error');
135+
expect(error.toString()).to.contain('Error: Account does not exist');
136+
}
122137
});
123138
});
124139

0 commit comments

Comments
 (0)