Contract Step Definitions
Chukti provides a set of smart contract related step definitions that can be used to perform contract interactions in your tests. These step definitions will help you to deploy a contract, perform read and write operations on contract. Each step definition is explained with its purpose, usage, required values, and examples.
List of Step Definitions
Initialize a contract
Given I have a smart contract located at "path/to/contract.sol"
Deploy a contract
When I deploy the smart contract with constructor arguments "args" and send "amount" Ether
Then I validate the deployment status is "expectedStatus"
Read from a contract
When I call the read function "functionName" from the contract with arguments "args"
Write to a contract
When I call the write function "functionName" from the contract with arguments "args" and send "amount" Ether
Detailed Step Definitions
🚀 Given I have a smart contract located at "path/to/contract.sol"
Purpose: To load a smart contract from a given file path.
Required Values:
path/to/contract.sol
: The file path to the smart contract relative to the project root.
Example:
Given I have a smart contract located at "contracts/MyContract.sol"
🚀 When I deploy the smart contract with constructor arguments "args" and send "amount" Ether
Purpose: To deploy a smart contract with given constructor arguments and initial Ether.
Required Values:
args
: Array of comma-separated Constructor arguments for the contract. Pass empty [] if no arguments required.amount
: Amount of Ether to send with the transaction.
Example:
When I deploy the smart contract with constructor arguments "[10, 'Alice']" and send "0" Ether
🚀 Then I validate the deployment status is "expectedStatus"
Purpose: To validate the deployment status of the smart contract.
Required Values:
expectedStatus
: The expected status of the transaction. It can be eithersuccess
orreverted
.
Example:
Then I validate the deployment status is "success"
🚀 When I call the read function "functionName" from the contract with arguments "args"
Purpose: To call a read-only function on the contract with the given name.
Required Values:
functionName
: The name of the contract function to call.args
: Array of comma-separated Constructor arguments for the contract. Pass empty [] if no arguments required.
Example:
When I call the read function "getBalance" from the contract with arguments "['Alice']"
🚀 When I call the write function "functionName" from the contract with arguments "args" and send "amount" Ether
Purpose: To call a state-changing (write) function on the contract with specified arguments and Ether.
Required Values:
functionName
: The name of the contract function to call.args
: Array of comma-separated Constructor arguments for the contract. Pass empty [] if no arguments required.amount
: Amount of Ether to send with the transaction.
Example:
When I call the write function "transfer" from the contract with arguments "['Bob',50]" and send "1" Ether
💡 Tip
Wanna learn how to write test using these step definitions? Visit How To Write Test page.