Inspired by The Ruby Koans, Solidity Koans is an introductory guide to smart contract development in ethereum through testing. In such a critical task like smart contracts programming, writing tests is a must.
Walk through Solidity's path of enlightment with this koans.
git clone [email protected]:martriay/solidity-koans.git
npm install
A koan is a test written in Javascript which needs to be fixed in order to pass. It lives in the tests/
folder and may involve contracts from the contracts/
directory.
In test-driven development (TDD) the mantra has always been red: write a failing test and run it, green: make the test pass, and refactor: look at the code and see if you can make it any better. With the koans, you will need to run the tests and see it fail (red), make the test pass (green), then take a moment and reflect upon the test to see what it is teaching you and improve the code to better communicate its intent (refactor).
To achieve enlightment you have to run the test, see it fail and then fix the corresponding files.
To run tests we use truffle
test
:
Compiling ./contracts/Cup.sol...
Compiling ./contracts/Migrations.sol...
Contract: About modifiers
✓ Modifiers can be used to easily change the behaviour of functions
✓ Modifiers can receive arguments
2 passing (171ms)
Note: the
npx
command comes with npm as of [email protected] version.
- About accounts
- About transactions (todo)
- About gas (todo)
- About data (todo)
- About contracts (todo)
- About modifiers
- About events (todo)
- About inheritance (todo)
- About visibility (todo)
- About interfaces (todo)
- About libraries (todo)
- About units (todo)
- About global variables (todo)
- About error handling (todo)
- About overflow (todo)
- About reentrancy (todo)
- About gassy arrays (todo)