Skip to content

Commit

Permalink
Add Test Case
Browse files Browse the repository at this point in the history
This patch simply adds a test-case to show how some accounts interact with the current Comptroller.
  • Loading branch information
coburncoburn authored and hayesgm committed Oct 1, 2021
1 parent 4aa526d commit 880c1b8
Show file tree
Hide file tree
Showing 11 changed files with 65,654 additions and 58,760 deletions.
1,416 changes: 1,416 additions & 0 deletions contracts/ComptrollerG10.sol

Large diffs are not rendered by default.

1,354 changes: 1,354 additions & 0 deletions contracts/ComptrollerG8.sol

Large diffs are not rendered by default.

1,447 changes: 1,447 additions & 0 deletions contracts/ComptrollerG9.sol

Large diffs are not rendered by default.

118,195 changes: 60,233 additions & 57,962 deletions networks/mainnet-abi.json

Large diffs are not rendered by default.

1,602 changes: 805 additions & 797 deletions networks/mainnet.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion scenario/src/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ export const accountMap = {
"sixth": 5,

"jared": 6,
"seventh": 6
"seventh": 6,

"tyler": 7,
"eighth": 7,

"gaston": 8,
"ninth": 8,

"felix": 9,
"tenth": 9
};

export interface Account {
Expand Down
59 changes: 59 additions & 0 deletions scenario/src/Builder/ComptrollerImplBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ const ComptrollerScenarioG5Contract = getContract('ComptrollerScenarioG5');
const ComptrollerG6Contract = getContract('ComptrollerG6');
const ComptrollerScenarioG6Contract = getContract('ComptrollerScenarioG6');

const ComptrollerG8Contract = getContract('ComptrollerG8');
const ComptrollerScenarioG8Contract = getContract('ComptrollerScenarioG8');

const ComptrollerG9Contract = getContract('ComptrollerG9');
const ComptrollerScenarioG9Contract = getContract('ComptrollerScenarioG9');

const ComptrollerG10Contract = getContract('ComptrollerG10');
const ComptrollerScenarioG10Contract = getContract('ComptrollerScenarioG10');

const ComptrollerScenarioContract = getTestContract('ComptrollerScenario');
const ComptrollerContract = getContract('Comptroller');

Expand Down Expand Up @@ -143,6 +152,56 @@ export async function buildComptrollerImpl(
})
),


new Fetcher<{ name: StringV }, ComptrollerImplData>(
`
#### ScenarioG8
* "ScenarioG8 name:<String>" - The Comptroller Scenario for local testing (last good)
* E.g. "ComptrollerImpl Deploy ScenarioG8 MyScen"
`,
'ScenarioG8',
[new Arg('name', getStringV)],
async (world, { name }) => ({
invokation: await ComptrollerScenarioG8Contract.deploy<ComptrollerImpl>(world, from, []),
name: name.val,
contract: 'ComptrollerScenarioG8Contract',
description: 'ScenarioG8 Comptroller Impl'
})
),

new Fetcher<{ name: StringV }, ComptrollerImplData>(
`
#### ScenarioG9
* "ScenarioG9 name:<String>" - The Comptroller Scenario for local testing (the bug)
* E.g. "ComptrollerImpl Deploy ScenarioG9 MyScen"
`,
'ScenarioG9',
[new Arg('name', getStringV)],
async (world, { name }) => ({
invokation: await ComptrollerScenarioG9Contract.deploy<ComptrollerImpl>(world, from, []),
name: name.val,
contract: 'ComptrollerScenarioG9Contract',
description: 'ScenarioG9 Comptroller Impl'
})
),

new Fetcher<{ name: StringV }, ComptrollerImplData>(
`
#### ScenarioG10
* "ScenarioG6 name:<String>" - The Comptroller Scenario for local testing (reverty)
* E.g. "ComptrollerImpl Deploy ScenarioG10 MyScen"
`,
'ScenarioG10',
[new Arg('name', getStringV)],
async (world, { name }) => ({
invokation: await ComptrollerScenarioG10Contract.deploy<ComptrollerImpl>(world, from, []),
name: name.val,
contract: 'ComptrollerScenarioG10Contract',
description: 'ScenarioG10 Comptroller Impl'
})
),


new Fetcher<{ name: StringV }, ComptrollerImplData>(
`
#### Scenario
Expand Down
201 changes: 201 additions & 0 deletions spec/scenario/Flywheel/CompSplitSpeed.scen
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@

Macro InitSpeedsOld
Comptroller SetCompSpeed cZRX (1)
Comptroller SetCompSpeed cBAT (1)
Prep Geoff 100e18 ZRX cZRX
Mint Geoff 50e18 cZRX--tokenbalance = 50e18 / 2e9 = 2.5e10
Prep Coburn 100e18 BAT cBAT
Mint Coburn 50e18 cBAT--tokenbalance = 6e18 / 2e9 = 3e9
EnterMarkets Coburn cBAT
Prep Tyler 100e18 BAT cBAT
Mint Tyler 50e18 cBAT--tokenbalance = 6e18 / 2e9 = 3e9
EnterMarkets Tyler cBAT
Prep Gaston 100e18 BAT cBAT
Mint Gaston 50e18 cBAT--tokenbalance = 6e18 / 2e9 = 3e9
EnterMarkets Gaston cBAT
Prep Felix 100e18 BAT cBAT
Mint Felix 50e18 cBAT--tokenbalance = 6e18 / 2e9 = 3e9
EnterMarkets Felix cBAT

Macro PreSplitComptroller
Unitroller Deploy
PriceOracle Deploy Fixed 1.0
PriceOracleProxy Deploy Admin (PriceOracle Address) (Address Zero) (Address Zero) (Address Zero) (Address Zero) (Address Zero)
-- Deploy Comptroller
ComptrollerImpl Deploy ScenarioG8 ScenComptrollerG8
Unitroller SetPendingImpl ScenComptrollerG8
ComptrollerImpl ScenComptrollerG8 BecomeG6--simply "become" with no arguments
-- Configure Comptroller
Comptroller SetPriceOracle (PriceOracleProxy Address)
Comptroller SetCloseFactor 0.5
Comptroller LiquidationIncentive 1.1
-- Add markets
NewCToken ZRX cZRX
NewCToken BAT cBAT
Support cZRX collateralFactor:0.5
Support cBAT collateralFactor:0.5
-- Setup COMP token
Erc20 Deploy Standard COMP "COMP Token" 18
Give (Address Comptroller) 5000000e18 COMP
Comptroller Send "setCompAddress(address)" (Address COMP)

Macro SwitchToG9_TheBug
ComptrollerImpl Deploy ScenarioG9 ScenComptrollerG9
Unitroller SetPendingImpl ScenComptrollerG9
ComptrollerImpl ScenComptrollerG9 Become

Macro SwitchToG10_Reverty
ComptrollerImpl Deploy ScenarioG10 ScenComptrollerG10
Unitroller SetPendingImpl ScenComptrollerG10
ComptrollerImpl ScenComptrollerG10 Become

Macro SwitchToLatestComptroller
ComptrollerImpl Deploy Scenario Latest
Unitroller SetPendingImpl Latest
ComptrollerImpl Latest Become

Macro AddYFI_PeopleBorrow
-- new token with no speed
NewCToken YFI cYFI
Support cYFI collateralFactor:0.5
Prep Torrey 100e18 YFI cYFI -- will mint right before
Mint Torrey 100e18 cYFI
Prep Jared 100e18 YFI cYFI -- will mint right after
Borrow Coburn 10e18 cYFI -- will borrow right before
Borrow Tyler 10e18 cYFI -- will borrow right before
Prep Gaston 10000e18 YFI cYFI -- for layer repay
Borrow Gaston 10e18 cYFI -- will borrow right before
Borrow Felix 10e18 cYFI -- will borrow right before
Prep Felix 10000e18 YFI cYFI -- for layer repay
EnterMarkets Geoff cZRX -- will borrow right after

Test "Claim COMP Prior to Upgrade"
PreSplitComptroller
InitSpeedsOld
--upgrade
Comptroller SetCompSpeed cYFI (2)
Mint Jared 10e18 cYFI
Borrow Geoff 10e18 cYFI
Assert Equal (Comptroller CompBorrowerIndex cYFI Coburn) 0
Assert Equal (Comptroller CompBorrowerIndex cYFI Geoff) 1e36
FastForward 1000 blocks
Comptroller ClaimComp Jared
Comptroller ClaimComp Torrey
Comptroller ClaimComp Geoff
Comptroller ClaimComp Coburn -- note coburn borrowed before geoff
Assert Equal (Erc20 COMP TokenBalance Coburn) 0
Assert Equal (Erc20 COMP TokenBalance Geoff) 1000
Assert Equal (Comptroller CompBorrowerIndex cYFI Coburn) (Comptroller CompBorrowerIndex cYFI Geoff) -- Coburn fully missed distrubution until an action
Assert (Erc20 COMP TokenBalance Geoff) GreaterThan (Erc20 COMP TokenBalance Coburn)
Assert Equal (Erc20 COMP TokenBalance Jared) (Erc20 COMP TokenBalance Torrey) -- suppliers are correctly initialized
FastForward 1000 blocks -- see where they stand now
Comptroller ClaimComp Coburn
Comptroller ClaimComp Geoff
Assert Equal (Erc20 COMP TokenBalance Coburn) 1000 -- 1000 comp missing forever
Assert Equal (Erc20 COMP TokenBalance Geoff) 2000

-- Start with G8, upgrade to G9 (bug), then upgrade to G10 (reverty), then upgrade to latest
Only "Claim COMP across upgrade"
PreSplitComptroller
InitSpeedsOld
AddYFI_PeopleBorrow
SwitchToG9_TheBug
Mint Jared 10e18 cYFI
Borrow Geoff 11e18 cYFI
Assert Equal (Comptroller CompBorrowerIndex cYFI Coburn) 0
Assert Equal (Comptroller CompBorrowerIndex cYFI Geoff) 1e36
FastForward 1000 blocks
Comptroller ClaimComp Coburn
Comptroller ClaimComp Geoff
Comptroller ClaimComp Jared
Comptroller ClaimComp Torrey
Assert Equal (Erc20 COMP TokenBalance Coburn) 10000000000000000250 -- buggy balance
Assert Equal (Erc20 COMP TokenBalance Geoff) 1000
Assert Equal (Erc20 COMP TokenBalance Jared) 0
Assert Equal (Erc20 COMP TokenBalance Torrey) 5e10 --buggy balance (double check)
Assert Equal (Erc20 COMP TokenBalance Tyler) 0
Assert Equal (Erc20 COMP TokenBalance Gaston) 0
Assert Equal (Erc20 COMP TokenBalance Felix) 0
Assert Equal (Comptroller CompAccrued Coburn) 0 -- Check accruals
Assert Equal (Comptroller CompAccrued Geoff) 0
Assert Equal (Comptroller CompAccrued Jared) 0
Assert Equal (Comptroller CompAccrued Torrey) 0
Assert Equal (Comptroller CompAccrued Tyler) 0
Assert Equal (Comptroller CompAccrued Gaston) 0
Assert Equal (Comptroller CompAccrued Felix) 0
Assert Equal (Comptroller CompBorrowerIndex cYFI Coburn) (Comptroller CompBorrowerIndex cYFI Geoff) -- Coburn fully missed distrubution until an action
FastForward 1000 blocks -- see where they stand now
Comptroller ClaimComp Coburn
Comptroller ClaimComp Geoff
Assert Equal (Erc20 COMP TokenBalance Coburn) 10000000000000000500 -- buggy balance
Assert Equal (Erc20 COMP TokenBalance Geoff) 2000
Assert Equal (Erc20 COMP TokenBalance Jared) 0
Assert Equal (Erc20 COMP TokenBalance Torrey) 5e10 --buggy balance (double check)
SwitchToG10_Reverty -- Let's go to the reverty fix
FastForward 1000 blocks
AllowFailures
Comptroller ClaimComp Coburn
Assert Revert "revert COMP rewards paused"
Comptroller ClaimComp Geoff
Assert Revert "revert COMP rewards paused"
Comptroller ClaimComp Jared
Assert Revert "revert COMP rewards paused"
Comptroller ClaimComp Torrey
Assert Revert "revert COMP rewards paused"
Comptroller ClaimComp Tyler
Assert Revert "revert COMP rewards paused"
Comptroller ClaimComp Gaston
Assert Revert "revert COMP rewards paused"
Comptroller ClaimComp Felix
Assert Revert "revert COMP rewards paused"
Assert Equal (Erc20 COMP TokenBalance Coburn) 10000000000000000500 -- buggy balance
Assert Equal (Erc20 COMP TokenBalance Geoff) 2000
Assert Equal (Erc20 COMP TokenBalance Jared) 0
Assert Equal (Erc20 COMP TokenBalance Torrey) 5e10 --buggy balance (double check)
Assert Equal (Erc20 COMP TokenBalance Tyler) 0
Assert Equal (Erc20 COMP TokenBalance Gaston) 0
Assert Equal (Erc20 COMP TokenBalance Felix) 0
Assert Equal (Comptroller CompAccrued Coburn) 0 -- Check accruals
Assert Equal (Comptroller CompAccrued Geoff) 0
Assert Equal (Comptroller CompAccrued Jared) 0
Assert Equal (Comptroller CompAccrued Torrey) 0
Assert Equal (Comptroller CompAccrued Tyler) 0
Assert Equal (Comptroller CompAccrued Gaston) 0
Assert Equal (Comptroller CompAccrued Felix) 0
RepayBorrow Gaston UInt256Max cYFI -- but can borrow or repay to trigger accrual
Assert Success
Assert Equal (Comptroller CompAccrued Gaston) 10000000000000000000
Redeem Gaston 0 cBAT -- borrow or repay can still trigger accrual and should be 750
Assert Success
Assert Equal (Comptroller CompAccrued Gaston) 10000000000000000750
SwitchToLatestComptroller
Comptroller ClaimComp Coburn -- TODO: This should be blocked
Assert Success
Comptroller ClaimComp Geoff -- Okay
Assert Success
Comptroller ClaimComp Jared -- Okay
Assert Success
Comptroller ClaimComp Torrey -- TODO: This should be blocked
Assert Success
Comptroller ClaimComp Tyler -- Okay
Assert Success
Comptroller ClaimComp Gaston -- TODO: This should be blocked
Assert Success
RepayBorrow Felix UInt256Max cYFI -- borrow or repay can still trigger accrual but should be 0
Assert Success
Redeem Felix 0 cBAT -- borrow or repay can still trigger accrual and should be 750
Assert Success
Assert Equal (Erc20 COMP TokenBalance Coburn) 10000000000000000750 -- buggy balance
Assert Equal (Erc20 COMP TokenBalance Geoff) 2000
Assert Equal (Erc20 COMP TokenBalance Jared) 0
Assert Equal (Erc20 COMP TokenBalance Torrey) 5e10 --buggy balance (double check)
Assert Equal (Erc20 COMP TokenBalance Tyler) 750 -- not buggy balance!
Assert Equal (Erc20 COMP TokenBalance Gaston) 10000000000000000750 -- buggy balance
Assert Equal (Erc20 COMP TokenBalance Felix) 0 -- buggy balance
Assert Equal (Comptroller CompAccrued Coburn) 0 -- Check accruals
Assert Equal (Comptroller CompAccrued Geoff) 0
Assert Equal (Comptroller CompAccrued Jared) 0
Assert Equal (Comptroller CompAccrued Torrey) 0
Assert Equal (Comptroller CompAccrued Tyler) 0
Assert Equal (Comptroller CompAccrued Gaston) 0
Assert Equal (Comptroller CompAccrued Felix) 750 -- Non-buggy accrual
43 changes: 43 additions & 0 deletions tests/Contracts/ComptrollerScenarioG10.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pragma solidity ^0.5.16;

import "../../contracts/ComptrollerG10.sol";

contract ComptrollerScenarioG10 is ComptrollerG10 {
uint public blockNumber;
address public compAddress;

constructor() ComptrollerG10() public {}

function fastForward(uint blocks) public returns (uint) {
blockNumber += blocks;
return blockNumber;
}

function setCompAddress(address compAddress_) public {
compAddress = compAddress_;
}

function getCompAddress() public view returns (address) {
return compAddress;
}

function setBlockNumber(uint number) public {
blockNumber = number;
}

function getBlockNumber() public view returns (uint) {
return blockNumber;
}

function membershipLength(CToken cToken) public view returns (uint) {
return accountAssets[address(cToken)].length;
}

function unlist(CToken cToken) public {
markets[address(cToken)].isListed = false;
}

function setCompSpeed(address cToken, uint compSpeed) public {
compSpeeds[cToken] = compSpeed;
}
}
43 changes: 43 additions & 0 deletions tests/Contracts/ComptrollerScenarioG8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pragma solidity ^0.5.16;

import "../../contracts/ComptrollerG8.sol";

contract ComptrollerScenarioG8 is ComptrollerG8 {
uint public blockNumber;
address public compAddress;

constructor() ComptrollerG8() public {}

function fastForward(uint blocks) public returns (uint) {
blockNumber += blocks;
return blockNumber;
}

function setCompAddress(address compAddress_) public {
compAddress = compAddress_;
}

function getCompAddress() public view returns (address) {
return compAddress;
}

function setBlockNumber(uint number) public {
blockNumber = number;
}

function getBlockNumber() public view returns (uint) {
return blockNumber;
}

function membershipLength(CToken cToken) public view returns (uint) {
return accountAssets[address(cToken)].length;
}

function unlist(CToken cToken) public {
markets[address(cToken)].isListed = false;
}

function setCompSpeed(address cToken, uint compSpeed) public {
compSpeeds[cToken] = compSpeed;
}
}
Loading

0 comments on commit 880c1b8

Please sign in to comment.