-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from flashburst/lifecycle-tests
Added tests to cover lifecycle contracts
- Loading branch information
Showing
16 changed files
with
1,915 additions
and
0 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
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,49 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
const BigNumber = require('bignumber.js') | ||
const { deployer, key } = require('../../../util') | ||
const { deployDependencies } = require('./deps') | ||
const cache = null | ||
|
||
require('chai') | ||
.use(require('chai-as-promised')) | ||
.use(require('chai-bignumber')(BigNumber)) | ||
.should() | ||
|
||
describe('cxTokenFactory: Constructor and Views', () => { | ||
let store, | ||
accessControlLibV1, | ||
baseLibV1, | ||
storeKeyUtil, | ||
validationLibV1, | ||
cxTokenFactoryLib | ||
|
||
before(async () => { | ||
const deployed = await deployDependencies() | ||
|
||
store = deployed.store | ||
accessControlLibV1 = deployed.accessControlLibV1 | ||
baseLibV1 = deployed.baseLibV1 | ||
storeKeyUtil = deployed.storeKeyUtil | ||
validationLibV1 = deployed.validationLibV1 | ||
cxTokenFactoryLib = deployed.cxTokenFactoryLib | ||
}) | ||
|
||
it('correctly deploys', async () => { | ||
const vault = await deployer.deployWithLibraries(cache, 'cxTokenFactory', { | ||
AccessControlLibV1: accessControlLibV1.address, | ||
BaseLibV1: baseLibV1.address, | ||
StoreKeyUtil: storeKeyUtil.address, | ||
ValidationLibV1: validationLibV1.address, | ||
cxTokenFactoryLibV1: cxTokenFactoryLib.address | ||
}, store.address) | ||
|
||
const _store = await vault.s() | ||
_store.should.equal(store.address) | ||
|
||
const version = await vault.version() | ||
version.should.equal(key.toBytes32('v0.1')) | ||
|
||
const name = await vault.getName() | ||
name.should.equal(key.PROTOCOL.CNAME.CXTOKEN_FACTORY) | ||
}) | ||
}) |
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,191 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
const { helper, deployer, key } = require('../../../util') | ||
const DAYS = 86400 | ||
const cache = null | ||
const PoolTypes = { | ||
Token: 0, | ||
POD: 1 | ||
} | ||
|
||
const deployDependencies = async () => { | ||
const [owner] = await ethers.getSigners() | ||
const store = await deployer.deploy(cache, 'Store') | ||
const router = await deployer.deploy(cache, 'FakeUniswapV2RouterLike') | ||
|
||
const npm = await deployer.deploy(cache, 'FakeToken', 'Neptune Mutual Token', 'NPM', helper.ether(100_000_000)) | ||
const storeKeyUtil = await deployer.deploy(cache, 'StoreKeyUtil') | ||
|
||
const protoUtilV1 = await deployer.deployWithLibraries(cache, 'ProtoUtilV1', { | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const accessControlLibV1 = await deployer.deployWithLibraries(cache, 'AccessControlLibV1', { | ||
ProtoUtilV1: protoUtilV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const registryLibV1 = await deployer.deployWithLibraries(cache, 'RegistryLibV1', { | ||
ProtoUtilV1: protoUtilV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const strategyLibV1 = await deployer.deployWithLibraries(cache, 'StrategyLibV1', { | ||
ProtoUtilV1: protoUtilV1.address, | ||
RegistryLibV1: registryLibV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const coverUtilV1 = await deployer.deployWithLibraries(cache, 'CoverUtilV1', { | ||
RegistryLibV1: registryLibV1.address, | ||
StrategyLibV1: strategyLibV1.address, | ||
ProtoUtilV1: protoUtilV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const routineInvokerLibV1 = await deployer.deployWithLibraries(cache, 'RoutineInvokerLibV1', { | ||
CoverUtilV1: coverUtilV1.address, | ||
ProtoUtilV1: protoUtilV1.address, | ||
RegistryLibV1: registryLibV1.address, | ||
StrategyLibV1: strategyLibV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const governanceUtilV1 = await deployer.deployWithLibraries(cache, 'GovernanceUtilV1', { | ||
CoverUtilV1: coverUtilV1.address, | ||
RoutineInvokerLibV1: routineInvokerLibV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const validationLibV1 = await deployer.deployWithLibraries(cache, 'ValidationLibV1', { | ||
AccessControlLibV1: accessControlLibV1.address, | ||
CoverUtilV1: coverUtilV1.address, | ||
GovernanceUtilV1: governanceUtilV1.address, | ||
ProtoUtilV1: protoUtilV1.address, | ||
RegistryLibV1: registryLibV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const transferLib = await deployer.deploy(cache, 'NTransferUtilV2') | ||
|
||
const stakingPoolCoreLibV1 = await deployer.deployWithLibraries(cache, 'StakingPoolCoreLibV1', { | ||
NTransferUtilV2: transferLib.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const stakingPoolLibV1 = await deployer.deployWithLibraries(cache, 'StakingPoolLibV1', { | ||
NTransferUtilV2: transferLib.address, | ||
ProtoUtilV1: protoUtilV1.address, | ||
StakingPoolCoreLibV1: stakingPoolCoreLibV1.address, | ||
RegistryLibV1: registryLibV1.address, | ||
StoreKeyUtil: storeKeyUtil.address | ||
}) | ||
|
||
const baseLibV1 = await deployer.deployWithLibraries(cache, 'BaseLibV1', { | ||
}) | ||
|
||
const vaultFactoryLib = await deployer.deployWithLibraries(cache, 'VaultFactoryLibV1', { | ||
AccessControlLibV1: accessControlLibV1.address, | ||
BaseLibV1: baseLibV1.address, | ||
NTransferUtilV2: transferLib.address, | ||
ProtoUtilV1: protoUtilV1.address, | ||
RegistryLibV1: registryLibV1.address, | ||
ValidationLibV1: validationLibV1.address | ||
}) | ||
|
||
const protocol = await deployer.deployWithLibraries(cache, 'Protocol', | ||
{ | ||
AccessControlLibV1: accessControlLibV1.address, | ||
BaseLibV1: baseLibV1.address, | ||
ProtoUtilV1: protoUtilV1.address, | ||
RegistryLibV1: registryLibV1.address, | ||
StoreKeyUtil: storeKeyUtil.address, | ||
ValidationLibV1: validationLibV1.address | ||
}, | ||
store.address | ||
) | ||
|
||
await store.setBool(key.qualify(protocol.address), true) | ||
await store.setBool(key.qualifyMember(protocol.address), true) | ||
|
||
await protocol.initialize( | ||
[helper.zero1, | ||
router.address, | ||
helper.randomAddress(), // factory | ||
npm.address, | ||
helper.randomAddress(), | ||
helper.randomAddress() | ||
], | ||
[helper.ether(0), // Cover Fee | ||
helper.ether(0), // Min Cover Stake | ||
helper.ether(250), // Min Reporting Stake | ||
7 * DAYS, // Claim period | ||
helper.percentage(30), // Governance Burn Rate: 30% | ||
helper.percentage(10), // Governance Reporter Commission: 10% | ||
helper.percentage(6.5), // Claim: Platform Fee: 6.5% | ||
helper.percentage(5), // Claim: Reporter Commission: 5% | ||
helper.percentage(0.5), // Flash Loan Fee: 0.5% | ||
helper.percentage(2.5), // Flash Loan Protocol Fee: 2.5% | ||
1 * DAYS // cooldown period | ||
] | ||
) | ||
|
||
await protocol.grantRoles([ | ||
{ | ||
account: protocol.address, | ||
roles: [ | ||
key.ACCESS_CONTROL.LIQUIDITY_MANAGER, | ||
key.ACCESS_CONTROL.UPGRADE_AGENT | ||
] | ||
}, | ||
{ | ||
account: owner.address, | ||
roles: [ | ||
key.ACCESS_CONTROL.LIQUIDITY_MANAGER, | ||
key.ACCESS_CONTROL.PAUSE_AGENT, | ||
key.ACCESS_CONTROL.UPGRADE_AGENT | ||
] | ||
} | ||
]) | ||
|
||
const cxTokenFactoryLib = await deployer.deployWithLibraries(cache, 'cxTokenFactoryLibV1', { | ||
AccessControlLibV1: accessControlLibV1.address, | ||
BaseLibV1: baseLibV1.address, | ||
ValidationLibV1: validationLibV1.address | ||
}) | ||
|
||
const cxTokenFactory = await deployer.deployWithLibraries(cache, 'cxTokenFactory', | ||
{ | ||
AccessControlLibV1: accessControlLibV1.address, | ||
BaseLibV1: baseLibV1.address, | ||
cxTokenFactoryLibV1: cxTokenFactoryLib.address, | ||
StoreKeyUtil: storeKeyUtil.address, | ||
ValidationLibV1: validationLibV1.address | ||
} | ||
, store.address | ||
) | ||
|
||
await protocol.addContract(key.PROTOCOL.CNS.COVER_CXTOKEN_FACTORY, cxTokenFactory.address) | ||
|
||
return { | ||
npm, | ||
store, | ||
router, | ||
storeKeyUtil, | ||
protoUtilV1, | ||
accessControlLibV1, | ||
registryLibV1, | ||
coverUtilV1, | ||
governanceUtilV1, | ||
validationLibV1, | ||
baseLibV1, | ||
stakingPoolCoreLibV1, | ||
stakingPoolLibV1, | ||
transferLib, | ||
strategyLibV1, | ||
vaultFactoryLib, | ||
cxTokenFactoryLib, | ||
protocol | ||
} | ||
} | ||
|
||
module.exports = { deployDependencies, PoolTypes } |
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,92 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
const { ethers } = require('hardhat') | ||
const BigNumber = require('bignumber.js') | ||
const { helper, deployer, key } = require('../../../../util') | ||
const composer = require('../../../../util/composer') | ||
const { deployDependencies } = require('./deps') | ||
const cache = null | ||
const DAYS = 86400 | ||
|
||
require('chai') | ||
.use(require('chai-as-promised')) | ||
.use(require('chai-bignumber')(BigNumber)) | ||
.should() | ||
|
||
describe('CoverProvision: Constructor', () => { | ||
let deployed, coverKey | ||
|
||
before(async () => { | ||
const [owner] = await ethers.getSigners() | ||
deployed = await deployDependencies() | ||
|
||
deployed.policy = await deployer.deployWithLibraries(cache, 'Policy', { | ||
AccessControlLibV1: deployed.accessControlLibV1.address, | ||
BaseLibV1: deployed.baseLibV1.address, | ||
CoverUtilV1: deployed.coverUtilV1.address, | ||
PolicyHelperV1: deployed.policyHelperV1.address, | ||
StrategyLibV1: deployed.strategyLibV1.address, | ||
ValidationLibV1: deployed.validationLibV1.address | ||
}, deployed.store.address) | ||
|
||
await deployed.protocol.addContract(key.PROTOCOL.CNS.COVER_POLICY, deployed.policy.address) | ||
|
||
coverKey = key.toBytes32('foo-bar') | ||
const stakeWithFee = helper.ether(10_000) | ||
const initialReassuranceAmount = helper.ether(1_000_000) | ||
const initialLiquidity = helper.ether(4_000_000) | ||
const minReportingStake = helper.ether(250) | ||
const reportingPeriod = 7 * DAYS | ||
const cooldownPeriod = 1 * DAYS | ||
const claimPeriod = 7 * DAYS | ||
const floor = helper.percentage(7) | ||
const ceiling = helper.percentage(45) | ||
|
||
const requiresWhitelist = false | ||
const values = [stakeWithFee, initialReassuranceAmount, minReportingStake, reportingPeriod, cooldownPeriod, claimPeriod, floor, ceiling] | ||
|
||
const info = key.toBytes32('info') | ||
|
||
deployed.cover.updateCoverCreatorWhitelist(owner.address, true) | ||
|
||
await deployed.npm.approve(deployed.stakingContract.address, stakeWithFee) | ||
await deployed.dai.approve(deployed.reassuranceContract.address, initialReassuranceAmount) | ||
|
||
await deployed.cover.addCover(coverKey, info, deployed.dai.address, requiresWhitelist, values) | ||
await deployed.cover.deployVault(coverKey) | ||
|
||
deployed.vault = await composer.vault.getVault({ | ||
store: deployed.store, | ||
libs: { | ||
accessControlLibV1: deployed.accessControlLibV1, | ||
baseLibV1: deployed.baseLibV1, | ||
transferLib: deployed.transferLib, | ||
protoUtilV1: deployed.protoUtilV1, | ||
registryLibV1: deployed.registryLibV1, | ||
validationLib: deployed.validationLibV1 | ||
} | ||
}, coverKey) | ||
|
||
await deployed.dai.approve(deployed.vault.address, initialLiquidity) | ||
await deployed.npm.approve(deployed.vault.address, minReportingStake) | ||
await deployed.vault.addLiquidity(coverKey, initialLiquidity, minReportingStake) | ||
}) | ||
|
||
it('correctly deploys', async () => { | ||
const cover = await deployer.deployWithLibraries(cache, 'CoverProvision', | ||
{ | ||
AccessControlLibV1: deployed.accessControlLibV1.address, | ||
BaseLibV1: deployed.baseLibV1.address, | ||
CoverLibV1: deployed.coverLibV1.address, | ||
StoreKeyUtil: deployed.storeKeyUtil.address, | ||
ValidationLibV1: deployed.validationLibV1.address | ||
}, | ||
deployed.store.address | ||
) | ||
|
||
const version = await cover.version() | ||
const name = await cover.getName() | ||
|
||
version.should.equal(key.toBytes32('v0.1')) | ||
name.should.equal(key.PROTOCOL.CNAME.COVER_PROVISION) | ||
}) | ||
}) |
Oops, something went wrong.