Skip to content

Commit c432e5a

Browse files
committed
additional testcases
1 parent ab2eb62 commit c432e5a

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed

scripts/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ task('deploy:wampl', 'Deploy wampl contract')
149149
.connect(deployer)
150150
.deploy(...constructorArguments)
151151
console.log('wAMPL deployed to:', wampl.address)
152-
await wampl.deployTransaction.wait()
152+
await wampl.deployTransaction.wait(5)
153153

154154
await hre.run('verify:verify', {
155155
address: wampl.address,

test/unit/WAMPL.ts

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ let accounts: Signer[],
2323
userC: Signer,
2424
userCAddress: string,
2525
ampl: Contract,
26-
wAMPL: Contract
26+
wAMPL: Contract,
27+
balanceBefore: BigNumber,
28+
balanceAfter: BigNumber
2729

2830
async function setupContracts() {
2931
accounts = await ethers.getSigners()
@@ -108,8 +110,10 @@ describe('WAMPL:deposit', () => {
108110
await wAMPL.connect(deployer).callStatic.deposit(amplesDeposited),
109111
).to.eq(wamplesMinted)
110112

113+
balanceBefore = await ampl.balanceOf(deployerAddress)
111114
r = wAMPL.connect(deployer).deposit(amplesDeposited)
112115
await r
116+
balanceAfter = await ampl.balanceOf(deployerAddress)
113117
})
114118

115119
it('should mint wamples', async function () {
@@ -127,6 +131,7 @@ describe('WAMPL:deposit', () => {
127131
await expect(r)
128132
.to.emit(ampl, 'Transfer')
129133
.withArgs(deployerAddress, wAMPL.address, amplesDeposited)
134+
expect(balanceBefore.sub(balanceAfter)).to.eq(amplesDeposited)
130135
})
131136

132137
it('should log mint', async function () {
@@ -157,8 +162,10 @@ describe('WAMPL:depositFor', () => {
157162
.callStatic.depositFor(userBAddress, amplesDeposited),
158163
).to.eq(wamplesMinted)
159164

165+
balanceBefore = await ampl.balanceOf(deployerAddress)
160166
r = wAMPL.connect(deployer).depositFor(userBAddress, amplesDeposited)
161167
await r
168+
balanceAfter = await ampl.balanceOf(deployerAddress)
162169
})
163170

164171
it('should mint wamples', async function () {
@@ -176,6 +183,7 @@ describe('WAMPL:depositFor', () => {
176183
await expect(r)
177184
.to.emit(ampl, 'Transfer')
178185
.withArgs(deployerAddress, wAMPL.address, amplesDeposited)
186+
expect(balanceBefore.sub(balanceAfter)).to.eq(amplesDeposited)
179187
})
180188

181189
it('should log mint', async function () {
@@ -220,8 +228,10 @@ describe('WAMPL:withdraw', () => {
220228
await wAMPL.connect(deployer).callStatic.withdraw(amplesWithdrawn),
221229
).to.eq(wamplesBurnt)
222230

231+
balanceBefore = await ampl.balanceOf(deployerAddress)
223232
r = wAMPL.connect(deployer).withdraw(amplesWithdrawn)
224233
await r
234+
balanceAfter = await ampl.balanceOf(deployerAddress)
225235
})
226236

227237
it('should burn wamples', async function () {
@@ -239,6 +249,7 @@ describe('WAMPL:withdraw', () => {
239249
await expect(r)
240250
.to.emit(ampl, 'Transfer')
241251
.withArgs(wAMPL.address, deployerAddress, amplesWithdrawn)
252+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesWithdrawn)
242253
})
243254

244255
it('should log burn', async function () {
@@ -285,8 +296,10 @@ describe('WAMPL:withdrawTo', () => {
285296
.callStatic.withdrawTo(userBAddress, amplesWithdrawn),
286297
).to.eq(wamplesBurnt)
287298

299+
balanceBefore = await ampl.balanceOf(userBAddress)
288300
r = wAMPL.connect(deployer).withdrawTo(userBAddress, amplesWithdrawn)
289301
await r
302+
balanceAfter = await ampl.balanceOf(userBAddress)
290303
})
291304

292305
it('should burn wamples', async function () {
@@ -306,6 +319,7 @@ describe('WAMPL:withdrawTo', () => {
306319
await expect(r)
307320
.to.emit(ampl, 'Transfer')
308321
.withArgs(wAMPL.address, userBAddress, amplesWithdrawn)
322+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesWithdrawn)
309323
})
310324

311325
it('should log burn', async function () {
@@ -336,8 +350,10 @@ describe('WAMPL:withdrawAll', () => {
336350
wamplesMinted,
337351
)
338352

353+
balanceBefore = await ampl.balanceOf(deployerAddress)
339354
r = wAMPL.connect(deployer).withdrawAll()
340355
await r
356+
balanceAfter = await ampl.balanceOf(deployerAddress)
341357
})
342358

343359
it('should burn wamples', async function () {
@@ -353,6 +369,7 @@ describe('WAMPL:withdrawAll', () => {
353369
await expect(r)
354370
.to.emit(ampl, 'Transfer')
355371
.withArgs(wAMPL.address, deployerAddress, amplesDeposited)
372+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesDeposited)
356373
})
357374

358375
it('should log burn', async function () {
@@ -383,8 +400,10 @@ describe('WAMPL:withdrawAllTo', () => {
383400
await wAMPL.connect(deployer).callStatic.withdrawAllTo(userBAddress),
384401
).to.eq(wamplesMinted)
385402

403+
balanceBefore = await ampl.balanceOf(userBAddress)
386404
r = wAMPL.connect(deployer).withdrawAllTo(userBAddress)
387405
await r
406+
balanceAfter = await ampl.balanceOf(userBAddress)
388407
})
389408

390409
it('should burn wamples', async function () {
@@ -402,6 +421,7 @@ describe('WAMPL:withdrawAllTo', () => {
402421
await expect(r)
403422
.to.emit(ampl, 'Transfer')
404423
.withArgs(wAMPL.address, userBAddress, amplesDeposited)
424+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesDeposited)
405425
})
406426

407427
it('should log burn', async function () {
@@ -430,8 +450,10 @@ describe('WAMPL:mint', () => {
430450
amplesDeposited,
431451
)
432452

453+
balanceBefore = await ampl.balanceOf(deployerAddress)
433454
r = wAMPL.connect(deployer).mint(wamplesMinted)
434455
await r
456+
balanceAfter = await ampl.balanceOf(deployerAddress)
435457
})
436458

437459
it('should mint wamples', async function () {
@@ -449,6 +471,7 @@ describe('WAMPL:mint', () => {
449471
await expect(r)
450472
.to.emit(ampl, 'Transfer')
451473
.withArgs(deployerAddress, wAMPL.address, amplesDeposited)
474+
expect(balanceBefore.sub(balanceAfter)).to.eq(amplesDeposited)
452475
})
453476

454477
it('should log mint', async function () {
@@ -479,8 +502,10 @@ describe('WAMPL:mintFor', () => {
479502
.callStatic.mintFor(userBAddress, wamplesMinted),
480503
).to.eq(amplesDeposited)
481504

505+
balanceBefore = await ampl.balanceOf(deployerAddress)
482506
r = wAMPL.connect(deployer).mintFor(userBAddress, wamplesMinted)
483507
await r
508+
balanceAfter = await ampl.balanceOf(deployerAddress)
484509
})
485510

486511
it('should mint wamples', async function () {
@@ -498,6 +523,7 @@ describe('WAMPL:mintFor', () => {
498523
await expect(r)
499524
.to.emit(ampl, 'Transfer')
500525
.withArgs(deployerAddress, wAMPL.address, amplesDeposited)
526+
expect(balanceBefore.sub(balanceAfter)).to.eq(amplesDeposited)
501527
})
502528

503529
it('should log mint', async function () {
@@ -542,8 +568,10 @@ describe('WAMPL:burn', () => {
542568
amplesWithdrawn,
543569
)
544570

571+
balanceBefore = await ampl.balanceOf(deployerAddress)
545572
r = wAMPL.connect(deployer).burn(wamplesBurnt)
546573
await r
574+
balanceAfter = await ampl.balanceOf(deployerAddress)
547575
})
548576

549577
it('should burn wamples', async function () {
@@ -561,6 +589,7 @@ describe('WAMPL:burn', () => {
561589
await expect(r)
562590
.to.emit(ampl, 'Transfer')
563591
.withArgs(wAMPL.address, deployerAddress, amplesWithdrawn)
592+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesWithdrawn)
564593
})
565594

566595
it('should log burn', async function () {
@@ -607,8 +636,10 @@ describe('WAMPL:burnTo', () => {
607636
.callStatic.burnTo(userBAddress, wamplesBurnt),
608637
).to.eq(amplesWithdrawn)
609638

639+
balanceBefore = await ampl.balanceOf(userBAddress)
610640
r = wAMPL.connect(deployer).burnTo(userBAddress, wamplesBurnt)
611641
await r
642+
balanceAfter = await ampl.balanceOf(userBAddress)
612643
})
613644

614645
it('should burn wamples', async function () {
@@ -628,6 +659,7 @@ describe('WAMPL:burnTo', () => {
628659
await expect(r)
629660
.to.emit(ampl, 'Transfer')
630661
.withArgs(wAMPL.address, userBAddress, amplesWithdrawn)
662+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesWithdrawn)
631663
})
632664

633665
it('should log burn', async function () {
@@ -658,8 +690,10 @@ describe('WAMPL:burnAll', () => {
658690
amplesDeposited,
659691
)
660692

693+
balanceBefore = await ampl.balanceOf(deployerAddress)
661694
r = wAMPL.connect(deployer).burnAll()
662695
await r
696+
balanceAfter = await ampl.balanceOf(deployerAddress)
663697
})
664698

665699
it('should burn wamples', async function () {
@@ -681,6 +715,7 @@ describe('WAMPL:burnAll', () => {
681715
await expect(r)
682716
.to.emit(wAMPL, 'Transfer')
683717
.withArgs(deployerAddress, ethers.constants.AddressZero, wamplesMinted)
718+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesDeposited)
684719
})
685720
})
686721

@@ -705,8 +740,10 @@ describe('WAMPL:burnAllTo', () => {
705740
await wAMPL.connect(deployer).callStatic.burnAllTo(userBAddress),
706741
).to.eq(amplesDeposited)
707742

743+
balanceBefore = await ampl.balanceOf(userBAddress)
708744
r = wAMPL.connect(deployer).withdrawAllTo(userBAddress)
709745
await r
746+
balanceAfter = await ampl.balanceOf(userBAddress)
710747
})
711748

712749
it('should burn wamples', async function () {
@@ -724,6 +761,7 @@ describe('WAMPL:burnAllTo', () => {
724761
await expect(r)
725762
.to.emit(ampl, 'Transfer')
726763
.withArgs(wAMPL.address, userBAddress, amplesDeposited)
764+
expect(balanceAfter.sub(balanceBefore)).to.eq(amplesDeposited)
727765
})
728766

729767
it('should log burn', async function () {
@@ -854,3 +892,64 @@ describe('Underlying Rebase:Contraction', async function () {
854892
expect(await wAMPL.balanceOf(userCAddress)).to.eq(toWAMPLFixedPt('60000'))
855893
})
856894
})
895+
896+
897+
describe('user sends funds to the contract incorrectly', async function () {
898+
beforeEach('setup WAMPL contract', setupContracts)
899+
900+
beforeEach(async function () {
901+
await ampl
902+
.connect(deployer)
903+
.transfer(userAAddress, toAMPLFixedPt('1000000'))
904+
await ampl
905+
.connect(deployer)
906+
.transfer(userBAddress, toAMPLFixedPt('1000000'))
907+
await ampl
908+
.connect(deployer)
909+
.transfer(userCAddress, toAMPLFixedPt('1000000'))
910+
911+
await ampl.connect(userA).approve(wAMPL.address, toAMPLFixedPt('100000'))
912+
await ampl.connect(userB).approve(wAMPL.address, toAMPLFixedPt('200000'))
913+
await ampl.connect(userC).approve(wAMPL.address, toAMPLFixedPt('300000'))
914+
915+
await wAMPL.connect(userA).deposit(toAMPLFixedPt('100000'))
916+
await wAMPL.connect(userB).deposit(toAMPLFixedPt('200000'))
917+
await wAMPL.connect(userC).deposit(toAMPLFixedPt('300000'))
918+
})
919+
920+
it('should not affect balances', async function () {
921+
expect(await wAMPL.totalUnderlying()).to.eq(toAMPLFixedPt('600000'))
922+
expect(await wAMPL.balanceOfUnderlying(userAAddress)).to.eq(
923+
toAMPLFixedPt('100000'),
924+
)
925+
expect(await wAMPL.balanceOfUnderlying(userBAddress)).to.eq(
926+
toAMPLFixedPt('200000'),
927+
)
928+
expect(await wAMPL.balanceOfUnderlying(userCAddress)).to.eq(
929+
toAMPLFixedPt('300000'),
930+
)
931+
932+
expect(await wAMPL.totalSupply()).to.eq(toWAMPLFixedPt('120000'))
933+
expect(await wAMPL.balanceOf(userAAddress)).to.eq(toWAMPLFixedPt('20000'))
934+
expect(await wAMPL.balanceOf(userBAddress)).to.eq(toWAMPLFixedPt('40000'))
935+
expect(await wAMPL.balanceOf(userCAddress)).to.eq(toWAMPLFixedPt('60000'))
936+
937+
await ampl.transfer(wAMPL.address, toAMPLFixedPt('300000'))
938+
939+
expect(await wAMPL.totalUnderlying()).to.eq(toAMPLFixedPt('600000'))
940+
expect(await wAMPL.balanceOfUnderlying(userAAddress)).to.eq(
941+
toAMPLFixedPt('100000'),
942+
)
943+
expect(await wAMPL.balanceOfUnderlying(userBAddress)).to.eq(
944+
toAMPLFixedPt('200000'),
945+
)
946+
expect(await wAMPL.balanceOfUnderlying(userCAddress)).to.eq(
947+
toAMPLFixedPt('300000'),
948+
)
949+
950+
expect(await wAMPL.totalSupply()).to.eq(toWAMPLFixedPt('120000'))
951+
expect(await wAMPL.balanceOf(userAAddress)).to.eq(toWAMPLFixedPt('20000'))
952+
expect(await wAMPL.balanceOf(userBAddress)).to.eq(toWAMPLFixedPt('40000'))
953+
expect(await wAMPL.balanceOf(userCAddress)).to.eq(toWAMPLFixedPt('60000'))
954+
})
955+
})

0 commit comments

Comments
 (0)