Skip to content

Commit

Permalink
Step 7: writing the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avasisht23 committed Oct 26, 2022
1 parent 4c4ca5b commit 473cf4f
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/solana-hello-world.ts
Expand Up @@ -9,4 +9,62 @@ describe("solana-hello-world", () => {

const program = anchor.workspace
.SolanaHelloWorld as Program<SolanaHelloWorld>;

it("Can create a message", async () => {
const message = anchor.web3.Keypair.generate();
const messageContent = "Hello World!";
await program.rpc.createMessage(messageContent, {
accounts: {
message: message.publicKey,
author: provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
},
signers: [message],
});

const messageAccount = await program.account.message.fetch(
message.publicKey
);

assert.equal(
messageAccount.author.toBase58(),
provider.wallet.publicKey.toBase58()
);
assert.equal(messageAccount.content, messageContent);
assert.ok(messageAccount.timestamp);
});

it("Can create and then update a message", async () => {
const message = anchor.web3.Keypair.generate();
const messageContent = "Hello World!";
await program.rpc.createMessage(messageContent, {
accounts: {
message: message.publicKey,
author: provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
},
signers: [message],
});

const updatedMessageContent = "Solana is cool!";
await program.rpc.updateMessage(updatedMessageContent, {
accounts: {
message: message.publicKey,
author: provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
},
});

const messageAccount = await program.account.message.fetch(
message.publicKey
);

assert.equal(
messageAccount.author.toBase58(),
provider.wallet.publicKey.toBase58()
);
assert.notEqual(messageAccount.content, messageContent);
assert.equal(messageAccount.content, updatedMessageContent);
assert.ok(messageAccount.timestamp);
});
});

0 comments on commit 473cf4f

Please sign in to comment.