Skip to content

Commit

Permalink
test: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Feb 20, 2024
1 parent 6bece78 commit 7f2eb3c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
2 changes: 2 additions & 0 deletions test/FeesManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
} = require('./roles')
const { getSentinelIdentity } = require('./utils')
const { hardhatReset } = require('./utils/hardhat-reset')
const { sendEth } = require('./utils/send-eth')

let stakingManagerLM,
stakingManagerRM,
Expand Down Expand Up @@ -87,6 +88,7 @@ describe('FeesManager', () => {
pntHolder1 = await ethers.getImpersonatedSigner(PNT_HOLDER_1_ADDRESS)
pntHolder2 = await ethers.getImpersonatedSigner(PNT_HOLDER_2_ADDRESS)
daoRoot = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
sendEth(ethers, owner, daoRoot.address, '1')

pnt = await TestToken.deploy('PNT', 'PNT')
acl = ACL.attach(ACL_ADDRESS)
Expand Down
18 changes: 10 additions & 8 deletions test/Forwarders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
SET_FORWARDER_ROLE
} = require('./roles')
const { encode, getSentinelIdentity, getUserDataGeneratedByForwarder } = require('./utils')
const { sendEth } = require('./utils/send-eth')

let acl,
forwarderNative,
Expand All @@ -44,7 +45,7 @@ let acl,
pToken,
pnetwork,
sentinel1,
root,
daoRoot,
pntHolder1,
pntHolder2,
fakeForwarder,
Expand Down Expand Up @@ -79,7 +80,8 @@ PTOKEN_CONTRACTS.map((_ptokenContract) =>
pnetwork = await ethers.getImpersonatedSigner(PNETWORK_ADDRESS)
pntHolder1 = await ethers.getImpersonatedSigner(PNT_HOLDER_1_ADDRESS)
pntHolder2 = await ethers.getImpersonatedSigner(PNT_HOLDER_2_ADDRESS)
root = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
daoRoot = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
sendEth(ethers, owner, daoRoot.address, '1')

acl = ACL.attach(ACL_ADDRESS)
pnt = await TestToken.deploy('PNT', 'PNT')
Expand Down Expand Up @@ -165,12 +167,12 @@ PTOKEN_CONTRACTS.map((_ptokenContract) =>
await voting.setForwarder(await forwarderHost.getAddress())

// set permissions
await acl.connect(root).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(root).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)
await acl.connect(root).grantPermission(await stakingManagerRM.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(root).grantPermission(await stakingManagerRM.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)
await acl.connect(root).grantPermission(await stakingManagerLM.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(root).grantPermission(await stakingManagerLM.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManagerRM.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManagerRM.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManagerLM.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManagerLM.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)
await lendingManager.grantRole(BORROW_ROLE, await registrationManager.getAddress())
await stakingManagerLM.grantRole(STAKE_ROLE, await lendingManager.getAddress())
await stakingManagerLM.grantRole(INCREASE_DURATION_ROLE, await lendingManager.getAddress())
Expand Down
2 changes: 2 additions & 0 deletions test/LendingManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
} = require('./roles')
const { truncateWithPrecision } = require('./utils')
const { hardhatReset } = require('./utils/hardhat-reset')
const { sendEth } = require('./utils/send-eth')

describe('LendingManager', () => {
let daoRoot,
Expand Down Expand Up @@ -63,6 +64,7 @@ describe('LendingManager', () => {
pntHolder1 = await ethers.getImpersonatedSigner(PNT_HOLDER_1_ADDRESS)
pntHolder2 = await ethers.getImpersonatedSigner(PNT_HOLDER_2_ADDRESS)
daoRoot = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
sendEth(ethers, owner, daoRoot.address, '1')

pnt = await TestToken.deploy('PNT', 'PNT')
acl = ACL.attach(ACL_ADDRESS)
Expand Down
2 changes: 2 additions & 0 deletions test/RegistrationManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
} = require('./roles')
const { getSentinelIdentity, truncateWithPrecision } = require('./utils')
const { hardhatReset } = require('./utils/hardhat-reset')
const { sendEth } = require('./utils/send-eth')

let signers,
stakingManagerRM,
Expand Down Expand Up @@ -97,6 +98,7 @@ describe('RegistrationManager', () => {
pntHolder1 = await ethers.getImpersonatedSigner(PNT_HOLDER_1_ADDRESS)
pntHolder2 = await ethers.getImpersonatedSigner(PNT_HOLDER_2_ADDRESS)
daoRoot = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
sendEth(ethers, owner, daoRoot.address, '1')

pnt = await TestToken.deploy('PNT', 'PNT')
acl = ACL.attach(ACL_ADDRESS)
Expand Down
17 changes: 7 additions & 10 deletions test/RewardsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const TokenManagerAbi = require('./abi/TokenManager.json')
const { EPOCH_DURATION, ONE_DAY, ONE_MONTH, PNT_MAX_TOTAL_SUPPLY, VOTE_STATUS } = require('./constants')
const { DEPOSIT_REWARD_ROLE, MINT_ROLE, BURN_ROLE, WITHDRAW_ROLE } = require('./roles')
const { hardhatReset } = require('./utils/hardhat-reset')
const { sendEth } = require('./utils/send-eth')

describe('RewardsManager', () => {
let epochsManager,
Expand All @@ -26,15 +27,9 @@ describe('RewardsManager', () => {
acl,
tokenManager,
daoPnt,
daoCreator
daoRoot

const setPermission = async (entity, app, role) => acl.connect(daoCreator).grantPermission(entity, app, role)

const sendEthers = (_from, _dest, _amount) =>
_from.sendTransaction({
to: _dest.address,
value: ethers.parseEther(_amount)
})
const setPermission = async (entity, app, role) => acl.connect(daoRoot).grantPermission(entity, app, role)

const sendPnt = (_from, _to, _amount) => pnt.connect(_from).transfer(_to, ethers.parseEther(_amount))

Expand Down Expand Up @@ -99,15 +94,17 @@ describe('RewardsManager', () => {

const signers = await ethers.getSigners()
owner = signers[0]
daoCreator = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
daoRoot = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
sendEth(ethers, owner, daoRoot.address, '1')

randomGuy = ethers.Wallet.createRandom().connect(ethers.provider)
pntHolder1 = ethers.Wallet.createRandom().connect(ethers.provider)
pntHolder2 = ethers.Wallet.createRandom().connect(ethers.provider)
pntHolder3 = ethers.Wallet.createRandom().connect(ethers.provider)
pntHolder4 = ethers.Wallet.createRandom().connect(ethers.provider)
pntHolders = [pntHolder1, pntHolder2, pntHolder3, pntHolder4]

await Promise.all([...pntHolders, daoCreator, randomGuy].map((_dest) => sendEthers(owner, _dest, '1001')))
await Promise.all([...pntHolders, daoRoot, randomGuy].map((_dest) => sendEth(ethers, owner, _dest.address, '1001')))

acl = await ethers.getContractAt(AclAbi, ACL_ADDRESS)
tokenManager = await ethers.getContractAt(TokenManagerAbi, TOKEN_MANAGER_ADDRESS)
Expand Down
12 changes: 7 additions & 5 deletions test/StakingManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const {
ZERO_ADDRESS
} = require('./constants')
const { CHANGE_MAX_TOTAL_SUPPLY_ROLE, UPGRADE_ROLE, SLASH_ROLE, MINT_ROLE, BURN_ROLE } = require('./roles')
const { sendEth } = require('./utils/send-eth')

describe('StakingManager', () => {
let pntHolder1, root, owner, stakingManager, StakingManager, fakeForwarder, challenger, acl, pnt, daoPnt
let pntHolder1, daoRoot, owner, stakingManager, StakingManager, fakeForwarder, challenger, acl, pnt, daoPnt

beforeEach(async () => {
StakingManager = await ethers.getContractFactory('StakingManager')
Expand All @@ -28,7 +29,8 @@ describe('StakingManager', () => {
fakeForwarder = signers[1]
challenger = signers[2]
pntHolder1 = await ethers.getImpersonatedSigner(PNT_HOLDER_1_ADDRESS)
root = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
daoRoot = await ethers.getImpersonatedSigner(SAFE_ADDRESS)
sendEth(ethers, owner, daoRoot.address, '1')

acl = ACL.attach(ACL_ADDRESS)
pnt = await TestToken.deploy('PNT', 'PNT')
Expand All @@ -46,15 +48,15 @@ describe('StakingManager', () => {
)

await owner.sendTransaction({
to: root.address,
to: daoRoot.address,
value: ethers.parseEther('10')
})

await stakingManager.grantRole(UPGRADE_ROLE, owner.address)
await stakingManager.grantRole(SLASH_ROLE, owner.address)
await stakingManager.grantRole(CHANGE_MAX_TOTAL_SUPPLY_ROLE, owner.address)
await acl.connect(root).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(root).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, MINT_ROLE)
await acl.connect(daoRoot).grantPermission(await stakingManager.getAddress(), TOKEN_MANAGER_ADDRESS, BURN_ROLE)

await owner.sendTransaction({
to: pntHolder1.address,
Expand Down
9 changes: 4 additions & 5 deletions test/utils/send-eth.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const R = require('ramda')

module.exports.sendEth = async (_hre, _from, _to, _eth, _opts = {}) => {
module.exports.sendEth = async (_ethers, _from, _to, _eth, _opts = {}) => {
if (R.isNil(_eth)) return Promise.reject(new Error('Unspecified amount:', _eth))

const value = R.type(_eth) === 'String' ? _hre.ethers.parseEther(_eth) : _eth
const balance = await _hre.ethers.provider.getBalance(await _from.getAddress())
const value = R.type(_eth) === 'String' ? _ethers.parseEther(_eth) : _eth
const balance = await _ethers.provider.getBalance(await _from.getAddress())

if (value > balance)
return Promise.reject(new Error(`Failed: insufficient balance ${_hre.ethers.formatEther(balance)}`))
if (value > balance) return Promise.reject(new Error(`Failed: insufficient balance ${_ethers.formatEther(balance)}`))

return _from.sendTransaction({ ..._opts, to: _to, value })
}

0 comments on commit 7f2eb3c

Please sign in to comment.