Testing your detector
Last updated
Was this helpful?
Last updated
Was this helpful?
Testing is key, not only when writing smart contracts but also when writing the detectors to test them.
Testing an Aderyn detector is extremely easy, as it's built in Rust and can be tested as any other Rust code, with the only difference being that you will need a Solidity smart contract implementing the vulnerability your detector has to find.
Luckily, Cyfrin Aderyn has a series of smart contracts in the tests/contracts_playground/src
folder, which you can use to test your detectors.
You can also find the same contracts in the .
Now, let's say we want to test the detector we've built in the , whose only job is ensuring that all modifiers assigned to every function are used and that there are no useless modifiers.
Simplified, the detector looks like this:
As you can notice, the perform()
function has the onlyeOnce
modifier assigned only, which does nothing, our detector should find it and report it - to test this is true, let's copy-paste the following code under our detector declaration:
In the code above, we are:
Run the detect function
Assert if we've effectively found the vulnerability
To run the one test we just made, run the following command in your terminal:
Or, to run all the tests:
If the vulnerability was found, the detector successfully worked, and you're ready to use it, publish it, and contribute to Aderyn. TODO
To test it, we will use the contract available in the tests/contracts_playground/contracts_playground
folder:
Importing the smart contract AST
You can learn more about using the official documentation.