Contract Test Snippet
This is a vscode snippet to help developers to write test files in more convenient way (for hardhat framework with ethers.js). It includes several commonly used functions.
Language Support
Available Snippets
getRevertMsg
prefix: "revert", "revertMsg", "getRevertMsg"
const getRevertMsg = (msg: string): string =>
`VM Exception while processing transaction: reverted with reason string '${msg}'`;
expectRevert
prefix: "er", "expectRevert", "revert"
await expect().to.be.revertedWith(getRevertMsg("Example Error Msg"));
takeSnapshot
prefix: "takesnapshot", "tsnapshot"
async function takeSnapshot() {
return network.provider.send("evm_snapshot", []);
}
revertToSnapShot
prefix: "rs", "revertsnapshot"
async function revertToSnapShot(id: string) {
await network.provider.send("evm_revert", [id]);
}
advanceTime
prefix: "advance", "at"
async function advanceTime(time: number) {
await network.provider.send("evm_increaseTime", [time]);
}
advanceBlock
prefix: "advance", "ab"
async function advanceBlock() {
await network.provider.send("evm_mine", []);
}
advanceTimeAndBlock
prefix: "advance", "atb"
async function advanceTimeAndBlock(time: number): Promise<providers.Block> {
await advanceTime(time);
await advanceBlock();
return Promise.resolve(ethers.provider.getBlock("latest"));
}
numberToBytes32Hex
prefix: "n2b", "number2bytes", "nb"
hexZeroPad(hexlify(number), 32);
newTestCase
prefix: "it"
it("", async () => {});
newTestCategory
prefix: "describe"
describe("", () => {});
Contribute
Any contribution is welcomed to make it better.
If you have any questions, please create an issue.
Enjoy!