Skip to content

Commit

Permalink
updated staking pool tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BkChoy committed Jun 6, 2024
1 parent fdd0d9f commit 24ce280
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
21 changes: 17 additions & 4 deletions contracts/core/interfaces/IStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ pragma solidity 0.8.15;
import "./IStakingRewardsPool.sol";

interface IStakingPool is IStakingRewardsPool {
function deposit(address _account, uint256 _amount) external;
function deposit(
address _account,
uint256 _amount,
bytes[] calldata _data
) external;

function withdraw(
address _account,
address _receiver,
uint256 _amount
uint256 _amount,
bytes[] calldata _data
) external;

function strategyDeposit(uint256 _index, uint256 _amount) external;
function strategyDeposit(
uint256 _index,
uint256 _amount,
bytes calldata _data
) external;

function strategyWithdraw(uint256 _index, uint256 _amount) external;
function strategyWithdraw(
uint256 _index,
uint256 _amount,
bytes calldata _data
) external;

function updateStrategyRewards(uint256[] memory _strategyIdxs, bytes memory _data) external;

Expand Down
4 changes: 2 additions & 2 deletions contracts/core/interfaces/IStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity 0.8.15;

interface IStrategy {
function deposit(uint256 _amount) external;
function deposit(uint256 _amount, bytes calldata _data) external;

function withdraw(uint256 _amount) external;
function withdraw(uint256 _amount, bytes calldata _data) external;

function updateDeposits(bytes calldata _data)
external
Expand Down
28 changes: 16 additions & 12 deletions test/core/staking-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ describe('StakingPool', () => {

async function stake(account: number, amount: number) {
await token.connect(signers[account]).transfer(accounts[0], toEther(amount))
await stakingPool.deposit(accounts[account], toEther(amount))
await stakingPool.deposit(accounts[account], toEther(amount), ['0x', '0x', '0x'])
}

async function withdraw(account: number, amount: number) {
await stakingPool.withdraw(accounts[account], accounts[account], toEther(amount))
await stakingPool.withdraw(accounts[account], accounts[account], toEther(amount), [
'0x',
'0x',
'0x',
])
}

before(async () => {
Expand Down Expand Up @@ -83,7 +87,7 @@ describe('StakingPool', () => {
await stakingPool.setRebaseController(accounts[0])

await token.approve(stakingPool.address, ethers.constants.MaxUint256)
await stakingPool.deposit(accounts[0], 1000)
await stakingPool.deposit(accounts[0], 1000, ['0x', '0x'])
})

it('derivative token metadata should be correct', async () => {
Expand Down Expand Up @@ -139,15 +143,15 @@ describe('StakingPool', () => {
})

it('should be able to remove strategies', async () => {
await stakingPool.removeStrategy(1, '0x')
await stakingPool.removeStrategy(1, '0x', '0x')
let strategies = await stakingPool.getStrategies()
assert.equal(
JSON.stringify(strategies),
JSON.stringify([strategy1.address, strategy3.address]),
'Remaining strategies incorrect'
)

await stakingPool.removeStrategy(1, '0x')
await stakingPool.removeStrategy(1, '0x', '0x')
strategies = await stakingPool.getStrategies()
assert.equal(
JSON.stringify(strategies),
Expand All @@ -158,7 +162,7 @@ describe('StakingPool', () => {

it('should not be able remove nonexistent strategy', async () => {
await assertThrowsAsync(async () => {
await stakingPool.removeStrategy(3, '0x')
await stakingPool.removeStrategy(3, '0x', '0x')
}, 'revert')
})

Expand Down Expand Up @@ -188,27 +192,27 @@ describe('StakingPool', () => {

it('should be able to deposit into strategy', async () => {
await token.transfer(stakingPool.address, toEther(1000))
await stakingPool.strategyDeposit(0, toEther(300))
await stakingPool.strategyDeposit(0, toEther(300), '0x')
assert.equal(fromEther(await token.balanceOf(strategy1.address)), 300, 'Tokens not deposited')
})

it('should not be able to deposit into nonexistent strategy', async () => {
await token.transfer(stakingPool.address, toEther(1000))
await assertThrowsAsync(async () => {
await stakingPool.strategyDeposit(3, toEther(1))
await stakingPool.strategyDeposit(3, toEther(1), '0x')
}, 'revert')
})

it('should be able to withdraw from strategy', async () => {
await token.transfer(stakingPool.address, toEther(1000))
await stakingPool.strategyDeposit(0, toEther(300))
await stakingPool.strategyWithdraw(0, toEther(100))
await stakingPool.strategyDeposit(0, toEther(300), '0x')
await stakingPool.strategyWithdraw(0, toEther(100), '0x')
assert.equal(fromEther(await token.balanceOf(strategy1.address)), 200, 'Tokens not withdrawn')
})

it('should not be able to withdraw from nonexistent strategy', async () => {
await assertThrowsAsync(async () => {
await stakingPool.strategyWithdraw(3, toEther(1))
await stakingPool.strategyWithdraw(3, toEther(1), '0x')
}, 'revert')
})

Expand Down Expand Up @@ -307,7 +311,7 @@ describe('StakingPool', () => {
await stake(1, 2000)
await stake(2, 1000)
await stake(3, 2000)
await stakingPool.strategyWithdraw(0, toEther(100))
await stakingPool.strategyWithdraw(0, toEther(100), '0x')
await withdraw(3, 2000)
assert.equal(
fromEther(await token.balanceOf(strategy1.address)),
Expand Down

0 comments on commit 24ce280

Please sign in to comment.