@onflow/flow-js-testing
Version:
This package will expose a set of utility methods, to allow Cadence code testing with libraries like Jest
36 lines (28 loc) • 862 B
JavaScript
import path from "path"
import {
init,
emulator,
getAccountAddress,
getFlowBalance,
mintFlow,
shallResolve,
} from "../src"
beforeEach(async () => {
const basePath = path.resolve(__dirname, "./cadence")
await init(basePath)
await emulator.start()
})
test("flow management", async () => {
// Get address for account with alias "Alice"
const Alice = await getAccountAddress("Alice")
// Get initial balance
const [initialBalance] = await shallResolve(getFlowBalance(Alice))
expect(initialBalance).toBe("0.00100000")
// Add 1.0 FLOW tokens to Alice account
await mintFlow(Alice, "1.0")
// Check updated balance
const [updatedBalance] = await shallResolve(getFlowBalance(Alice))
const expectedBalance = parseFloat(initialBalance) + 1.0
expect(parseFloat(updatedBalance)).toBe(expectedBalance)
await emulator.stop()
})