0
0
Blockchain / Solidityprogramming~5 mins

Development tools setup (Hardhat, Remix) in Blockchain / Solidity - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Development tools setup (Hardhat, Remix)
O(n)
Understanding Time Complexity

When setting up blockchain development tools like Hardhat or Remix, it's important to understand how the time to complete tasks grows as your project gets bigger.

We want to know how the setup and running of these tools scale with the size of your smart contracts and tests.

Scenario Under Consideration

Analyze the time complexity of the following Hardhat test script snippet.


const { expect } = require("chai");
describe("Token contract", function () {
  it("Deployment should assign total supply", async function () {
    const Token = await ethers.getContractFactory("Token");
    const token = await Token.deploy();
    await token.deployed();
    const totalSupply = await token.totalSupply();
    expect(totalSupply).to.equal(1000000);
  });
});
    

This code deploys a token contract and checks its total supply in a test.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Running each test case which deploys contracts and calls functions.
  • How many times: Once per test case; if you have many tests, this repeats for each.
How Execution Grows With Input

As you add more tests or your contracts get larger, the time to deploy and test grows.

Input Size (n)Approx. Operations
10 testsAbout 10 deployments and checks
100 testsAbout 100 deployments and checks
1000 testsAbout 1000 deployments and checks

Pattern observation: The time grows roughly in direct proportion to the number of tests you run.

Final Time Complexity

Time Complexity: O(n)

This means the time to run your tests grows linearly with the number of tests you have.

Common Mistake

[X] Wrong: "Adding more tests won't affect the total time much because each test is small."

[OK] Correct: Each test deploys contracts and runs calls, which takes time. More tests add up and increase total time linearly.

Interview Connect

Understanding how your development tools scale helps you write efficient tests and manage project growth confidently.

Self-Check

"What if we reused the same deployed contract instance for all tests instead of deploying each time? How would the time complexity change?"