Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/echidna additional tests #172

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion contracts/OptionsContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract OptionsContract is Ownable, ERC20 {

mapping(address => Vault) internal vaults;

address payable[] public vaultOwners;
address payable[] private vaultOwners;

// 10 is 0.01 i.e. 1% incentive.
Number public liquidationIncentive = Number(10, -3);
Expand Down Expand Up @@ -226,6 +226,13 @@ contract OptionsContract is Ownable, ERC20 {
return vaultOwners.length;
}

/**
* @notice This function returns all the vault owners
*/
function getVaultOwners() external view returns (address payable[] memory) {
return vaultOwners;
}

/**
* @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.
Expand Down
52 changes: 52 additions & 0 deletions contracts/echidna/EchidnaOptionsContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,56 @@ contract EchidnaOptionsContract is TestOptionsContract {
{
return minCollateralizationRatio.value >= 10;
}

function echidna_vault_collateral_sum() public view returns (bool) {
uint256 collateralSum = 0;
if (vaultOwners.length > 0) {
for (uint256 i = 0; i < vaultOwners.length; i++) {
Vault memory vault = vaults[vaultOwners[i]];
collateralSum = collateralSum.add(vault.collateral);
}
}

uint256 collateralBalance = 0;
if (isETH(collateral)) {
collateralBalance = address(this).balance;
} else {
collateralBalance = collateral.balanceOf(address(this));
}
return collateralBalance == collateralSum;
}

function echidna_vault_oTokens_sum() public view returns (bool) {
uint256 oTokensSum = 0;
if (vaultOwners.length > 0) {
for (uint256 i = 0; i < vaultOwners.length; i++) {
Vault memory vault = vaults[vaultOwners[i]];
oTokensSum = oTokensSum.add(vault.oTokensIssued);
}
}

return oTokensSum == totalSupply();
}

function echidna_vault_underlying_sum() public view returns (bool) {
uint256 underlyingSum = 0;
if (vaultOwners.length > 0) {
for (uint256 i = 0; i < vaultOwners.length; i++) {
Vault memory vault = vaults[vaultOwners[i]];
underlyingSum = underlyingSum.add(vault.underlying);
}
}

uint256 underlyingBalance = 0;
if (isETH(underlying)) {
underlyingBalance = address(this).balance;
} else {
underlyingBalance = underlying.balanceOf(address(this));
}
return underlyingBalance == underlyingSum;
}

function echidna_test_should_fail() public view returns (bool) {
return collateral.balanceOf(address(this)) == 0;
}
}
3 changes: 2 additions & 1 deletion contracts/echidna/contracts/TestOptionsContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ contract TestOptionsContract is Ownable, ERC20 {

IERC20 _collateral = IERC20(usdc);
int32 _collExp = -6;
IERC20 _underlying = IERC20(address(new ERC20()));
// IERC20 _underlying = IERC20(address(new ERC20()));
IERC20 _underlying = IERC20(address(0));
int32 _underlyingExp = -18;
int32 _oTokenExchangeExp = -6;
uint256 _strikePrice = 25;
Expand Down
9 changes: 9 additions & 0 deletions test/optionsContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ contract('OptionsContract', accounts => {
});

describe('#openVault()', () => {
it('there should be no vault owners before opening any vaults', async () => {
const vaultOwners = await optionsContracts[0].getVaultOwners();
expect(vaultOwners.toString()).to.equal('');
});
it('should open first vault correctly', async () => {
const result = await optionsContracts[0].openVault({
from: creatorAddress
Expand Down Expand Up @@ -398,6 +402,11 @@ contract('OptionsContract', accounts => {
expect(vault['1'].toString()).to.equal('0');
expect(vault['2'].toString()).to.equal('0');
expect(vault['3']).to.equal(true);

// test getVaultOwners
const vaultOwners = await optionsContracts[0].getVaultOwners();
expect(vaultOwners[0].toString()).to.equal(creatorAddress);
expect(vaultOwners[1].toString()).to.equal(firstOwnerAddress);
});
});

Expand Down