Skip to content

Instantly share code, notes, and snippets.

@FoobarProtocol
Last active September 14, 2024 02:05
Show Gist options
  • Save FoobarProtocol/44c18f05b699fe52d7cef4fd2623762d to your computer and use it in GitHub Desktop.
Save FoobarProtocol/44c18f05b699fe52d7cef4fd2623762d to your computer and use it in GitHub Desktop.
This is the test echidna file that we created to go with the tutorial. There are errors in here on purpose. We're going to refine this smart contract and the finalized version will be submitted in an entirely separate contract
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.7.6;
import "./GnosisSafe.sol";
contract GnosisSafeTest is GnosisSafe {
constructor() {
// Initialize the Gnosis Safe with some owners and a threshold
address[] memory owners = new address[](3);
owners[0] = address(0x1);
owners[1] = address(0x2);
owners[2] = address(0x3);
setup(owners, 2, address(0), "", address(0), address(0), 0, address(0));
}
// Invariant: Transactions should not be executed without enough signatures
function echidna_cannot_execute_without_signatures() public returns (bool) {
// Try executing a transaction with less than the required number of signatures
bytes memory signatures;
bool success = execTransaction(address(0x1), 0, "", Enum.Operation.Call, 100000, 0, 0, address(0), payable(address(0)), signatures);
return !success;
}
// Invariant: Nonce must always increase after a transaction
function echidna_nonce_increases() public returns (bool) {
uint256 oldNonce = nonce;
execTransaction(address(0x1), 0, "", Enum.Operation.Call, 100000, 0, 0, address(0), payable(address(0)), "");
return nonce > oldNonce;
}
// Invariant: The contract must have enough gas to execute a transaction
function echidna_sufficient_gas_for_execution() public returns (bool) {
uint256 safeTxGas = 100000;
return gasleft() >= safeTxGas;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment