Skip to content

Commit

Permalink
Refactor v1 tests folder structure (#137)
Browse files Browse the repository at this point in the history
* Remove gas option to avoid coverage failure

* Update cicd script

* Move interfaces to interfaces/ (#139)

* Enable coverage

* WIP refactor tests (#138)

* Create helper file for common functions

* Unify describe message for all option parameter tests

* Put new series test into folder series/
  • Loading branch information
antoncoding authored Aug 7, 2020
1 parent 4bbc898 commit aab6a54
Show file tree
Hide file tree
Showing 37 changed files with 835 additions and 1,025 deletions.
54 changes: 37 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
version: 2.1
#orbs:
# coveralls: coveralls/[email protected]
orbs:
coveralls: coveralls/[email protected]

workflows:
build-test-report:
jobs:
- build
- test:
requires:
- build

jobs:
build:
working_directory: ~/optionsprotocol
docker:
- image: circleci/node:10.18.0
- image: trufflesuite/ganache-cli:v6.7.0
command: ganache-cli --deterministic -e 300 -p 8545 -m 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat' --accounts 30 --allowUnlimitedContractSize
steps:
- checkout
- restore_cache:
Expand All @@ -18,6 +25,23 @@ jobs:
- run:
name: Lint Contracts
command: npm run lint:sol
- run:
name: Build types
command: npm run build
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
test:
working_directory: ~/optionsprotocol
docker:
- image: circleci/node:10.18.0
- image: trufflesuite/ganache-cli:v6.7.0
command: ganache-cli --deterministic -e 300 -p 8545 -m 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat' --accounts 30 --allowUnlimitedContractSize
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Deploy Contracts
command: npm run deploy:development
Expand All @@ -27,17 +51,13 @@ jobs:
- store_artifacts:
path: /test_output
# NOTE -> This requires a paid CircleCI plan to increase the RAM size up to 6/8GB. Fails at current
#- run:
# name: Produce Coverage Report
# command: npm run coverage
#- coveralls/upload
#- store_artifacts:
# path: /coverage
#- store_artifacts:
# path: /.coverage.json
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules

- run:
name: Produce Coverage Report
command: npm run coverage
- coveralls/upload
- store_artifacts:
path: /coverage
- store_artifacts:
path: /.coverage.json


3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build/
flattened/
.idea
secret.js
coverage/
coverage/
coverage.json
2 changes: 2 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = {
copyPackages: ['openzeppelin'],
skipFiles: [
'Migrations.sol',
'lib/MockCompoundOracle.sol',
'lib/MockUniswapFactory.sol',
]
};

11 changes: 5 additions & 6 deletions contracts/OptionsContract.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
pragma solidity 0.5.10;

import "./lib/CompoundOracleInterface.sol";
import "./interfaces/CompoundOracleInterface.sol";
import "./interfaces/UniswapFactoryInterface.sol";
import "./interfaces/UniswapExchangeInterface.sol";
import "./OptionsExchange.sol";
import "./OptionsUtils.sol";
import "./lib/UniswapFactoryInterface.sol";
import "./lib/UniswapExchangeInterface.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
Expand Down Expand Up @@ -228,7 +227,7 @@ contract OptionsContract is Ownable, ERC20 {
}

/**
* @notice Can only be called by owner. Used to update the fees, minminCollateralizationRatio, etc
* @notice Can only be called by owner. Used to update the fees, minCollateralizationRatio, etc
* @param _liquidationIncentive The incentive paid to liquidator. 10 is 0.01 i.e. 1% incentive.
* @param _liquidationFactor Max amount that a Vault can be liquidated by. 500 is 0.5.
* @param _transactionFee The fees paid to our protocol every time a execution happens. 100 is egs. 0.1 i.e. 10%.
Expand Down Expand Up @@ -463,7 +462,7 @@ contract OptionsContract is Ownable, ERC20 {
* issue and immidiately sell the oTokens! (Either call the createAndSell function in the oToken contract
* of batch the issueOTokens transaction with a sell transaction and ensure it happens atomically).
* @dev The owner of a Vault should only be able to have a max of
* repo.collateral * collateralToStrike / (minminCollateralizationRatio * strikePrice) tokens issued.
* repo.collateral * collateralToStrike / (minCollateralizationRatio * strikePrice) tokens issued.
* @param oTokensToIssue The number of o tokens to issue
* @param receiver The address to send the oTokens to
*/
Expand Down
7 changes: 3 additions & 4 deletions contracts/OptionsExchange.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
pragma solidity 0.5.10;

import "./lib/CompoundOracleInterface.sol";
import "./OptionsUtils.sol";
import "./lib/UniswapFactoryInterface.sol";
import "./lib/UniswapExchangeInterface.sol";
import "./interfaces/CompoundOracleInterface.sol";
import "./interfaces/UniswapFactoryInterface.sol";
import "./interfaces/UniswapExchangeInterface.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";


Expand Down
1 change: 0 additions & 1 deletion contracts/OptionsFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pragma solidity 0.5.10;

import "./OptionsContract.sol";
import "./oToken.sol";
import "./OptionsUtils.sol";
import "./lib/StringComparator.sol";
import "@openzeppelin/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand Down
6 changes: 3 additions & 3 deletions contracts/OptionsUtils.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pragma solidity 0.5.10;

import "./lib/CompoundOracleInterface.sol";
import "./lib/UniswapExchangeInterface.sol";
import "./lib/UniswapFactoryInterface.sol";
import "./interfaces/CompoundOracleInterface.sol";
import "./interfaces/UniswapExchangeInterface.sol";
import "./interfaces/UniswapFactoryInterface.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";


Expand Down
4 changes: 2 additions & 2 deletions contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pragma solidity 0.5.10;

import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./lib/CompoundOracleInterface.sol";
import "./lib/CTokenInterface.sol";
import "./interfaces/CompoundOracleInterface.sol";
import "./interfaces/CTokenInterface.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";


Expand Down
61 changes: 61 additions & 0 deletions contracts/interfaces/CTokenInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pragma solidity ^0.5.10;


contract CTokenInterface {
/*** User Interface ***/
address public underlying;
uint256 public initialExchangeRateMantissa;

function transfer(address dst, uint256 amount) external returns (bool);

function transferFrom(
address src,
address dst,
uint256 amount
) external returns (bool);

function approve(address spender, uint256 amount) external returns (bool);

function allowance(address owner, address spender)
external
view
returns (uint256);

function balanceOf(address owner) external view returns (uint256);

function balanceOfUnderlying(address owner) external returns (uint256);

function getAccountSnapshot(address account)
external
view
returns (
uint256,
uint256,
uint256,
uint256
);

function borrowRatePerBlock() external view returns (uint256);

function supplyRatePerBlock() external view returns (uint256);

function totalBorrowsCurrent() external returns (uint256);

function borrowBalanceCurrent(address account) external returns (uint256);

function borrowBalanceStored(address account) public view returns (uint256);

function exchangeRateCurrent() public returns (uint256);

function exchangeRateStored() public view returns (uint256);

function getCash() external view returns (uint256);

function accrueInterest() public returns (uint256);

function seize(
address liquidator,
address borrower,
uint256 seizeTokens
) external returns (uint256);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
pragma solidity ^0.5.0;
pragma solidity ^0.5.10;
// AT MAINNET ADDRESS: 0x02557a5E05DeFeFFD4cAe6D83eA3d173B272c904
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";


contract CompoundOracleInterface {
// returns asset:eth -- to get USDC:eth, have to do 10**24/result,


constructor() public {
}
constructor() public {}

/**
* @notice retrieves price of an asset
* @dev function to get price for an asset
* @param asset Asset for which to get the price
* @return uint mantissa of asset price (scaled by 1e18) or zero if unset or contract paused
*/
function getPrice(address asset) public view returns (uint);
function getUnderlyingPrice(ERC20 cToken) public view returns (uint);
* @notice retrieves price of an asset
* @dev function to get price for an asset
* @param asset Asset for which to get the price
* @return uint mantissa of asset price (scaled by 1e18) or zero if unset or contract paused
*/
function getPrice(address asset) public view returns (uint256);

function getUnderlyingPrice(ERC20 cToken) public view returns (uint256);
// function getPrice(address asset) public view returns (uint) {
// return 527557000000000;
// }

}
Loading

0 comments on commit aab6a54

Please sign in to comment.