-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comet balance constraint + Constraint and Transfer scenarios + Comet …
…Solidity bug fix (#247) This PR includes the following changes: -Constraint for setting the Comet balance of an actor -More transfer scenarios and new set of scenarios for testing constraints -Fixing a Solidity underflow bug that was caught by the transfer scenarios -Librarifying some code between the BalanceConstraint and -CometBalanceConstraint Example of CometBalanceConstraint usage: ``` scenario( 'Comet#comet balance constraint', { cometBalances: { albert: { $base: 100, $asset0: 10 }, // in units of asset, not wei }, }, ```
- Loading branch information
1 parent
7bd91fb
commit 71aec02
Showing
11 changed files
with
487 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { scenario } from './context/CometContext'; | ||
import { expect } from 'chai'; | ||
import { expectApproximately } from './utils'; | ||
|
||
scenario( | ||
'Comet#constraint > collateral CometBalanceConstraint + BalanceConstraint both satisfied', | ||
{ | ||
upgrade: true, | ||
balances: { | ||
albert: { $asset0: 100 }, // in units of asset, not wei | ||
}, | ||
cometBalances: { | ||
albert: { $asset0: 100 }, // in units of asset, not wei | ||
}, | ||
}, | ||
async ({ comet, actors }, world, context) => { | ||
const { albert } = actors; | ||
const { asset: asset0Address, scale } = await comet.getAssetInfo(0); | ||
const collateralAsset = context.getAssetByAddress(asset0Address); | ||
|
||
expect(await collateralAsset.balanceOf(albert.address)).to.be.equal(scale.toBigInt() * 100n); | ||
expect(await comet.collateralBalanceOf(albert.address, collateralAsset.address)).to.be.equal(scale.mul(100)); | ||
} | ||
); | ||
|
||
scenario( | ||
'Comet#constraint > base CometBalanceConstraint + BalanceConstraint both satisfied', | ||
{ | ||
upgrade: true, | ||
balances: { | ||
albert: { $base: 100 }, // in units of asset, not wei | ||
}, | ||
cometBalances: { | ||
albert: { $base: 100 }, // in units of asset, not wei | ||
}, | ||
}, | ||
async ({ comet, actors }, world, context) => { | ||
const { albert } = actors; | ||
const baseAssetAddress = await comet.baseToken(); | ||
const baseAsset = context.getAssetByAddress(baseAssetAddress); | ||
const scale = (await comet.baseScale()).toBigInt(); | ||
|
||
expect(await baseAsset.balanceOf(albert.address)).to.be.equal(100n * scale); | ||
expect(await albert.getCometBaseBalance()).to.be.equal(100n * scale); | ||
} | ||
); | ||
|
||
scenario( | ||
'Comet#constraint > negative comet base balance (borrow position)', | ||
{ | ||
upgrade: true, | ||
balances: { | ||
albert: { $base: 100 }, // in units of asset, not wei | ||
}, | ||
cometBalances: { | ||
albert: { $base: -100 }, // in units of asset, not wei | ||
}, | ||
}, | ||
async ({ comet, actors }, world, context) => { | ||
const { albert } = actors; | ||
const baseAssetAddress = await comet.baseToken(); | ||
const baseAsset = context.getAssetByAddress(baseAssetAddress); | ||
const scale = (await comet.baseScale()).toBigInt(); | ||
|
||
expect(await baseAsset.balanceOf(albert.address)).to.be.equal(100n * scale); | ||
expectApproximately(await albert.getCometBaseBalance(), -100n * scale, 1n); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.