From 2655e17202e764dea057350b7211d4b724a8821e Mon Sep 17 00:00:00 2001 From: Sam McCord Date: Mon, 26 Aug 2024 11:34:18 -0600 Subject: [PATCH] chore(tests): more tests --- .../evm/contracts/budgets/AManagedBudget.sol | 264 +++----- .../evm/contracts/budgets/ManagedBudget.sol | 4 +- packages/evm/test/budgets/ManagedBudget.t.sol | 603 ++++-------------- 3 files changed, 184 insertions(+), 687 deletions(-) diff --git a/packages/evm/contracts/budgets/AManagedBudget.sol b/packages/evm/contracts/budgets/AManagedBudget.sol index 222e0e9b3..b62174e14 100644 --- a/packages/evm/contracts/budgets/AManagedBudget.sol +++ b/packages/evm/contracts/budgets/AManagedBudget.sol @@ -16,12 +16,7 @@ import {Cloneable} from "contracts/shared/Cloneable.sol"; /// @title Abstract Managed Budget /// @notice A minimal budget implementation that simply holds and distributes tokens (ERC20-like and native) /// @dev This type of budget supports ETH, ERC20, and ERC1155 assets only -abstract contract AManagedBudget is - Budget, - OwnableRoles, - IERC1155Receiver, - ReentrancyGuard -{ +abstract contract AManagedBudget is Budget, OwnableRoles, IERC1155Receiver, ReentrancyGuard { using SafeTransferLib for address; /// @notice The role for depositing funds. @@ -47,55 +42,31 @@ abstract contract AManagedBudget is /// @return True if the allocation was successful /// @dev The caller must have already approved the contract to transfer the asset /// @dev If the asset transfer fails, the allocation will revert - function allocate( - bytes calldata data_ - ) external payable virtual override returns (bool) { + function allocate(bytes calldata data_) external payable virtual override returns (bool) { Transfer memory request = abi.decode(data_, (Transfer)); if (request.assetType == AssetType.ETH) { - FungiblePayload memory payload = abi.decode( - request.data, - (FungiblePayload) - ); + FungiblePayload memory payload = abi.decode(request.data, (FungiblePayload)); // Ensure the value received is equal to the `payload.amount` if (msg.value != payload.amount) { revert InvalidAllocation(request.asset, payload.amount); } } else if (request.assetType == AssetType.ERC20) { - FungiblePayload memory payload = abi.decode( - request.data, - (FungiblePayload) - ); + FungiblePayload memory payload = abi.decode(request.data, (FungiblePayload)); // Transfer `payload.amount` of the token to this contract - request.asset.safeTransferFrom( - request.target, - address(this), - payload.amount - ); + request.asset.safeTransferFrom(request.target, address(this), payload.amount); if (request.asset.balanceOf(address(this)) < payload.amount) { revert InvalidAllocation(request.asset, payload.amount); } } else if (request.assetType == AssetType.ERC1155) { - ERC1155Payload memory payload = abi.decode( - request.data, - (ERC1155Payload) - ); + ERC1155Payload memory payload = abi.decode(request.data, (ERC1155Payload)); // Transfer `payload.amount` of `payload.tokenId` to this contract IERC1155(request.asset).safeTransferFrom( - request.target, - address(this), - payload.tokenId, - payload.amount, - payload.data + request.target, address(this), payload.tokenId, payload.amount, payload.data ); - if ( - IERC1155(request.asset).balanceOf( - address(this), - payload.tokenId - ) < payload.amount - ) { + if (IERC1155(request.asset).balanceOf(address(this), payload.tokenId) < payload.amount) { revert InvalidAllocation(request.asset, payload.amount); } } else { @@ -113,38 +84,20 @@ abstract contract AManagedBudget is /// @dev Only admins can directly reclaim assets from the budget /// @dev If the amount is zero, the entire balance of the asset will be transferred to the receiver /// @dev If the asset transfer fails, the reclamation will revert - function reclaim( - bytes calldata data_ - ) external virtual override onlyOwnerOrRoles(ADMIN_ROLE) returns (bool) { + function reclaim(bytes calldata data_) external virtual override onlyOwnerOrRoles(ADMIN_ROLE) returns (bool) { Transfer memory request = abi.decode(data_, (Transfer)); - if ( - request.assetType == AssetType.ETH || - request.assetType == AssetType.ERC20 - ) { - FungiblePayload memory payload = abi.decode( - request.data, - (FungiblePayload) - ); + if (request.assetType == AssetType.ETH || request.assetType == AssetType.ERC20) { + FungiblePayload memory payload = abi.decode(request.data, (FungiblePayload)); _transferFungible( - request.asset, - request.target, - payload.amount == 0 ? available(request.asset) : payload.amount + request.asset, request.target, payload.amount == 0 ? available(request.asset) : payload.amount ); } else if (request.assetType == AssetType.ERC1155) { - ERC1155Payload memory payload = abi.decode( - request.data, - (ERC1155Payload) - ); + ERC1155Payload memory payload = abi.decode(request.data, (ERC1155Payload)); _transferERC1155( request.asset, request.target, payload.tokenId, - payload.amount == 0 - ? IERC1155(request.asset).balanceOf( - address(this), - payload.tokenId - ) - : payload.amount, + payload.amount == 0 ? IERC1155(request.asset).balanceOf(address(this), payload.tokenId) : payload.amount, payload.data ); } else { @@ -159,9 +112,7 @@ abstract contract AManagedBudget is /// @param data_ The packed {Transfer} request /// @return True if the disbursement was successful /// @dev If the asset transfer fails, the disbursement will revert - function disburse( - bytes calldata data_ - ) + function disburse(bytes calldata data_) public virtual override @@ -169,14 +120,8 @@ abstract contract AManagedBudget is returns (bool) { Transfer memory request = abi.decode(data_, (Transfer)); - if ( - request.assetType == AssetType.ERC20 || - request.assetType == AssetType.ETH - ) { - FungiblePayload memory payload = abi.decode( - request.data, - (FungiblePayload) - ); + if (request.assetType == AssetType.ERC20 || request.assetType == AssetType.ETH) { + FungiblePayload memory payload = abi.decode(request.data, (FungiblePayload)); uint256 avail = available(request.asset); if (payload.amount > avail) { @@ -185,26 +130,14 @@ abstract contract AManagedBudget is _transferFungible(request.asset, request.target, payload.amount); } else if (request.assetType == AssetType.ERC1155) { - ERC1155Payload memory payload = abi.decode( - request.data, - (ERC1155Payload) - ); + ERC1155Payload memory payload = abi.decode(request.data, (ERC1155Payload)); - uint256 avail = IERC1155(request.asset).balanceOf( - address(this), - payload.tokenId - ); + uint256 avail = IERC1155(request.asset).balanceOf(address(this), payload.tokenId); if (payload.amount > avail) { revert InsufficientFunds(request.asset, avail, payload.amount); } - _transferERC1155( - request.asset, - request.target, - payload.tokenId, - payload.amount, - payload.data - ); + _transferERC1155(request.asset, request.target, payload.tokenId, payload.amount, payload.data); } else { return false; } @@ -216,9 +149,7 @@ abstract contract AManagedBudget is /// @notice Disburses assets from the budget to multiple recipients /// @param data_ The packed array of {Transfer} requests /// @return True if all disbursements were successful - function disburseBatch( - bytes[] calldata data_ - ) external virtual override returns (bool) { + function disburseBatch(bytes[] calldata data_) external virtual override returns (bool) { for (uint256 i = 0; i < data_.length; i++) { if (!disburse(data_[i])) return false; } @@ -228,20 +159,18 @@ abstract contract AManagedBudget is /// @inheritdoc Budget /// @dev Checks if account has any level of authorization - function isAuthorized( - address account_ - ) public view virtual override returns (bool) { - return - owner() == account_ || - hasAnyRole(account_, MANAGER_ROLE | ADMIN_ROLE); + function isAuthorized(address account_) public view virtual override returns (bool) { + return owner() == account_ || hasAnyRole(account_, MANAGER_ROLE | ADMIN_ROLE); } /// @inheritdoc Budget /// @dev If authorization is true, grant manager role, otherwise revoke manager role. - function setAuthorized( - address[] calldata accounts_, - bool[] calldata authorized_ - ) external virtual override onlyOwnerOrRoles(ADMIN_ROLE) { + function setAuthorized(address[] calldata accounts_, bool[] calldata authorized_) + external + virtual + override + onlyOwnerOrRoles(ADMIN_ROLE) + { if (accounts_.length != authorized_.length) { revert BoostError.LengthMismatch(); } @@ -258,10 +187,11 @@ abstract contract AManagedBudget is /// @notice Set roles for accounts authoried to use the budget /// @param accounts_ The accounts to assign the corresponding role by index /// @param roles_ The roles to assign - function grantRoles( - address[] calldata accounts_, - uint256[] calldata roles_ - ) external virtual onlyOwnerOrRoles(ADMIN_ROLE) { + function grantRoles(address[] calldata accounts_, uint256[] calldata roles_) + external + virtual + onlyOwnerOrRoles(ADMIN_ROLE) + { if (accounts_.length != roles_.length) { revert BoostError.LengthMismatch(); } @@ -273,10 +203,11 @@ abstract contract AManagedBudget is /// @notice Revoke roles for accounts authoried to use the budget /// @param accounts_ The accounts to assign the corresponding role by index /// @param roles_ The roles to remove - function revokeRoles( - address[] calldata accounts_, - uint256[] calldata roles_ - ) external virtual onlyOwnerOrRoles(ADMIN_ROLE) { + function revokeRoles(address[] calldata accounts_, uint256[] calldata roles_) + external + virtual + onlyOwnerOrRoles(ADMIN_ROLE) + { if (accounts_.length != roles_.length) { revert BoostError.LengthMismatch(); } @@ -290,9 +221,7 @@ abstract contract AManagedBudget is /// @param asset_ The address of the asset /// @return The total amount of assets /// @dev This is simply the sum of the current balance and the distributed amount - function total( - address asset_ - ) external view virtual override returns (uint256) { + function total(address asset_) external view virtual override returns (uint256) { return available(asset_) + _distributedFungible[asset_]; } @@ -300,13 +229,8 @@ abstract contract AManagedBudget is /// @param asset_ The address of the asset /// @param tokenId_ The ID of the token /// @return The total amount of assets - function total( - address asset_, - uint256 tokenId_ - ) external view virtual returns (uint256) { - return - IERC1155(asset_).balanceOf(address(this), tokenId_) + - _distributedERC1155[asset_][tokenId_]; + function total(address asset_, uint256 tokenId_) external view virtual returns (uint256) { + return IERC1155(asset_).balanceOf(address(this), tokenId_) + _distributedERC1155[asset_][tokenId_]; } /// @inheritdoc Budget @@ -315,23 +239,15 @@ abstract contract AManagedBudget is /// @return The amount of assets available /// @dev This is simply the current balance held by the budget /// @dev If the zero address is passed, this function will return the native balance - function available( - address asset_ - ) public view virtual override returns (uint256) { - return - asset_ == address(0) - ? address(this).balance - : asset_.balanceOf(address(this)); + function available(address asset_) public view virtual override returns (uint256) { + return asset_ == address(0) ? address(this).balance : asset_.balanceOf(address(this)); } /// @notice Get the amount of ERC1155 assets available for distribution from the budget /// @param asset_ The address of the asset /// @param tokenId_ The ID of the token /// @return The amount of assets available - function available( - address asset_, - uint256 tokenId_ - ) public view virtual returns (uint256) { + function available(address asset_, uint256 tokenId_) public view virtual returns (uint256) { return IERC1155(asset_).balanceOf(address(this), tokenId_); } @@ -339,9 +255,7 @@ abstract contract AManagedBudget is /// @notice Get the amount of assets that have been distributed from the budget /// @param asset_ The address of the asset /// @return The amount of assets distributed - function distributed( - address asset_ - ) external view virtual override returns (uint256) { + function distributed(address asset_) external view virtual override returns (uint256) { return _distributedFungible[asset_]; } @@ -349,18 +263,13 @@ abstract contract AManagedBudget is /// @param asset_ The address of the asset /// @param tokenId_ The ID of the token /// @return The amount of assets distributed - function distributed( - address asset_, - uint256 tokenId_ - ) external view virtual returns (uint256) { + function distributed(address asset_, uint256 tokenId_) external view virtual returns (uint256) { return _distributedERC1155[asset_][tokenId_]; } /// @inheritdoc Budget /// @dev This is a no-op as there is no local balance to reconcile - function reconcile( - bytes calldata - ) external virtual override returns (uint256) { + function reconcile(bytes calldata) external virtual override returns (uint256) { return 0; } @@ -370,11 +279,7 @@ abstract contract AManagedBudget is /// @param amount_ The amount of the asset to transfer /// @dev This function is used to transfer assets from the budget to a given recipient (typically an incentive contract) /// @dev If the destination address is the zero address, or the transfer fails for any reason, this function will revert - function _transferFungible( - address asset_, - address to_, - uint256 amount_ - ) internal virtual nonReentrant { + function _transferFungible(address asset_, address to_, uint256 amount_) internal virtual nonReentrant { // Increment the total amount of the asset distributed from the budget if (to_ == address(0)) revert TransferFailed(asset_, to_, amount_); if (amount_ > available(asset_)) { @@ -393,83 +298,58 @@ abstract contract AManagedBudget is emit Distributed(asset_, to_, amount_); } - function _transferERC1155( - address asset_, - address to_, - uint256 tokenId_, - uint256 amount_, - bytes memory data_ - ) internal virtual nonReentrant { + function _transferERC1155(address asset_, address to_, uint256 tokenId_, uint256 amount_, bytes memory data_) + internal + virtual + nonReentrant + { // Increment the total amount of the asset distributed from the budget if (to_ == address(0)) revert TransferFailed(asset_, to_, amount_); if (amount_ > available(asset_, tokenId_)) { - revert InsufficientFunds( - asset_, - available(asset_, tokenId_), - amount_ - ); + revert InsufficientFunds(asset_, available(asset_, tokenId_), amount_); } _distributedERC1155[asset_][tokenId_] += amount_; // Transfer the asset to the recipient // wake-disable-next-line reentrancy (`nonReentrant` modifier is applied to the function) - IERC1155(asset_).safeTransferFrom( - address(this), - to_, - tokenId_, - amount_, - data_ - ); + IERC1155(asset_).safeTransferFrom(address(this), to_, tokenId_, amount_, data_); emit Distributed(asset_, to_, amount_); } /// @inheritdoc IERC1155Receiver /// @dev This contract does not care about the specifics of the inbound token, so we simply return the magic value (i.e. the selector for `onERC1155Received`) - function onERC1155Received( - address, - address, - uint256, - uint256, - bytes calldata - ) external pure override returns (bytes4) { + function onERC1155Received(address, address, uint256, uint256, bytes calldata) + external + pure + override + returns (bytes4) + { // We don't need to do anything here return IERC1155Receiver.onERC1155Received.selector; } /// @inheritdoc IERC1155Receiver /// @dev This contract does not care about the specifics of the inbound token, so we simply return the magic value (i.e. the selector for `onERC1155Received`) - function onERC1155BatchReceived( - address, - address, - uint256[] calldata, - uint256[] calldata, - bytes calldata - ) external pure override returns (bytes4) { + function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata) + external + pure + override + returns (bytes4) + { // We don't need to do anything here return IERC1155Receiver.onERC1155BatchReceived.selector; } /// @inheritdoc Cloneable - function supportsInterface( - bytes4 interfaceId - ) public view virtual override(Budget, IERC165) returns (bool) { - return - interfaceId == type(AManagedBudget).interfaceId || - interfaceId == type(IERC1155Receiver).interfaceId || - interfaceId == type(IERC165).interfaceId || - Budget.supportsInterface(interfaceId); + function supportsInterface(bytes4 interfaceId) public view virtual override(Budget, IERC165) returns (bool) { + return interfaceId == type(AManagedBudget).interfaceId || interfaceId == type(IERC1155Receiver).interfaceId + || interfaceId == type(IERC165).interfaceId || Budget.supportsInterface(interfaceId); } /// @inheritdoc Cloneable - function getComponentInterface() - public - pure - virtual - override - returns (bytes4) - { + function getComponentInterface() public pure virtual override returns (bytes4) { return type(AManagedBudget).interfaceId; } } diff --git a/packages/evm/contracts/budgets/ManagedBudget.sol b/packages/evm/contracts/budgets/ManagedBudget.sol index b85674112..97be3e212 100644 --- a/packages/evm/contracts/budgets/ManagedBudget.sol +++ b/packages/evm/contracts/budgets/ManagedBudget.sol @@ -22,9 +22,7 @@ contract ManagedBudget is AManagedBudget { /// @inheritdoc AManagedBudget /// @param data_ The packed init data for the budget `(address owner, address[] authorized, uint256[] roles)` - function initialize( - bytes calldata data_ - ) public virtual override initializer { + function initialize(bytes calldata data_) public virtual override initializer { InitPayload memory init_ = abi.decode(data_, (InitPayload)); _initializeOwner(init_.owner); for (uint256 i = 0; i < init_.authorized.length; i++) { diff --git a/packages/evm/test/budgets/ManagedBudget.t.sol b/packages/evm/test/budgets/ManagedBudget.t.sol index 95ddb1073..0b7f9ba9d 100644 --- a/packages/evm/test/budgets/ManagedBudget.t.sol +++ b/packages/evm/test/budgets/ManagedBudget.t.sol @@ -32,16 +32,10 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC1155.mint(address(this), 42, 100); // Deploy a new ManagedBudget contract - managedBudget = ManagedBudget( - payable(LibClone.clone(address(new ManagedBudget()))) - ); + managedBudget = ManagedBudget(payable(LibClone.clone(address(new ManagedBudget())))); managedBudget.initialize( abi.encode( - ManagedBudget.InitPayload({ - owner: address(this), - authorized: new address[](0), - roles: new uint256[](0) - }) + ManagedBudget.InitPayload({owner: address(this), authorized: new address[](0), roles: new uint256[](0)}) ) ); } @@ -89,10 +83,8 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Because the slot is private, we use `vm.load` to access it then parse out the bits: // - [0] is the `initializing` flag (which should be 0 == false) // - [1..64] hold the `initializedVersion` (which should be 1) - bytes32 slot = vm.load( - address(managedBudget), - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffbf601132 - ); + bytes32 slot = + vm.load(address(managedBudget), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffbf601132); uint64 version; assembly { @@ -109,15 +101,9 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testInitialize() public { // Initializer can only be called on clones, not the base contract bytes memory data = abi.encode( - ManagedBudget.InitPayload({ - owner: address(this), - authorized: new address[](0), - roles: new uint256[](0) - }) - ); - ManagedBudget clone = ManagedBudget( - payable(LibClone.clone(address(managedBudget))) + ManagedBudget.InitPayload({owner: address(this), authorized: new address[](0), roles: new uint256[](0)}) ); + ManagedBudget clone = ManagedBudget(payable(LibClone.clone(address(managedBudget)))); clone.initialize(data); // Ensure the budget has the correct authorities @@ -141,12 +127,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); assertTrue(managedBudget.allocate(data)); // Ensure the budget has 100 tokens @@ -155,12 +136,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testAllocate_NativeBalance() public { // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(this), 100 ether); managedBudget.allocate{value: 100 ether}(data); // Ensure the budget has 100 tokens @@ -177,9 +153,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { assetType: Budget.AssetType.ERC1155, asset: address(mockERC1155), target: address(this), - data: abi.encode( - Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""}) - ) + data: abi.encode(Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""})) }) ); assertTrue(managedBudget.allocate(data)); @@ -190,42 +164,20 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testAllocate_NativeBalanceValueMismatch() public { // Encode an allocation of 100 ETH - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(this), 100 ether); // Expect a revert due to a value mismatch (too much ETH) - vm.expectRevert( - abi.encodeWithSelector( - Budget.InvalidAllocation.selector, - address(0), - uint256(100 ether) - ) - ); + vm.expectRevert(abi.encodeWithSelector(Budget.InvalidAllocation.selector, address(0), uint256(100 ether))); managedBudget.allocate{value: 101 ether}(data); // Expect a revert due to a value mismatch (too little ETH) - vm.expectRevert( - abi.encodeWithSelector( - Budget.InvalidAllocation.selector, - address(0), - uint256(100 ether) - ) - ); + vm.expectRevert(abi.encodeWithSelector(Budget.InvalidAllocation.selector, address(0), uint256(100 ether))); managedBudget.allocate{value: 99 ether}(data); } function testAllocate_NoApproval() public { // Allocate 100 tokens to the budget without approval - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); vm.expectRevert(SafeTransferLib.TransferFromFailed.selector); managedBudget.allocate(data); } @@ -235,12 +187,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 101 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 101 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 101 ether); vm.expectRevert(SafeTransferLib.TransferFromFailed.selector); managedBudget.allocate(data); } @@ -266,22 +213,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.available(address(mockERC20)), 100 ether); // Reclaim 99 tokens from the budget - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 99 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 99 ether); assertTrue(managedBudget.reclaim(data)); // Ensure the budget has 1 token left @@ -290,22 +227,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testReclaim_NativeBalance() public { // Allocate 100 ETH to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(this), 100 ether); managedBudget.allocate{value: 100 ether}(data); assertEq(managedBudget.available(address(0)), 100 ether); // Reclaim 99 ETH from the budget - data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(1), - 99 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(1), 99 ether); assertTrue(managedBudget.reclaim(data)); // Ensure the budget has 1 ETH left @@ -322,9 +249,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { assetType: Budget.AssetType.ERC1155, asset: address(mockERC1155), target: address(this), - data: abi.encode( - Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""}) - ) + data: abi.encode(Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""})) }) ); managedBudget.allocate(data); @@ -336,9 +261,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { assetType: Budget.AssetType.ERC1155, asset: address(mockERC1155), target: address(this), - data: abi.encode( - Budget.ERC1155Payload({tokenId: 42, amount: 99, data: ""}) - ) + data: abi.encode(Budget.ERC1155Payload({tokenId: 42, amount: 99, data: ""})) }) ); assertTrue(managedBudget.reclaim(data)); @@ -352,22 +275,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.available(address(mockERC20)), 100 ether); // Reclaim all tokens from the budget - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 0 - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 0); assertTrue(managedBudget.reclaim(data)); // Ensure the budget has no tokens left @@ -379,29 +292,14 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.available(address(mockERC20)), 100 ether); // Reclaim 100 tokens from the budget to address(0) - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(0), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(0), 100 ether); vm.expectRevert( - abi.encodeWithSelector( - Budget.TransferFailed.selector, - address(mockERC20), - address(0), - uint256(100 ether) - ) + abi.encodeWithSelector(Budget.TransferFailed.selector, address(mockERC20), address(0), uint256(100 ether)) ); managedBudget.reclaim(data); @@ -414,28 +312,15 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Reclaim 101 tokens from the budget - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 101 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 101 ether); vm.expectRevert( abi.encodeWithSelector( - Budget.InsufficientFunds.selector, - address(mockERC20), - uint256(100 ether), - uint256(101 ether) + Budget.InsufficientFunds.selector, address(mockERC20), uint256(100 ether), uint256(101 ether) ) ); managedBudget.reclaim(data); @@ -448,12 +333,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); @@ -468,12 +348,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); @@ -495,12 +370,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); @@ -522,12 +392,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); @@ -546,22 +411,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Disburse 100 tokens from the budget to the recipient - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(1), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(1), 100 ether); assertTrue(managedBudget.disburse(data)); assertEq(mockERC20.balanceOf(address(1)), 100 ether); @@ -572,21 +427,11 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testDisburse_NativeBalance() public { // Allocate 100 ETH to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(this), 100 ether); managedBudget.allocate{value: 100 ether}(data); // Disburse 100 ETH from the budget to the recipient - data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(1), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(1), 100 ether); assertTrue(managedBudget.disburse(data)); assertEq(address(1).balance, 100 ether); @@ -605,9 +450,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { assetType: Budget.AssetType.ERC1155, asset: address(mockERC1155), target: address(this), - data: abi.encode( - Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""}) - ) + data: abi.encode(Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""})) }) ); managedBudget.allocate(data); @@ -619,9 +462,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { assetType: Budget.AssetType.ERC1155, asset: address(mockERC1155), target: address(1), - data: abi.encode( - Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""}) - ) + data: abi.encode(Budget.ERC1155Payload({tokenId: 42, amount: 100, data: ""})) }) ); assertTrue(managedBudget.disburse(data)); @@ -639,55 +480,21 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Allocate the assets to the budget managedBudget.allocate( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 50 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 50 ether) ); managedBudget.allocate{value: 25 ether}( - _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(this), - 25 ether - ) - ); - managedBudget.allocate( - _makeERC1155Transfer( - address(mockERC1155), - address(this), - 42, - 50, - bytes("") - ) + _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(this), 25 ether) ); + managedBudget.allocate(_makeERC1155Transfer(address(mockERC1155), address(this), 42, 50, bytes(""))); assertEq(managedBudget.total(address(mockERC20)), 50 ether); assertEq(managedBudget.total(address(0)), 25 ether); assertEq(managedBudget.total(address(mockERC1155), 42), 50); // Prepare the disbursement requests bytes[] memory requests = new bytes[](3); - requests[0] = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(1), - 25 ether - ); - requests[1] = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(2), - 25 ether - ); - requests[2] = _makeERC1155Transfer( - address(mockERC1155), - address(3), - 42, - 10, - bytes("") - ); + requests[0] = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(1), 25 ether); + requests[1] = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(2), 25 ether); + requests[2] = _makeERC1155Transfer(address(mockERC1155), address(3), 42, 10, bytes("")); // Disburse: // 25 tokens to address(1); and @@ -713,28 +520,15 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Disburse 101 tokens from the budget to the recipient - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(1), - 101 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(1), 101 ether); vm.expectRevert( abi.encodeWithSelector( - Budget.InsufficientFunds.selector, - address(mockERC20), - uint256(100 ether), - uint256(101 ether) + Budget.InsufficientFunds.selector, address(mockERC20), uint256(100 ether), uint256(101 ether) ) ); managedBudget.disburse(data); @@ -747,12 +541,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); @@ -767,22 +556,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Try to disburse 100 tokens from the budget as a non-owner - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(0xdeadbeef), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(0xdeadbeef), 100 ether); vm.prank(address(0xc0ffee)); vm.expectRevert(); managedBudget.disburse(data); @@ -799,22 +578,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Try to disburse 100 tokens from the budget as a non-owner - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(0xdeadbeef), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(0xdeadbeef), 100 ether); vm.prank(address(0xdeadbeef)); managedBudget.disburse(data); } @@ -830,22 +599,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Try to disburse 100 tokens from the budget as a non-owner - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(0xdeadbeef), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(0xdeadbeef), 100 ether); vm.prank(address(0xdeadbeef)); managedBudget.disburse(data); } @@ -855,33 +614,19 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Mock the ERC20 transfer to fail in an unexpected way vm.mockCallRevert( address(mockERC20), - abi.encodeWithSelector( - bytes4(keccak256("transfer(address,uint256)")), - address(1), - 100 ether - ), + abi.encodeWithSelector(bytes4(keccak256("transfer(address,uint256)")), address(1), 100 ether), unicode"WeïrdÊrrör(ツ)" ); // Try to disburse 100 tokens from the budget - data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(1), - 100 ether - ); + data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(1), 100 ether); vm.expectRevert(SafeTransferLib.TransferFailed.selector); managedBudget.disburse(data); } @@ -891,44 +636,20 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { mockERC20.approve(address(managedBudget), 100 ether); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether); managedBudget.allocate(data); assertEq(managedBudget.total(address(mockERC20)), 100 ether); // Prepare the disbursement data bytes[] memory requests = new bytes[](3); - requests[0] = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(1), - 25 ether - ); - requests[1] = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(2), - 50 ether - ); - requests[2] = _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(3), - 10 ether - ); + requests[0] = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(1), 25 ether); + requests[1] = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(2), 50 ether); + requests[2] = _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(3), 10 ether); // Mock the second ERC20 transfer to fail in an unexpected way vm.mockCallRevert( address(mockERC20), - abi.encodeWithSelector( - bytes4(keccak256("transfer(address,uint256)")), - address(2), - 50 ether - ), + abi.encodeWithSelector(bytes4(keccak256("transfer(address,uint256)")), address(2), 50 ether), unicode"WeïrdÊrrör(ツ)" ); @@ -948,12 +669,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Allocate 100 tokens to the budget mockERC20.approve(address(managedBudget), 100 ether); managedBudget.allocate( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether) ); // Ensure the budget has 100 tokens @@ -965,12 +681,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { assertEq(managedBudget.total(address(0)), 0); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(this), 100 ether); managedBudget.allocate{value: 100 ether}(data); // Ensure the budget has 100 tokens @@ -983,32 +694,15 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Allocate 50 tokens to the budget managedBudget.allocate( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 50 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 50 ether) ); // Disburse 25 tokens from the budget to the recipient - managedBudget.disburse( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(1), - 25 ether - ) - ); + managedBudget.disburse(_makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(1), 25 ether)); // Allocate another 50 tokens to the budget managedBudget.allocate( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 50 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 50 ether) ); // Ensure the budget has 50 - 25 + 50 = 75 tokens @@ -1032,12 +726,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Allocate 100 tokens to the budget mockERC20.approve(address(managedBudget), 100 ether); managedBudget.allocate( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether) ); // Ensure the budget has 100 tokens available @@ -1049,12 +738,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { assertEq(managedBudget.available(address(0)), 0); // Allocate 100 tokens to the budget - bytes memory data = _makeFungibleTransfer( - Budget.AssetType.ETH, - address(0), - address(this), - 100 ether - ); + bytes memory data = _makeFungibleTransfer(Budget.AssetType.ETH, address(0), address(this), 100 ether); managedBudget.allocate{value: 100 ether}(data); // Ensure the budget has 100 tokens available @@ -1077,22 +761,12 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Allocate 100 tokens to the budget mockERC20.approve(address(managedBudget), 100 ether); managedBudget.allocate( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether) ); // Disburse 50 tokens from the budget to the recipient managedBudget.disburse( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 50 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 50 ether) ); // Ensure the budget has 50 tokens distributed @@ -1100,12 +774,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Disburse 25 more tokens from the budget to the recipient managedBudget.disburse( - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 25 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 25 ether) ); // Ensure the budget has 75 tokens distributed @@ -1134,17 +803,9 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { accounts[1] = address(0xaaaa); authorized[1] = managedBudget.ADMIN_ROLE(); managedBudget.grantRoles(accounts, authorized); + assertTrue(managedBudget.hasAllRoles(address(0xc0ffee), managedBudget.MANAGER_ROLE())); assertTrue( - managedBudget.hasAllRoles( - address(0xc0ffee), - managedBudget.MANAGER_ROLE() - ) - ); - assertTrue( - managedBudget.hasAllRoles( - address(0xaaaa), - managedBudget.MANAGER_ROLE() & managedBudget.ADMIN_ROLE() - ) + managedBudget.hasAllRoles(address(0xaaaa), managedBudget.MANAGER_ROLE() & managedBudget.ADMIN_ROLE()) ); assertFalse(managedBudget.isAuthorized(address(0xdeadbeef))); } @@ -1217,31 +878,15 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { accounts[1] = address(0xaaaa); authorized[1] = managedBudget.ADMIN_ROLE(); managedBudget.grantRoles(accounts, authorized); + assertTrue(managedBudget.hasAllRoles(address(0xc0ffee), managedBudget.MANAGER_ROLE())); assertTrue( - managedBudget.hasAllRoles( - address(0xc0ffee), - managedBudget.MANAGER_ROLE() - ) - ); - assertTrue( - managedBudget.hasAllRoles( - address(0xaaaa), - managedBudget.MANAGER_ROLE() & managedBudget.ADMIN_ROLE() - ) + managedBudget.hasAllRoles(address(0xaaaa), managedBudget.MANAGER_ROLE() & managedBudget.ADMIN_ROLE()) ); assertFalse(managedBudget.isAuthorized(address(0xdeadbeef))); managedBudget.revokeRoles(accounts, authorized); + assertFalse(managedBudget.hasAllRoles(address(0xc0ffee), managedBudget.MANAGER_ROLE())); assertFalse( - managedBudget.hasAllRoles( - address(0xc0ffee), - managedBudget.MANAGER_ROLE() - ) - ); - assertFalse( - managedBudget.hasAnyRole( - address(0xaaaa), - managedBudget.ADMIN_ROLE() | managedBudget.MANAGER_ROLE() - ) + managedBudget.hasAnyRole(address(0xaaaa), managedBudget.ADMIN_ROLE() | managedBudget.MANAGER_ROLE()) ); } @@ -1407,9 +1052,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testSupportsERC1155Receiver() public { // Ensure the contract supports the Budget interface - assertTrue( - managedBudget.supportsInterface(type(IERC1155Receiver).interfaceId) - ); + assertTrue(managedBudget.supportsInterface(type(IERC1155Receiver).interfaceId)); } function testSupportsERC165() public { @@ -1428,7 +1071,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testFallback() public { // Ensure the fallback is payable - (bool success, ) = payable(managedBudget).call{value: 1 ether}(""); + (bool success,) = payable(managedBudget).call{value: 1 ether}(""); assertTrue(success); } @@ -1439,15 +1082,10 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Allocate 100 tokens to the budget bytes memory data = abi.encodeWithSelector( AManagedBudget.allocate.selector, - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether) ); - (bool success, ) = payable(managedBudget).call(data); + (bool success,) = payable(managedBudget).call(data); assertTrue(success, "Fallback function failed"); // Ensure the budget has 100 tokens @@ -1464,15 +1102,10 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Note that the function itself will revert, but because we're issuing // a low-level call, the revert won't bubble up. Instead, we are just // checking that the low-level call was not successful. - (bool success, ) = payable(managedBudget).call{value: 1 ether}( + (bool success,) = payable(managedBudget).call{value: 1 ether}( abi.encodeWithSelector( bytes4(0xdeadbeef), - _makeFungibleTransfer( - Budget.AssetType.ERC20, - address(mockERC20), - address(this), - 100 ether - ) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), 100 ether) ) ); assertFalse(success); @@ -1484,7 +1117,7 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { function testReceive() public { // Ensure the receive function catches non-fallback ETH transfers - (bool success, ) = payable(managedBudget).call{value: 1 ether}(""); + (bool success,) = payable(managedBudget).call{value: 1 ether}(""); assertTrue(success); assertEq(managedBudget.available(address(0)), 1 ether); } @@ -1493,72 +1126,58 @@ contract ManagedBudgetTest is Test, IERC1155Receiver { // Test Helper Functions // /////////////////////////// - function _makeFungibleTransfer( - Budget.AssetType assetType, - address asset, - address target, - uint256 value - ) internal pure returns (bytes memory) { + function _makeFungibleTransfer(Budget.AssetType assetType, address asset, address target, uint256 value) + internal + pure + returns (bytes memory) + { Budget.Transfer memory transfer; transfer.assetType = assetType; transfer.asset = asset; transfer.target = target; - if ( - assetType == Budget.AssetType.ETH || - assetType == Budget.AssetType.ERC20 - ) { + if (assetType == Budget.AssetType.ETH || assetType == Budget.AssetType.ERC20) { transfer.data = abi.encode(Budget.FungiblePayload({amount: value})); } else if (assetType == Budget.AssetType.ERC1155) { // we're not actually handling this case yet, so hardcoded token ID of 1 is fine - transfer.data = abi.encode( - Budget.ERC1155Payload({tokenId: 1, amount: value, data: ""}) - ); + transfer.data = abi.encode(Budget.ERC1155Payload({tokenId: 1, amount: value, data: ""})); } return abi.encode(transfer); } - function _makeERC1155Transfer( - address asset, - address target, - uint256 tokenId, - uint256 value, - bytes memory data - ) internal pure returns (bytes memory) { + function _makeERC1155Transfer(address asset, address target, uint256 tokenId, uint256 value, bytes memory data) + internal + pure + returns (bytes memory) + { Budget.Transfer memory transfer; transfer.assetType = Budget.AssetType.ERC1155; transfer.asset = asset; transfer.target = target; - transfer.data = abi.encode( - Budget.ERC1155Payload({tokenId: tokenId, amount: value, data: data}) - ); + transfer.data = abi.encode(Budget.ERC1155Payload({tokenId: tokenId, amount: value, data: data})); return abi.encode(transfer); } - function onERC1155Received( - address, - address, - uint256, - uint256, - bytes calldata - ) external pure override returns (bytes4) { + function onERC1155Received(address, address, uint256, uint256, bytes calldata) + external + pure + override + returns (bytes4) + { return IERC1155Receiver.onERC1155Received.selector; } - function onERC1155BatchReceived( - address, - address, - uint256[] calldata, - uint256[] calldata, - bytes calldata - ) external pure override returns (bytes4) { + function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata) + external + pure + override + returns (bytes4) + { return IERC1155Receiver.onERC1155BatchReceived.selector; } - function supportsInterface( - bytes4 interfaceId - ) external pure returns (bool) { + function supportsInterface(bytes4 interfaceId) external pure returns (bool) { return interfaceId == type(IERC1155Receiver).interfaceId; } }