import { Near } from "near-kit"
import { Sandbox } from "near-kit/sandbox"
import { beforeAll, afterAll, test, expect } from "bun:test"
let sandbox: Sandbox
let near: Near
// 1. Start Sandbox
beforeAll(async () => {
// This downloads a NEAR binary and starts a node locally
sandbox = await Sandbox.start()
// near-kit automatically configures the RPC and
// loads the root account key for you.
near = new Near({ network: sandbox })
})
// 2. Stop Sandbox
afterAll(async () => {
if (sandbox) await sandbox.stop()
})
// 3. Write Tests
test("can create account", async () => {
const newAccount = `test.${sandbox.rootAccount.id}`
await near
.transaction(sandbox.rootAccount.id)
.createAccount(newAccount)
.send()
const exists = await near.accountExists(newAccount)
expect(exists).toBe(true)
})