Skip to content

Commit

Permalink
test: fix Module unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Nov 22, 2023
1 parent 310297f commit fad90f9
Showing 1 changed file with 61 additions and 83 deletions.
144 changes: 61 additions & 83 deletions solidity/test/unit/modules/Module.t.sol
Original file line number Diff line number Diff line change
@@ -1,83 +1,61 @@
// // SPDX-License-Identifier: MIT
// pragma solidity ^0.8.19;

// import 'forge-std/Test.sol';

// import {Module, IModule} from '../../../contracts/Module.sol';
// import {IOracle} from '../../../interfaces/IOracle.sol';

// /**
// * @dev Harness to deploy the abstract contract
// */
// contract ForTest_Module is Module {
// constructor(IOracle _oracle) Module(_oracle) {}

// function moduleName() external pure returns (string memory _moduleName) {
// return 'abstractModule';
// }
// }

// /**
// * @title Module Abstract Unit tests
// */
// contract Module_UnitTest is Test {
// // The target contract
// Module public module;

// // A mock oracle
// IOracle public oracle;

// /**
// * @notice Deploy the target and mock oracle extension
// */
// function setUp() public {
// oracle = IOracle(makeAddr('Oracle'));
// vm.etch(address(oracle), hex'069420');

// module = new ForTest_Module(oracle);
// }

// /**
// * @notice Test that setupRequestData stores the data
// */
// function test_decodeRequestData(bytes32 _requestId, bytes calldata _data) public {
// // Set the request data
// vm.prank(address(oracle));
// module.setupRequest(_requestId, _data);

// // Check: decoded values match original values?
// assertEq(module.requestData(_requestId), _data);
// }

// /**
// * @notice Test that setupRequestData reverts if the oracle is not the caller
// */
// function test_setupRequestRevertsWhenCalledByNonOracle(bytes32 _requestId, bytes calldata _data) public {
// vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector));
// // Set the request data
// module.setupRequest(_requestId, _data);
// }

// /**
// * @notice Test if finalizeRequest can only be called by the oracle
// */
// function test_finalizeRequestOnlyOracle(bytes32 _requestId, address _caller) public {
// vm.assume(_caller != address(oracle));

// // Check: reverts if not called by oracle?
// vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector));
// vm.prank(_caller);
// module.finalizeRequest(_requestId, address(_caller));

// // Check: does not revert if called by oracle
// vm.prank(address(oracle));
// module.finalizeRequest(_requestId, address(oracle));
// }

// /**
// * @notice Test that the moduleName function returns the correct name
// */
// function test_moduleNameReturnsName() public {
// assertEq(module.moduleName(), 'abstractModule');
// }
// }
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import 'forge-std/Test.sol';

import {Module, IModule} from '../../../contracts/Module.sol';
import {IOracle} from '../../../interfaces/IOracle.sol';
import {Helpers} from '../../utils/Helpers.sol';

/**
* @dev Harness to deploy the abstract contract
*/
contract ForTest_Module is Module {
constructor(IOracle _oracle) Module(_oracle) {}

function moduleName() external pure returns (string memory _moduleName) {
return 'AbstractModule';
}
}

/**
* @title Module Abstract Unit tests
*/
contract Module_UnitTest is Test, Helpers {
// The target contract
Module public module;

// A mock oracle
IOracle public oracle;

/**
* @notice Deploy the target and mock oracle extension
*/
function setUp() public {
oracle = IOracle(_mockContract('Oracle'));
module = new ForTest_Module(oracle);
}

/**
* @notice Test if finalizeRequest can only be called by the oracle
*/
function test_finalizeRequest_onlyOracle(address _caller) public {
vm.assume(_caller != address(oracle));

// Check: reverts if not called by oracle?
vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector));
vm.prank(_caller);
module.finalizeRequest(mockRequest, mockResponse, _caller);

// Check: does not revert if called by oracle
vm.prank(address(oracle));
module.finalizeRequest(mockRequest, mockResponse, address(oracle));
}

/**
* @notice Test that the moduleName function returns the correct name
*/
function test_moduleName_returnsName() public {
assertEq(module.moduleName(), 'AbstractModule');
}
}

0 comments on commit fad90f9

Please sign in to comment.