Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenSwen committed Sep 18, 2023
1 parent f406852 commit c5bac00
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions test/PowerPod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { expBase } = require('./helpers/utils');

describe('PowerPod', function () {
async function initContracts() {
const commonLockDuration = time.duration.days('40');
const MAX_WHITELISTED = 3;
const BALANCE_THRESHOLD = 1000; // 10%

const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => {
await st1inch.connect(user).deposit(0, commonLockDuration);
await st1inch.depositFor(user.address, amount);
await st1inch.connect(user).addPod(delegation.address);
await delegation
.connect(user)
.functions['register(string,string)'](
`${userIndex}DelegatingToken`,
`A${userIndex}DT`,
);
await delegation.connect(user).delegate(user.address);
};
const COMMON_LOCK_DURATION = time.duration.days('40');
const MAX_WHITELISTED = 3;
const BALANCE_THRESHOLD = 1000; // 10%

const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => {
await st1inch.connect(user).deposit(0, COMMON_LOCK_DURATION);
await st1inch.depositFor(user.address, amount);
await st1inch.connect(user).addPod(delegation.address);
await delegation
.connect(user)
.functions['register(string,string)'](
`${userIndex}DelegatingToken`,
`A${userIndex}DT`,
);
await delegation.connect(user).delegate(user.address);
};

const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => {
await st1inch.connect(from).deposit(amount, duration);
await st1inch.connect(from).addPod(delegation.address);
await delegation.connect(from).delegate(to);
};
const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = COMMON_LOCK_DURATION) => {
await st1inch.connect(from).deposit(amount, duration);
await st1inch.connect(from).addPod(delegation.address);
await delegation.connect(from).delegate(to);
};

async function initContracts() {
const accounts = await ethers.getSigners();
const [owner, alice] = accounts;
const [owner, alice, whitelistedUser1, /* whitelistedUser2 */, /* whitelistedUser3 */, clearAddress] = accounts;

const oneInch = await deployContract('ERC20PermitMock', ['1inch', '1inch', owner.address, ether('200')]);
await oneInch.transfer(alice.address, ether('100'));
Expand All @@ -52,16 +52,15 @@ describe('PowerPod', function () {

return {
contracts: { st1inch, delegation, whitelistRegistry },
accounts: { owner, alice, accounts },
accounts: { owner, alice, whitelistedUser1, clearAddress },
functions: { depositAndDelegateTo },
other: { commonLockDuration },
};
}

describe('Should calculate voting power', function () {
it('for account with 0 balance', async function () {
const { contracts: { delegation }, accounts: { accounts } } = await loadFixture(initContracts);
expect(await delegation.votingPowerOf(accounts[9].address)).to.equal(0);
const { contracts: { delegation }, accounts: { clearAddress } } = await loadFixture(initContracts);
expect(await delegation.votingPowerOf(clearAddress.address)).to.equal(0);
});

it('for account with st1inch balance', async function () {
Expand Down Expand Up @@ -93,12 +92,11 @@ describe('PowerPod', function () {
const {
contracts: { st1inch, delegation, whitelistRegistry },
accounts: { owner, alice },
other: { commonLockDuration },
} = await loadFixture(initContracts);
// delegate to owner and deposit 1inch
await st1inch.connect(alice).addPod(delegation.address);
await delegation.connect(alice).delegate(owner.address);
await st1inch.connect(alice).deposit(ether('2'), commonLockDuration);
await st1inch.connect(alice).deposit(ether('2'), COMMON_LOCK_DURATION);

await whitelistRegistry.register();
});
Expand Down Expand Up @@ -126,28 +124,28 @@ describe('PowerPod', function () {
it('should decrease delegatee balance, if delegator undelegate stake', async function () {
const {
contracts: { st1inch, delegation, whitelistRegistry },
accounts: { owner, alice, accounts },
accounts: { owner, alice, whitelistedUser1 },
functions: { depositAndDelegateTo },
} = await loadFixture(initContracts);
await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8'));
await whitelistRegistry.register();

await delegation.connect(alice).delegate(constants.ZERO_ADDRESS);
await whitelistRegistry.connect(accounts[2]).register();
await whitelistRegistry.connect(whitelistedUser1).register();
expect(await whitelistRegistry.getWhitelist()).to.not.contain(owner.address);
});

it('should decrease delegatee balance, if delegator delegate to other account', async function () {
const {
contracts: { st1inch, delegation, whitelistRegistry },
accounts: { owner, alice, accounts },
accounts: { owner, alice, whitelistedUser1 },
functions: { depositAndDelegateTo },
} = await loadFixture(initContracts);
await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8'));
await whitelistRegistry.register();

await delegation.connect(alice).delegate(accounts[2].address);
await whitelistRegistry.connect(accounts[2]).register();
await delegation.connect(alice).delegate(whitelistedUser1.address);
await whitelistRegistry.connect(whitelistedUser1).register();
expect(await whitelistRegistry.getWhitelist()).to.not.contain(owner.address);
});
});
Expand Down

0 comments on commit c5bac00

Please sign in to comment.