Integration Tests
FPS enables the simulation of proposals within integration tests. This capability is essential for verifying the functionality of your proposals and ensuring they don't break existing features. Additionally, it allows testing of the entire proposal lifecycle, including governance proposals and deployment scripts. This guide illustrates writing integration tests with the Multisig example from our Multisig Proposal Guide. These integration tests have already been implemented in the fps-example repo.
Setting Up PostProposalCheck.sol
The first step is to create a PostProposalCheck.sol contract, which serves as a base for your integration test contracts. This contract is responsible for deploying proposal contracts, executing them, and updating the addresses object. This allows integration tests to run against the newly updated state after all changes from the governance proposal go into effect.
pragma solidity ^0.8.0;
import "@forge-std/Test.sol";
import { MultisigProposal } from "@forge-proposal-simulator/src/proposals/MultisigProposal.sol";
import { Addresses } from "@forge-proposal-simulator/addresses/Addresses.sol";
// @notice this is a helper contract to execute proposals before running integration tests.
// @dev should be inherited by integration test contracts.
contract MultisigPostProposalCheck is Test {
Addresses public addresses;
function setUp() public virtual {
string[] memory inputs = new string[](2);
inputs[0] = "./get-latest-proposal.sh";
inputs[1] = "MultisigProposal";
string memory output = string(vm.ffi(inputs));
MultisigProposal multisigProposal = MultisigProposal(
deployCode(output)
);
vm.makePersistent(address(multisigProposal));
// Execute proposals
multisigProposal.run();
addresses = multisigProposal.addresses();
}
}Creating a script that returns the latest proposal based on the type of proposal.
Creating Integration Test Contracts
Next, the creation of the MultisigProposalIntegrationTest contract is required, which will inherit from MultisigPostProposalCheck. Tests should be added to this contract. Utilize the addresses object within this contract to access the addresses of the contracts that have been deployed by the proposals.
Running Integration Tests
Executing the integration tests triggers the setUp() function before each test, ensuring the tests are always executed on a fresh state after the proposals execution.
Last updated