Skip to content

adding test cases to check math overflow #183

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

Open
wants to merge 1 commit 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
20 changes: 20 additions & 0 deletions test/series/bal-put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,25 @@ contract('OptionsContract: BAL put', accounts => {
// check underlying In the vault
assert.equal(vault[2].toString(), underlyingRequired);
});

it('exponents should not overflow', async () => {
const strikePrice = await oToken.strikePrice();
const strikeExponent = strikePrice[1];
const colalteralExponent = await oToken.collateralExp();
const collateralToPayExponent = Math.max(
Math.abs(strikeExponent - colalteralExponent),
Math.abs(strikeExponent - colalteralExponent - 3)
);

assert(collateralToPayExponent <= 9, 'overflow possibility');

const oTokenExchangeExponent = await oToken.oTokenExchangeRate();
const underlingExponent = await oToken.underlyingExp();

assert(
Math.abs(oTokenExchangeExponent[1] - underlingExponent) <= 19,
'overflow possiblitiy'
);
});
});
});
20 changes: 20 additions & 0 deletions test/series/comp-put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,25 @@ contract('OptionsContract: COMP put', accounts => {
assert.equal(vault[1].toString(), '0');
assert.equal(vault[2].toString(), underlyingRequired);
});

it('exponents should not overflow', async () => {
const strikePrice = await oComp.strikePrice();
const strikeExponent = strikePrice[1];
const colalteralExponent = await oComp.collateralExp();
const collateralToPayExponent = Math.max(
Math.abs(strikeExponent - colalteralExponent),
Math.abs(strikeExponent - colalteralExponent - 3)
);

assert(collateralToPayExponent <= 9, 'overflow possibility');

const oTokenExchangeExponent = await oComp.oTokenExchangeRate();
const underlingExponent = await oComp.underlyingExp();

assert(
Math.abs(oTokenExchangeExponent[1] - underlingExponent) <= 19,
'overflow possiblitiy'
);
});
});
});
20 changes: 20 additions & 0 deletions test/series/eth-put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,25 @@ contract('OptionsContract: ETH put', accounts => {
vaultOwner: firstOwner
});
});

it('exponents should not overflow', async () => {
const strikePrice = await oETH.strikePrice();
const strikeExponent = strikePrice[1];
const colalteralExponent = await oETH.collateralExp();
const collateralToPayExponent = Math.max(
Math.abs(strikeExponent - colalteralExponent),
Math.abs(strikeExponent - colalteralExponent - 3)
);

assert(collateralToPayExponent <= 9, 'overflow possibility');

const oTokenExchangeExponent = await oETH.oTokenExchangeRate();
const underlingExponent = await oETH.underlyingExp();

assert(
Math.abs(oTokenExchangeExponent[1] - underlingExponent) <= 19,
'overflow possiblitiy'
);
});
});
});
4 changes: 2 additions & 2 deletions test/utils/FactoryEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function AssetAdded(params: { asset: string; addr: string }) {
export function AssetAdded(params: {asset: string; addr: string}) {
return {
event: 'AssetAdded',
args: {
Expand All @@ -8,7 +8,7 @@ export function AssetAdded(params: { asset: string; addr: string }) {
};
}

export function ContractCreated(params: { addr: string }) {
export function ContractCreated(params: {addr: string}) {
return {
event: 'ContractCreated',
args: {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/OptionContractEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function RepoOpened(params: { addr: string }) {
export function RepoOpened(params: {addr: string}) {
return {
event: 'RepoOpened',
args: {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/reverter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Web3 from 'web3';
import { HttpProvider } from 'web3-core';
import {HttpProvider} from 'web3-core';

export default class Reverter {
// Web3 instance
Expand Down