-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathStakePrizePool.test.js
128 lines (95 loc) · 4.1 KB
/
StakePrizePool.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const { deployMockContract } = require('ethereum-waffle')
const { ethers } = require('ethers')
const { expect } = require('chai')
const hardhat = require('hardhat')
const toWei = ethers.utils.parseEther
const debug = require('debug')('ptv3:PrizePool.test')
let overrides = { gasLimit: 9500000 }
describe('StakePrizePool', function() {
let wallet, wallet2
let prizePool, erc20token, erc721token, stakeToken, prizeStrategy, registry
let poolMaxExitFee = toWei('0.5')
let ticket
let initializeTxPromise
let isInitializeTest = false
const initializeStakePrizePool = async (stakeTokenAddress) => {
return await prizePool['initialize(address,address[],uint256,address)'](
registry.address,
[ticket.address],
poolMaxExitFee,
stakeTokenAddress,
);
}
beforeEach(async () => {
[wallet, wallet2] = await hardhat.ethers.getSigners()
debug(`using wallet ${wallet.address}`)
debug('mocking tokens...')
const IERC20 = await hre.artifacts.readArtifact("IERC20Upgradeable")
erc20token = await deployMockContract(wallet, IERC20.abi, overrides)
const IERC721 = await hre.artifacts.readArtifact("IERC721Upgradeable")
erc721token = await deployMockContract(wallet, IERC721.abi, overrides)
const ERC20Mintable = await hre.artifacts.readArtifact("ERC20Mintable")
stakeToken = await deployMockContract(wallet, ERC20Mintable.abi, overrides)
// await stakeToken.mock.underlying.returns(erc20token.address)
const TokenListenerInterface = await hre.artifacts.readArtifact("TokenListenerInterface")
prizeStrategy = await deployMockContract(wallet, TokenListenerInterface.abi, overrides)
await prizeStrategy.mock.supportsInterface.returns(true)
await prizeStrategy.mock.supportsInterface.withArgs('0xffffffff').returns(false)
const RegistryInterface = await hre.artifacts.readArtifact("RegistryInterface")
registry = await deployMockContract(wallet, RegistryInterface.abi, overrides)
debug('deploying StakePrizePoolHarness...')
const StakePrizePoolHarness = await hre.ethers.getContractFactory("StakePrizePoolHarness", wallet, overrides)
prizePool = await StakePrizePoolHarness.deploy()
const ControlledToken = await hre.artifacts.readArtifact("ControlledToken")
ticket = await deployMockContract(wallet, ControlledToken.abi, overrides)
await ticket.mock.controller.returns(prizePool.address)
if (!isInitializeTest) {
initializeTxPromise = await initializeStakePrizePool(stakeToken.address)
await prizePool.setPrizeStrategy(prizeStrategy.address)
}
})
describe('initialize()', () => {
before(() => {
isInitializeTest = true
})
after(() => {
isInitializeTest = false
})
it('should initialize StakePrizePool', async () => {
initializeTxPromise = await initializeStakePrizePool(stakeToken.address)
await expect(initializeTxPromise)
.to.emit(prizePool, 'StakePrizePoolInitialized')
.withArgs(
stakeToken.address
)
})
it('should fail to initialize StakePrizePool if stakeToken is address zero', async () => {
await expect(
initializeStakePrizePool(ethers.constants.AddressZero)
).to.be.revertedWith('StakePrizePool/stake-token-not-zero-address')
})
})
describe('_redeem()', () => {
it('should return amount staked', async () => {
let amount = toWei('500')
await stakeToken.mock.balanceOf.withArgs(prizePool.address).returns(toWei('32'))
await prizePool.redeem(amount)
})
})
describe('canAwardExternal()', () => {
it('should not allow the stake award', async () => {
expect(await prizePool.canAwardExternal(stakeToken.address)).to.be.false
})
})
describe('balance()', () => {
it('should return the staked balance', async () => {
await stakeToken.mock.balanceOf.withArgs(prizePool.address).returns(toWei('32'))
expect(await prizePool.callStatic.balance()).to.equal(toWei('32'))
})
})
describe('_token()', () => {
it('should return the staked token token', async () => {
expect(await prizePool.token()).to.equal(stakeToken.address)
})
})
});