40,000 USDC
View results
Submission Details
Severity: gas

Fuzz test used for EscrowFactory

Summary

While testing the contract, a fuzz test was created to test that the address deployed to in newEscrow() will match the precomputed address with all parameters fuzzed.

Details

function testComputedAddressEqualsDeployedAddress(uint salt, uint price, address buyer, address seller, address arbiter, uint arbiter_fee) public hasTokensApprovedForSending {
if (buyer == address(0)) {
buyer = BUYER;
}
if (seller == address(0)) {
seller = SELLER;
}
if (arbiter == address(0)) {
arbiter = ARBITER;
}
price /= 2;
if (price <= 1) {
price = PRICE;
}
if (arbiter_fee >= price) {
arbiter_fee = price / 2;
}
address computedAddress = escrowFactory.computeEscrowAddress(
type(Escrow).creationCode,
address(escrowFactory),
uint256(salt),
price,
i_tokenContract,
buyer,
seller,
arbiter,
arbiter_fee
);
ERC20Mock(address(i_tokenContract)).mint(computedAddress, price);
vm.startPrank(address(escrowFactory));
Escrow escrow = new Escrow{salt: bytes32(salt)}(
price,
i_tokenContract,
buyer,
seller,
arbiter,
arbiter_fee
);
vm.stopPrank();
assertEq(computedAddress, address(escrow));
}

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.