Project Testing¶
The following section covers the testing strategy and implementation for all Smart Contracts in the Tru Reputation Token project including supporting Libraries & Smart Contracts.
1. Strategy¶
The Testing Strategy for the Tru Reputation Token Project is as defined below:
- Due to the inherent financial risk of Cryptocurrency, and the nature of Solidity, all Contract code including any supporting Smart Contracts must be subjected to full coverage unit tests to cover all lines, statements, branches and functions.
- All testing is to be conducted on each commit to the Repository.
- Testing will include, as much as practicable, all contrary cases that could cause any failure.
- The Tru Reputation Token Project will not be released without the above items being met.
2. Testing Helpers & Harnesses¶
To facilitate full coverage, the following Testing Helpers and Harnesses have been created:
Name | Detail |
MockFailUpgradeAgent.sol | Test harness of an UpgradeAgent used to test failure paths for upgrades on the TruReputationToken |
MockMigrationTarget.sol | Test harness of an TruReputationToken to simulate an upgrade of the token |
MockSale.sol | Test harness of a TruSale to provide full coverage of failure paths |
MockSupportToken.sol | Test harness for full failure path testing of StandardToken |
MockUpgradeableToken.sol | Test harness of an Upgradeable token for testing of the TruUpgradeableToken Smart Contract |
MockUpgradeableAgent.sol | Test harness of an Upgradeable token for testing of the UpgradeAgent Smart Contract |
EVMInvalidAddress.js | Javascript helper for catching Invalid Address errors from EVM |
EVMRevert.js | Javascript helper for catching Revert errors from EVM |
EVMThrow.js | Javascript helper for catching Throw errors from EVM |
expectFuzzFail.js | Javascript helper for catching Fuzzing failure errors from EVM |
expectNotDeployed.js | Javascript helper for catching Not Deployed errors from EVM |
expectThrow.js | Javascript helper promise for catching Throw errors |
increaseTime.js | Javascript helper to change current time on TestRPC |
isEven.js | Javascript helper to detect in a number is odd or even |
latestTime.js | Javascript helper to get current timestamp of block on TestRPC |
MockFailUpgradeAgent.sol¶
Name: | MockFailUpgradeAgent.sol |
Type: | Solidity Contract |
Path: | ./contracts/test-helpers/MockFailUpgradeAgent.sol |
Detail: | Test harness of an UpgradeAgent used to test failure paths for upgrades on the TruReputationToken |
Author: | Tru Ltd |
MockMigrationTarget.sol¶
Name: | MockMigrationTarget.sol |
Type: | Solidity Contract |
Path: | ./contracts/test-helpers/MockMigrationTarget.sol |
Detail: | Test harness of an TruReputationToken to simulate an upgrade of the token |
Author: | Tru Ltd |
MockSale.sol¶
Name: | MockSale.sol |
Type: | Solidity Contract |
Path: | ./contracts/test-helpers/MockSale.sol |
Detail: | Test harness of a TruSale to provide full coverage of failure paths |
Author: | Tru Ltd |
MockSupportToken.sol¶
Name: | MockSupportToken.sol |
Type: | Solidity Contract |
Path: | ./contracts/test-helpers/MockSupportToken.sol |
Detail: | Test harness for full failure path testing of StandardToken |
Author: | Tru Ltd |
MockUpgradeableToken.sol¶
Name: | MockUpgradeableToken.sol |
Type: | Solidity Contract |
Path: | ./contracts/test-helpers/MockUpgradeableToken.sol |
Detail: | Test harness of an Upgradeable token for testing of the TruUpgradeableToken Smart Contract |
Author: | Tru Ltd |
MockUpgradeableAgent.sol¶
Name: | MockUpgradeableAgent.sol |
Type: | Solidity Contract |
Path: | ./contracts/test-helpers/MockUpgradeableAgent.sol |
Detail: | Test harness of an Upgradeable token for testing of the UpgradeAgent Smart Contract |
Author: | Tru Ltd |
EVMInvalidAddress.js¶
Name: | EVMInvalidAddress.js |
Type: | Solidity Contract |
Path: | ./test/helpers/EVMInvalidAddress.js |
Detail: | Javascript helper for catching Invalid Address errors from EVM |
Author: | Tru Ltd |
EVMRevert.js¶
Name: | EVMRevert.js |
Type: | Solidity Contract |
Path: | ./test/helpers/EVMRevert.js |
Detail: | Javascript helper for catching Revert errors from EVM |
Author: | Tru Ltd |
EVMThrow.js¶
Name: | EVMThrow.js |
Type: | Solidity Contract |
Path: | ./test/helpers/EVMThrow.js |
Detail: | Javascript helper for catching Throw errors from EVM |
Author: | Zeppelin Solidity |
expectFuzzFail.js¶
Name: | expectFuzzFail.js |
Type: | Solidity Contract |
Path: | ./test/helpers/expectFuzzFail.js |
Detail: | Javascript helper for catching Fuzzing failure errors from EVM |
Author: | Tru Ltd |
expectNotDeployed.js¶
Name: | expectNotDeployed.js |
Type: | Solidity Contract |
Path: | ./test/helpers/expectNotDeployed.js |
Detail: | Javascript helper for catching Not Deployed errors from EVM |
Author: | Tru Ltd |
expectThrow.js¶
Name: | expectThrow.js |
Type: | Solidity Contract |
Path: | ./test/helpers/expectThrow.js |
Detail: | Javascript helper promise for catching Throw errors |
Author: | Zeppelin Solidity |
increaseTime.js¶
Name: | increaseTime.js |
Type: | Solidity Contract |
Path: | ./test/helpers/increaseTime.js |
Detail: | Javascript helper to change current time on TestRPC |
Author: | Zeppelin Solidity |
isEven.js¶
Name: | isEven.js |
Type: | Solidity Contract |
Path: | ./test/helpers/isEven.js |
Detail: | Javascript helper to detect in a number is odd or even |
Author: | Tru Ltd |
latestTime.js¶
Name: | latestTime.js |
Type: | Solidity Contract |
Path: | ./test/helpers/latestTime.js |
Detail: | Javascript helper to get current timestamp of block on TestRPC |
Author: | Zeppelin Solidity |
3. Unit Tests¶
The following Unit Tests are defined for the Tru Reputation Token project:
3.1. TruReputationToken Unit Tests¶
Name: | TruReputationToken Unit Tests |
Path: | ./test/Unit_Tests_TruReputationToken.js |
Detail: | Unit Tests covering the TruReputationToken.sol Smart Contract |
No of Test Cases: | 35 |
Description | |
01 | TruReputationToken should have correct name, symbol and description |
02 | Owner should be able to assign Executive Board Address once |
03 | No other account should be able to change Executive Board Address |
04 | Should be unable to assign an empty address as Exec Board |
05 | Should be unable to assign an self as Exec Board |
06 | Exec Board should be able to assign different Exec Board Account |
07 | TruReputationToken should have 0 total supply |
08 | Only TruReputationToken owner can set the Release Agent |
09 | Only TruReputationToken Owner can set transferAgent |
10 | mintingFinished should be false after construction |
11 | Should fail to deploy new Upgrade Token with no tokens |
12 | Should mint a token with 10^18 decimal places |
13 | Should mint 100 tokens to a supplied address |
14 | Should fail to mint after calling finishMinting |
15 | Token should have correct Upgrade Agent |
16 | Should deploy new Upgrade Token |
17 | Should fail to set empty UpgradeMaster |
18 | Should fail to set UpgradeMaster if not already master |
19 | Should set UpgradeMaster if already master |
20 | Token should be able to set the upgrade |
21 | Token should not upgrade without an upgrade agent set |
22 | Should not set an upgrade agent with empty address |
23 | Should not set an upgrade agent with a Token that is not allowed to upgrade |
24 | Should set an upgrade agent that is not an upgrade agent |
25 | Should set an upgrade agent |
26 | Only Token owner can set upgrade |
27 | Token should not upgrade with an empty upgrade amount |
28 | Token should not upgrade from an account without tokens |
29 | Token should not upgrade with an amount greater than the supply |
30 | Should upgrade the token |
31 | UpgradeAgent should not be changed after the upgrade has started |
32 | MockMigrationTarget should revert on attempt to transfer to it |
33 | Functions increaseApproval & decreaseApproval should increase & decrease approved allowance |
34 | Function transferFrom should fail with invalid values |
3.2. TruPreSale Unit Tests¶
Name: | TruPreSale Unit Tests |
Path: | ./test/Unit_Tests_TruPreSale.js |
Detail: | Unit Tests covering the TruPreSale.sol Smart Contract |
No of Test Cases: | 36 |
Description | |
01 | Cannot deploy TruPreSale with incorrect variables |
02 | TruPreSale and TruReputationToken are deployed |
03 | Fallback function should revert |
04 | Pre-Sale hard variables are as expected |
05 | Set Release Agent for TruReputationToken |
06 | Transfer TruReputationToken ownership to Pre-Sale |
07 | Can Add Purchaser to Purchaser Whitelist |
08 | Can Remove Purchaser from Purchaser Whitelist |
09 | Cannot purchase before start of Pre-Sale |
10 | Cannot purchase below minimum purchase amount |
11 | Cannot purchase above maximum purchase amount if not on Whitelist |
12 | Can purchase above maximum purchase amount if on Whitelist |
13 | Can halt Pre-Sale in an emergency |
14 | Tokens cannot be transferred before Pre-Sale is finalised |
15 | Only nominated Release Agent can make Tokens transferable |
16 | Only Token Owner can mint Tokens |
17 | Has correct Purchaser count |
18 | Cannot buy more than cap |
19 | Pre-Sale owner cannot finalise a Pre-Sale before it ends |
20 | Cannot buy with invalid address |
21 | Cannot buy 0 amount |
22 | Can buy repeatedly from the same address |
23 | Can buy up to the cap on the Pre-Sale |
24 | Cannot buy once the cap is reached on the Pre-Sale |
25 | Cannot buy once Pre-Sale has ended |
26 | Pre-Sale owner can finalise the Pre-Sale |
27 | Cannot finalise a finalised Pre-Sale |
28 | Minted TruReputationToken cannot be transferred yet |
29 | Can change Pre-Sale end time to further into the future |
30 | Cannot change Pre-Sale end time to less than start time |
31 | Can change Pre-Sale end time to less than current end time |
32 | Can change Pre-Sale end time to less than current time & end sale |
33 | Only Pre-Sale Owner can change Pre-Sale end time |
34 | Cannot create Pre-Sale with end time before start time |
35 | Cannot create Pre-Sale with invalid Token Address |
36 | Cannot create Pre-Sale with invalid Sale Wallet Address |
3.3. TruCrowdSale Unit Tests¶
Name: | TruCrowdSale Unit Tests |
Path: | ./test/Unit_Tests_TruCrowdSale.js |
Detail: | Unit Tests covering the TruCrowdSale.sol Smart Contract |
No of Test Cases: | 37 |
Description | |
01 | Cannot deploy TruCrowdSale with incorrect variables |
02 | TruPreSale and TruReputationToken are deployed |
03 | Simulate completed PreSale and transition to CrowdSale |
04 | Fallback function should revert |
05 | CrowdSale hard variables are as expected |
06 | Transfer TruReputationToken ownership to CrowdSale |
07 | Can Add Purchaser to CrowdSale Purchaser Whitelist |
08 | Can Remove Purchaser from CrowdSale Purchaser Whitelist |
09 | Cannot purchase before start of CrowdSale |
10 | Cannot purchase below minimum purchase amount |
11 | Cannot purchase above maximum purchase amount if not on CrowdSale Whitelist |
12 | Can purchase above maximum purchase amount if on CrowdSale Whitelist |
13 | Can halt CrowdSale in an emergency |
14 | Tokens cannot be transferred before CrowdSale is finalised |
15 | Only nominated Release Agent can make Tokens transferable |
16 | Only Token Owner can mint Tokens |
17 | CrowdSale has correct Purchaser count |
18 | Cannot buy more than CrowdSale cap |
19 | CrowdSale owner cannot finalise a CrowdSale before it ends |
20 | Cannot buy from CrowdSale with invalid address |
21 | Cannot buy 0 amount from CrowdSale |
22 | Can buy repeatedly from the same address |
23 | Can buy up to the cap on the CrowdSale |
24 | Cannot buy once the cap is reached on the CrowdSale |
25 | CrowdSale owner can finalise the CrowdSale |
26 | Cannot buy once CrowdSale has ended |
27 | Cannot finalise a finalised CrowdSale |
28 | Minted TruReputationToken can be transferred |
29 | CrowdSale has higher cap if PreSale did not hit cap |
30 | Can change CrowdSale end time to further into the future |
31 | Cannot change CrowdSale end time to less than start time |
32 | Can change CrowdSale end time to less than current end time |
33 | Can change CrowdSale end time to less than current time & end sale |
34 | Only Crowdsale Owner can change CrowdSale end time |
35 | Cannot create Crowdsale with end time before start time |
36 | Cannot create Crowdsale with invalid Token Address |
37 | Cannot create Crowdsale with invalid Sale Wallet Address |
4. Fuzzing Tests¶
To ensure a robust testing strategy to ensure code quality and predictability, using fuzzing testing can expose non-obvious exploits through testing non-obvious code paths and reactions to large numbers of tests with large amount of data.
To ensure the security and stability of the Tru Reputation Protocol and the Tru Reputation Token project, Fuzzing is performed on all Smart Contracts to expose and remedy any potential vulnerabilities or exploits introduced in each release cycle.
Due to the nature of fuzzing and the defaults of Mocha and some characteristics of the TestRPC network these tests can take up to an hour to execute.
4.1. TruReputationToken Fuzzing Tests¶
Name: | TruReputationToken Fuzzing Tests |
Path: | ./test/Fuzzing_Tests_TruReputationToken.js |
Detail: | Fuzzing Tests covering the TruReputationToken.sol Smart Contract |
No of Test Cases: | 27 |
Description | |
01 | Fuzz test of TruReputationToken Constructor with invalid executor address |
02 | Fuzz test of TruReputationToken changeBoardAddress with invalid arguments |
03 | Fuzz test of TruMintableToken mint with invalid arguments |
04 | Fuzz test of TruMintableToken finishMinting with invalid arguments |
05 | Fuzz test of ReleasableToken setTransferAgent with invalid arguments |
06 | Fuzz test of ReleasableToken setReleaseAgent with invalid arguments |
07 | Fuzz test of ReleasableToken releaseTokenTransfer with invalid arguments |
08 | Fuzz test of ReleasableToken transfer with invalid arguments |
09 | Fuzz test of ReleasableToken transferFrom with invalid arguments |
10 | Fuzz test of StandardToken approve with invalid arguments |
11 | Fuzz test of StandardToken allowance with invalid arguments |
12 | Fuzz test of StandardToken increaseApproval with invalid arguments |
13 | Fuzz test of StandardToken decreaseApproval with invalid arguments |
14 | Fuzz test of transferFrom of StandardToken with invalid arguments |
15 | Fuzz test of BasicToken balanceOf with invalid arguments |
16 | Fuzz test of transferOwnership of Ownable with invalid arguments |
17 | Fuzz test of UpgradeableToken setUpgradeAgent with invalid arguments |
18 | Fuzz test of UpgradeableToken setUpgradeMaster with invalid arguments |
19 | Fuzz test of UpgradeableToken upgrade with invalid arguments |
20 | Fuzz test of UpgradeableToken upgradeFrom with invalid arguments |
21 | Fuzz test of Ownable transferOwnership with invalid arguments |
22 | Fuzz test performing a large volume of transfer() transactions of 1 TRU between accounts |
23 | Fuzz test performing a large volume of transferFrom() transactions of 1 TRU between accounts |
24 | Fuzz test performing a large volume of transfer() transactions of 300,000,000 TRU between accounts |
25 | Fuzz test performing a large volume transferFrom() transactions of 300,000,000 TRU between accounts |
26 | Fuzz test of functions that receive no direct input |
27 | Fuzz test of structural send & sendTransaction functions |
4.2. TruPreSale Fuzzing Tests¶
Name: | TruPreSale Fuzzing Tests |
Path: | ./test/Fuzzing_Tests_TruPreSale.js |
Detail: | Fuzzing Tests covering the TruPreSale.sol Smart Contract |
No of Test Cases: | 13 |
Description | |
01 | Fuzz test of TruPreSale Constructor with invalid parameters |
02 | Fuzz test of TruPreSale updateWhiteList with invalid parameters |
03 | Fuzz test of TruPreSale buy with invalid parameters |
04 | Fuzz test of TruPreSale finalise with invalid parameters |
05 | Fuzz test of TruPreSale halt with invalid parameters |
06 | Fuzz test of TruPreSale hasEnded with invalid parameters |
07 | Fuzz test of TruPreSale send with invalid parameters |
08 | Fuzz test of TruPreSale sendTransaction with invalid parameters |
09 | Fuzz test of TruPreSale transferOwnership with invalid parameters |
10 | Fuzz test of TruPreSale unhalt with invalid parameters |
11 | Fuzz test of TruPreSale purchasedAmount with invalid parameters |
12 | Fuzz test of TruPreSale purchaserWhiteList with invalid parameters |
13 | Fuzz test of TruPreSale tokenAmount with invalid parameters |
4.3. TruCrowdSale Fuzzing Tests¶
Name: | TruCrowdSale Fuzzing Tests |
Path: | ./test/Fuzzing_Tests_TruCrowdSale.js |
Detail: | Fuzzing Tests covering the TruCrowdSale.sol Smart Contract |
No of Test Cases: | 13 |
Description | |
01 | Fuzz test of TruCrowdSale Constructor with invalid parameters |
02 | Fuzz test of TruCrowdSale updateWhiteList with invalid parameters |
03 | Fuzz test of TruCrowdSale buy with invalid parameters |
04 | Fuzz test of TruCrowdSale finalise with invalid parameters |
05 | Fuzz test of TruCrowdSale halt with invalid parameters |
06 | Fuzz test of TruCrowdSale hasEnded with invalid parameters |
07 | Fuzz test of TruCrowdSale send with invalid parameters |
08 | Fuzz test of TruCrowdSale sendTransaction with invalid parameters |
09 | Fuzz test of TruCrowdSale transferOwnership with invalid parameters |
10 | Fuzz test of TruCrowdSale unhalt with invalid parameters |
11 | Fuzz test of TruCrowdSale purchasedAmount with invalid parameters |
12 | Fuzz test of TruCrowdSale purchaserWhiteList with invalid parameters |
13 | Fuzz test of TruCrowdSale tokenAmount with invalid parameters |
5. Edge Tests¶
To fully test edge cases, uncommon scenarios, or non conventional paths in code, Edge Tests have been written to ensure all paths in code are tested fully and for all possible results.
5.1 Supporting Edge Tests¶
Name: | Supporting Edge Tests |
Path: | ./test/Edge_Tests_Supporting.js |
Detail: | Edges Tests covering edge case & failure testing on Supporting Smart Contracts & Libraries |
No of Test Cases: | 5 |
Description | |
01 | Should test all SafeMath functions |
02 | Should test transferFrom edge case |
03 | Should test all edge cases for TruSale |
04 | Should fail to set Migration Agent with |
05 | Should fail with invalid upgradeMaster Address in constructor |