From 7c3c9c67259bc65a2261df7bd1405e23084800c0 Mon Sep 17 00:00:00 2001 From: aparnakr Date: Wed, 2 Sep 2020 17:29:52 -0700 Subject: [PATCH] adding test cases to check math overflow --- test/series/bal-put.test.ts | 20 ++++++++++++++++++++ test/series/comp-put.test.ts | 20 ++++++++++++++++++++ test/series/eth-put.test.ts | 20 ++++++++++++++++++++ test/utils/FactoryEvents.ts | 4 ++-- test/utils/OptionContractEvents.ts | 2 +- test/utils/reverter.ts | 2 +- 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/test/series/bal-put.test.ts b/test/series/bal-put.test.ts index 4bd7b39..1f3359a 100644 --- a/test/series/bal-put.test.ts +++ b/test/series/bal-put.test.ts @@ -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' + ); + }); }); }); diff --git a/test/series/comp-put.test.ts b/test/series/comp-put.test.ts index 08852b1..7434fc6 100644 --- a/test/series/comp-put.test.ts +++ b/test/series/comp-put.test.ts @@ -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' + ); + }); }); }); diff --git a/test/series/eth-put.test.ts b/test/series/eth-put.test.ts index 2be95ef..1931e0d 100644 --- a/test/series/eth-put.test.ts +++ b/test/series/eth-put.test.ts @@ -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' + ); + }); }); }); diff --git a/test/utils/FactoryEvents.ts b/test/utils/FactoryEvents.ts index 09c72ef..ee7e882 100644 --- a/test/utils/FactoryEvents.ts +++ b/test/utils/FactoryEvents.ts @@ -1,4 +1,4 @@ -export function AssetAdded(params: { asset: string; addr: string }) { +export function AssetAdded(params: {asset: string; addr: string}) { return { event: 'AssetAdded', args: { @@ -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: { diff --git a/test/utils/OptionContractEvents.ts b/test/utils/OptionContractEvents.ts index 5b89444..0047eb0 100644 --- a/test/utils/OptionContractEvents.ts +++ b/test/utils/OptionContractEvents.ts @@ -1,4 +1,4 @@ -export function RepoOpened(params: { addr: string }) { +export function RepoOpened(params: {addr: string}) { return { event: 'RepoOpened', args: { diff --git a/test/utils/reverter.ts b/test/utils/reverter.ts index d363f93..3c52f6a 100644 --- a/test/utils/reverter.ts +++ b/test/utils/reverter.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import { HttpProvider } from 'web3-core'; +import {HttpProvider} from 'web3-core'; export default class Reverter { // Web3 instance