import { Cl, ClarityType } from "@stacks/transactions";
import { beforeEach, describe, expect, it } from "vitest";
import { initSimnet } from '@stacks/clarinet-sdk';
let simnet: Awaited<ReturnType<typeof initSimnet>>;
let accounts: ReturnType<Awaited<ReturnType<typeof initSimnet>>['getAccounts']>;
let deployer: string;
let address1: string;
beforeEach(async () => {
simnet = await initSimnet();
accounts = simnet.getAccounts();
deployer = accounts.get("deployer")!;
address1 = accounts.get("wallet_1")!;
});
describe("example tests", () => {
let content = "Hello Stacks Devs!"
it("allows user to add a new message", () => {
let currentBurnBlockHeight = simnet.burnBlockHeight;
let confirmation = simnet.callPublicFn(
"message",
"add-message",
[Cl.stringUtf8(content)],
address1
)
const messageCount = simnet.getDataVar("message", "message-count");
expect(confirmation.result.type).toBe(ClarityType.ResponseOk);
expect(confirmation.result).toEqual(Cl.ok(messageCount));
expect(confirmation.events[1].data.value).toEqual(Cl.tuple({
author: Cl.standardPrincipal(address1),
event: Cl.stringAscii("[Stacks Dev Quickstart] New Message"),
id: messageCount,
message: Cl.stringUtf8(content),
time: Cl.uint(currentBurnBlockHeight),
}));
});
it("allows contract owner to withdraw funds", () => {
simnet.callPublicFn(
"message",
"add-message",
[Cl.stringUtf8(content)],
address1
)
simnet.mineEmptyBurnBlocks(2);
let confirmation = simnet.callPublicFn(
"message",
"withdraw-funds",
[],
deployer
)
expect(confirmation.result).toEqual(Cl.ok(Cl.bool(true)));
expect(confirmation.events[0].event).toBe("ft_transfer_event")
expect(confirmation.events[0].data).toMatchObject({
amount: '1',
asset_identifier: 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token::sbtc-token',
recipient: deployer,
sender: `${deployer}.message`,
})
})
});