🍟 github vscode is so cool

This commit is contained in:
bt3gl 2022-09-29 08:31:54 +00:00
parent 0931961978
commit 5b8de9dc6d
21 changed files with 16 additions and 1 deletions

26
solidity/tests/README.md Normal file
View file

@ -0,0 +1,26 @@
## 🍣 tests in solidity
<br>
### unit testing
<br>
* [Solidity-Coverage](https://github.com/sc-forks/solidity-coverage)
* [Remix tests](https://github.com/ethereum/remix-project/tree/master/libs/remix-tests)
* [OpenZeppelin test helpers](https://github.com/OpenZeppelin/openzeppelin-test-helpers)
* [foundry forge tests](https://github.com/foundry-rs/foundry/tree/master/forge)
* [etheno](https://github.com/crytic/etheno)
<br>
### articles
<br>
* [how to mock solidity contracts](https://ethereum.org/en/developers/tutorials/how-to-mock-solidity-contracts-for-testing/)
* [truffle smart contract test framework](https://ethereum.org/en/developers/tutorials/how-to-mock-solidity-contracts-for-testing/)
* [in-depth guide to testing ethereum smart contracts](https://iamdefinitelyahuman.medium.com/an-in-depth-guide-to-testing-ethereum-smart-contracts-2e41b2770297)
* [how to test smart contracts](https://betterprogramming.pub/how-to-test-ethereum-smart-contracts-35abc8fa199d)

View file

@ -0,0 +1,63 @@
## Basic Unit testing
<br>
Functions in a test file to make testing more structural:
* `beforeEach()` - Runs before each test
* `beforeAll()` - Runs before all tests
* `afterEach()` - Runs after each test
* `afterAll()` - Runs after all tests
<br>
A generic unit testing file looks like:
```
pragma solidity >=0.4.22 <0.8.0;
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "remix_accounts.sol";
// Import here the file to test.
// File name has to end with '_test.sol', this file can contain more than one testSuite contracts
contract testSuite {
/// 'beforeAll' runs before all other tests
/// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll'
function beforeAll() public {
// Here should instantiate tested contract
Assert.equal(uint(1), uint(1), "1 should be equal to 1");
}
function checkSuccess() public {
// Use 'Assert' to test the contract,
// See documentation: https://remix-ide.readthedocs.io/en/latest/assert_library.html
Assert.equal(uint(2), uint(2), "2 should be equal to 2");
Assert.notEqual(uint(2), uint(3), "2 should not be equal to 3");
}
function checkSuccess2() public pure returns (bool) {
// Use the return value (true or false) to test the contract
return true;
}
function checkFailure() public {
Assert.equal(uint(1), uint(2), "1 is not equal to 2");
}
/// Custom Transaction Context
/// See more: https://remix-ide.readthedocs.io/en/latest/unittesting.html#customization
/// #sender: account-1
/// #value: 100
function checkSenderAndValue() public payable {
// account index varies 0-9, value is in wei
Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender");
Assert.equal(msg.value, 100, "Invalid value");
}
}
```
Note that ine can input custom values for `msg.sender` & `msg.value` of transaction using NatSpec comments.