|
| 1 | +# Testing |
| 2 | + |
| 3 | +Tests are implemented in [bca-token-solidity/test](./bca-token-solidity/test/) and can be run: |
| 4 | + |
| 5 | +```sh |
| 6 | +cd bca-token-solidity |
| 7 | +npx hardhat test |
| 8 | +``` |
| 9 | + |
| 10 | +# Test coverage |
| 11 | + |
| 12 | +How much of the contract's code is covered by tests? This can be answered by: |
| 13 | + |
| 14 | +```sh |
| 15 | +cd bca-token-solidity |
| 16 | +npx hardhat coverage |
| 17 | +``` |
| 18 | + |
| 19 | +Which outputs as of today (2024-11-23): |
| 20 | + |
| 21 | +```sh |
| 22 | +------------------------------|----------|----------|----------|----------|----------------| |
| 23 | +File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | |
| 24 | +------------------------------|----------|----------|----------|----------|----------------| |
| 25 | + contracts/ | 88.66 | 71.82 | 89.29 | 91.37 | | |
| 26 | + BCA_ERC20_nf.sol | 100 | 68.75 | 100 | 100 | | |
| 27 | + BCA_Funding24.sol | 84.62 | 81.25 | 100 | 88.89 | 64,66 | |
| 28 | + BCA_Service.sol | 25 | 25 | 33.33 | 46.15 |... 45,48,50,54 | |
| 29 | + BCA_ServiceController.sol | 85.71 | 50 | 66.67 | 88.89 | 43 | |
| 30 | + BCA_ServiceInstance.sol | 95.45 | 81.48 | 100 | 96.97 | 141,171 | |
| 31 | + BCA_ServiceManager.sol | 100 | 60 | 100 | 100 | | |
| 32 | + Iface_Funding24.sol | 100 | 100 | 100 | 100 | | |
| 33 | + Iface_Service.sol | 100 | 100 | 100 | 100 | | |
| 34 | + Iface_ServiceController.sol | 100 | 100 | 100 | 100 | | |
| 35 | + Iface_ServiceInstance.sol | 100 | 100 | 100 | 100 | | |
| 36 | + Iface_ServiceManager.sol | 100 | 100 | 100 | 100 | | |
| 37 | +------------------------------|----------|----------|----------|----------|----------------| |
| 38 | +All files | 88.66 | 71.82 | 89.29 | 91.37 | | |
| 39 | +------------------------------|----------|----------|----------|----------|----------------| |
| 40 | +``` |
| 41 | + |
| 42 | +Clearly, for some of the contracts we have to write some more tests to increase coverage. |
| 43 | + |
| 44 | +# Estimating Gas costs |
| 45 | + |
| 46 | +If we run the tests with the environment variable `REPORT_GAS=true`, then the output will contain information about the Gas usage of the transactions. |
| 47 | + |
| 48 | +```sh |
| 49 | +cd bca-token-solidity |
| 50 | +REPORT_GAS=true npx hardhat test |
| 51 | +``` |
| 52 | + |
| 53 | +Will output: |
| 54 | +```sh |
| 55 | +·----------------------------------------------|---------------------------|--------------|-----------------------------· |
| 56 | +| Solc version: 0.8.24 · Optimizer enabled: true · Runs: 1000 · Block limit: 30000000 gas │ |
| 57 | +···············································|···························|··············|······························ |
| 58 | +| Methods │ |
| 59 | +·························|·····················|·············|·············|··············|···············|·············· |
| 60 | +| Contract · Method · Min · Max · Avg · # calls · usd (avg) │ |
| 61 | +·························|·····················|·············|·············|··············|···············|·············· |
| 62 | +| BCAServiceController · newService · - · - · 1106858 · 4 · - │ |
| 63 | +·························|·····················|·············|·············|··············|···············|·············· |
| 64 | +| BCAServiceFunding24 · deposit · 100100 · 156994 · 138029 · 12 · - │ |
| 65 | +·························|·····················|·············|·············|··············|···············|·············· |
| 66 | +| BCAServiceInstance · makeDeposit · 51323 · 105528 · 101656 · 28 · - │ |
| 67 | +·························|·····················|·············|·············|··············|···············|·············· |
| 68 | +| BCAServiceInstance · stop · - · - · 49123 · 4 · - │ |
| 69 | +·························|·····················|·············|·············|··············|···············|·············· |
| 70 | +| BCAServiceInstance · withdrawProvider · 70814 · 105014 · 87939 · 9 · - │ |
| 71 | +·························|·····················|·············|·············|··············|···············|·············· |
| 72 | +| BCAServiceInstance · withdrawUser · - · - · 73013 · 2 · - │ |
| 73 | +·························|·····················|·············|·············|··············|···············|·············· |
| 74 | +| BCAServiceManager · newController · 1385995 · 1402892 · 1394444 · 4 · - │ |
| 75 | +·························|·····················|·············|·············|··············|···············|·············· |
| 76 | +| BCAServiceToken · approve · 46388 · 46448 · 46417 · 25 · - │ |
| 77 | +·························|·····················|·············|·············|··············|···············|·············· |
| 78 | +| BCAServiceToken · burn · 33963 · 33975 · 33971 · 6 · - │ |
| 79 | +·························|·····················|·············|·············|··············|···············|·············· |
| 80 | +| BCAServiceToken · mint · 36620 · 70856 · 61634 · 26 · - │ |
| 81 | +·························|·····················|·············|·············|··············|···············|·············· |
| 82 | +| BCAServiceToken · setBurnerAddress · - · - · 56508 · 1 · - │ |
| 83 | +·························|·····················|·············|·············|··············|···············|·············· |
| 84 | +| BCAServiceToken · setMinterAddress · - · - · 56486 · 1 · - │ |
| 85 | +·························|·····················|·············|·············|··············|···············|·············· |
| 86 | +| BCAServiceToken · setServiceAddress · - · - · 54551 · 2 · - │ |
| 87 | +·························|·····················|·············|·············|··············|···············|·············· |
| 88 | +| BCAServiceToken · transfer · 29706 · 51582 · 45948 · 13 · - │ |
| 89 | +·························|·····················|·············|·············|··············|···············|·············· |
| 90 | +| BCAServiceToken · transferFrom · - · - · 57616 · 3 · - │ |
| 91 | +·························|·····················|·············|·············|··············|···············|·············· |
| 92 | +| Deployments · · % of limit · │ |
| 93 | +···············································|·············|·············|··············|···············|·············· |
| 94 | +| BCAServiceFunding24 · - · - · 854510 · 2.8 % · - │ |
| 95 | +···············································|·············|·············|··············|···············|·············· |
| 96 | +| BCAServiceInstance · - · - · 769313 · 2.6 % · - │ |
| 97 | +···············································|·············|·············|··············|···············|·············· |
| 98 | +| BCAServiceManager · - · - · 1781152 · 5.9 % · - │ |
| 99 | +···············································|·············|·············|··············|···············|·············· |
| 100 | +| BCAServiceToken · - · - · 1175977 · 3.9 % · - │ |
| 101 | +·----------------------------------------------|-------------|-------------|--------------|---------------|-------------· |
| 102 | +``` |
0 commit comments