Skip to content

Chukti

Testing Smart Contracts Effortlessly

Write Smart Contract Tests using Plain English Sentences

Chukti

Overview ​

gherkin
Feature: Counter contract example

  Scenario: Deploy and interact with the Counter contract
    Given I have a smart contract located at "contracts/Counter.sol"
    When I deploy the smart contract with constructor arguments "[10]" and send "0" Ether
    Then I validate the deployment status is "success"

    When I call the read function "getNumber" from the contract with arguments "[]"
    Then I store the result in "currentNumber"
    And I validate the value stored in "currentNumber" should be "equal to" "10"

    When I call the write function "increment" from the contract with arguments "[]" and send "0" Ether
    Then I validate the status of the last transaction is "success"

    And I call the read function "getNumber" from the contract with arguments "[]"
    Then I store the result in "currentNumber"
    And I validate the value stored in "currentNumber" should be "equal to" "11"
solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract Counter {
    uint256 private number;

    constructor(uint256 _number) {
        number = _number;
    }

    function getNumber() public view returns (uint256) {
        return number;
    }

    function setNumber(uint256 _number) public {
        number = _number;
    }

    function increment() public {
        number++;
    }

    function decrement() public {
        number--;
    }

    function resetNumber() public {
        number = 0;
    }

    function incrementBy(uint256 _value) public {
        number += _value;
    }
}

Released under the MIT License.