Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and test cases #11

Open
wants to merge 2 commits into
base: solution-add-comments
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions programs/anchor-movie-review-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ pub mod anchor_movie_review_program {
movie_comment.review = ctx.accounts.movie_review.key();
movie_comment.commenter = ctx.accounts.initializer.key();
movie_comment.comment = comment;
movie_comment.count = movie_comment_counter.counter;

movie_comment_counter.counter += 1;
movie_comment.count = movie_comment_counter.counter;

mint_to(
CpiContext::new_with_signer(
Expand Down
27 changes: 18 additions & 9 deletions tests/anchor-movie-review-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ describe("anchor-movie-review-program", () => {
.rpc()

const account = await program.account.movieAccountState.fetch(movie_pda)
expect(movie.title === account.title)
expect(movie.rating === account.rating)
expect(movie.description === account.description)
expect(account.reviewer === provider.wallet.publicKey)
expect(account.title).to.equal(movie.title);
expect(account.rating).to.equal(movie.rating);
expect(account.description).to.equal(movie.description);
expect(account.reviewer.toBase58()).to.equal(provider.wallet.publicKey.toBase58())

const userAta = await getAccount(provider.connection, tokenAccount)
expect(Number(userAta.amount)).to.equal((10 * 10) ^ 6)
Expand All @@ -80,10 +80,10 @@ describe("anchor-movie-review-program", () => {
.rpc()

const account = await program.account.movieAccountState.fetch(movie_pda)
expect(movie.title === account.title)
expect(newRating === account.rating)
expect(newDescription === account.description)
expect(account.reviewer === provider.wallet.publicKey)
expect(account.title).to.equal(movie.title);
expect(account.rating).to.equal(newRating);
expect(account.description).to.equal(newDescription);
expect(account.reviewer.toBase58()).to.equal(provider.wallet.publicKey.toBase58())
})

it("Adds a comment to a movie review", async () => {
Expand All @@ -104,8 +104,9 @@ describe("anchor-movie-review-program", () => {
program.programId
)

const testComment = "Just a test comment";
const tx = await program.methods
.addComment("Just a test comment")
.addComment(testComment)
.accountsPartial({
movieReview: movie_pda,
mint: mint,
Expand All @@ -114,6 +115,14 @@ describe("anchor-movie-review-program", () => {
movieComment: commentPda,
})
.rpc()

const commentAccount = await program.account.movieComment.fetch(commentPda);
expect(commentAccount.comment).to.equal(testComment);
expect(commentAccount.commenter.toBase58()).to.equal(provider.wallet.publicKey.toBase58());
expect(commentAccount.count.toNumber()).to.equal(1);

const commentCounterAccount = await program.account.movieCommentCounter.fetch(commentCounterPda);
expect(commentCounterAccount.counter.toNumber()).to.equal(1);
})

it("Deletes a movie review", async () => {
Expand Down