Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>Contract Test SnippetNew to Visual Studio Code? Get it now.
Contract Test Snippet

Contract Test Snippet

SpaceStation09

|
2,442 installs
| (0) | Free
Simple snippets which can be used in testing files for smart contracts in Hardhat
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

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

  • typescript

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!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft