Skip to content

Commit

Permalink
Fix LIP-3 related unit tests #128
Browse files Browse the repository at this point in the history
  • Loading branch information
ongrid committed Nov 22, 2020
1 parent c19df22 commit c0685d8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 687 deletions.
74 changes: 37 additions & 37 deletions test/0.4.24/lido.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// +1 ETH
await web3.eth.sendTransaction({ to: app.address, from: user1, value: ETH(1) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 0, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 0, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await validatorRegistration.totalCalls(), 0)
assertBn(await app.getTotalPooledEther(), ETH(1))
assertBn(await app.getBufferedEther(), ETH(1))
Expand All @@ -236,7 +236,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {

// +2 ETH
await app.submit(ZERO_ADDRESS, { from: user2, value: ETH(2) }) // another form of a deposit call
await checkStat({ depositedValidators: 0, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 0, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await validatorRegistration.totalCalls(), 0)
assertBn(await app.getTotalPooledEther(), ETH(3))
assertBn(await app.getBufferedEther(), ETH(3))
Expand All @@ -246,7 +246,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// +30 ETH
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(30) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(33))
assertBn(await app.getBufferedEther(), ETH(1))
assertBn(await token.balanceOf(user1), tokens(1))
Expand All @@ -264,7 +264,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// +100 ETH
await web3.eth.sendTransaction({ to: app.address, from: user1, value: ETH(100) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 4, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 4, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(133))
assertBn(await app.getBufferedEther(), ETH(5))
assertBn(await token.balanceOf(user1), tokens(101))
Expand Down Expand Up @@ -333,7 +333,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {

await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(100) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await validatorRegistration.totalCalls(), 1)
assertBn(await app.getTotalPooledEther(), ETH(100))
assertBn(await app.getBufferedEther(), ETH(100 - 32))
Expand All @@ -348,7 +348,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
)
await web3.eth.sendTransaction({ to: app.address, from: user1, value: ETH(1) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await validatorRegistration.totalCalls(), 3)
assertBn(await app.getTotalPooledEther(), ETH(101))
assertBn(await app.getBufferedEther(), ETH(5))
Expand Down Expand Up @@ -380,7 +380,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
assertBn(await token.totalSupply(), tokens(1))
assertBn(await app.getBufferedEther(), ETH(1))

await checkStat({ depositedValidators: 0, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 0, beaconValidators: 0, beaconBalance: ETH(0) })

await assertRevert(app.withdraw(tokens(1), pad('0x1000', 32), { from: nobody }), 'NOT_IMPLEMENTED_YET')
await assertRevert(app.withdraw(tokens(1), pad('0x1000', 32), { from: user1 }), 'NOT_IMPLEMENTED_YET')
Expand All @@ -402,20 +402,20 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {

await web3.eth.sendTransaction({ to: app.address, from: user2, value: ETH(34) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0) })

await assertRevert(app.pushBeacon(1, ETH(30), { from: appManager }), 'APP_AUTH_FAILED')

await oracle.reportBeacon(100, 1, ETH(30))
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(30)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(30) })

await assertRevert(app.pushBeacon(1, ETH(29), { from: nobody }), 'APP_AUTH_FAILED')

await oracle.reportBeacon(50, 1, ETH(100)) // stale data
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(100)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(100) })

await oracle.reportBeacon(200, 1, ETH(33))
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(33)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(33) })
})

it('oracle data affects deposits', async () => {
Expand All @@ -436,15 +436,15 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {

await web3.eth.sendTransaction({ to: app.address, from: user2, value: ETH(34) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await validatorRegistration.totalCalls(), 1)
assertBn(await app.getTotalPooledEther(), ETH(34))
assertBn(await app.getBufferedEther(), ETH(2))

// down
await oracle.reportBeacon(100, 1, ETH(15))

await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(15)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(15) })
assertBn(await validatorRegistration.totalCalls(), 1)
assertBn(await app.getTotalPooledEther(), ETH(17))
assertBn(await app.getBufferedEther(), ETH(2))
Expand All @@ -454,7 +454,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await web3.eth.sendTransaction({ to: app.address, from: user1, value: ETH(2) })
await app.depositBufferedEther()

await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(15)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(15) })
assertBn(await validatorRegistration.totalCalls(), 1)
assertBn(await app.getTotalPooledEther(), ETH(19))
assertBn(await app.getBufferedEther(), ETH(4))
Expand All @@ -465,12 +465,12 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await assertRevert(oracle.reportBeacon(200, 2, ETH(48)), 'REPORTED_MORE_DEPOSITED')
await oracle.reportBeacon(200, 1, ETH(48))

await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(48)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(48) })
assertBn(await validatorRegistration.totalCalls(), 1)
assertBn(await app.getTotalPooledEther(), ETH(52))
assertBn(await app.getBufferedEther(), ETH(4))
assertBn(await token.totalSupply(), tokens(52))
/*
/*
// 2nd deposit, ratio is 2
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(2) })
Expand Down Expand Up @@ -502,7 +502,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {

await web3.eth.sendTransaction({ to: app.address, from: user2, value: ETH(40) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getBufferedEther(), ETH(8))

await assertRevert(app.stop({ from: user2 }), 'APP_AUTH_FAILED')
Expand All @@ -517,7 +517,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {

await web3.eth.sendTransaction({ to: app.address, from: user1, value: ETH(4) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 1, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getBufferedEther(), ETH(12))
})

Expand All @@ -542,7 +542,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await app.depositBufferedEther()

await oracle.reportBeacon(300, 1, ETH(36))
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(36)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(36) })
assertBn(await token.totalSupply(), tokens(38)) // remote + buffered
await checkRewards({ treasury: 599, insurance: 399, operator: 1000 })
})
Expand All @@ -569,22 +569,22 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// some slashing occured
await oracle.reportBeacon(100, 1, ETH(30))

await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(30)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(30) })
// ToDo check buffer=2
assertBn(await token.totalSupply(), tokens(32)) // 30 remote (slashed) + 2 buffered = 32
await checkRewards({ treasury: 0, insurance: 0, operator: 0 })

// rewarded 200 Ether (was 30, became 230)
await oracle.reportBeacon(200, 1, ETH(130))
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(130)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(130) })
// Todo check reward effects
//await checkRewards({ treasury: 0, insurance: 0, operator: 0 })
// await checkRewards({ treasury: 0, insurance: 0, operator: 0 })

await oracle.reportBeacon(300, 1, ETH(2230))
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(2230)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(2230) })
assertBn(await token.totalSupply(), tokens(2232))
// Todo check reward effects
//await checkRewards({ treasury: tokens(33), insurance: tokens(22), operator: tokens(55) })
// await checkRewards({ treasury: tokens(33), insurance: tokens(22), operator: tokens(55) })
})

it('deposits accounted properly during rewards distribution', async () => {
Expand All @@ -605,7 +605,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
assertBn(await token.totalSupply(), tokens(64))

await oracle.reportBeacon(300, 1, ETH(36))
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(36)})
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(36) })
assertBn(await token.totalSupply(), tokens(68))
await checkRewards({ treasury: 599, insurance: 399, operator: 1000 })
})
Expand Down Expand Up @@ -637,7 +637,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// Deposit huge chunk
await web3.eth.sendTransaction({ to: app.address, from: user1, value: ETH(32 * 3 + 50) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(146))
assertBn(await app.getBufferedEther(), ETH(50))
assertBn(await validatorRegistration.totalCalls(), 3)
Expand All @@ -655,7 +655,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// Next deposit changes nothing
await web3.eth.sendTransaction({ to: app.address, from: user2, value: ETH(32) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(178))
assertBn(await app.getBufferedEther(), ETH(82))
assertBn(await validatorRegistration.totalCalls(), 3)
Expand All @@ -674,7 +674,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await operators.reportStoppedValidators(1, 1, { from: voting })
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(1) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 4, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 4, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(179))
assertBn(await app.getBufferedEther(), ETH(51))
assertBn(await validatorRegistration.totalCalls(), 4)
Expand All @@ -693,7 +693,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await operators.addSigningKeys(0, 1, pad('0x0003', 48), pad('0x01', 96), { from: voting })
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(1) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 5, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 5, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(180))
assertBn(await app.getBufferedEther(), ETH(20))
assertBn(await validatorRegistration.totalCalls(), 5)
Expand All @@ -712,7 +712,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await operators.setNodeOperatorActive(2, true, { from: voting })
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(12) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 6, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 6, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(192))
assertBn(await app.getBufferedEther(), ETH(0))
assertBn(await validatorRegistration.totalCalls(), 6)
Expand Down Expand Up @@ -758,7 +758,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await web3.eth.sendTransaction({ to: app.address, from: user1, value: ETH(6) })
await app.depositBufferedEther()

await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(146))
assertBn(await app.getBufferedEther(), ETH(50))
assertBn(await validatorRegistration.totalCalls(), 3)
Expand All @@ -776,7 +776,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// Next deposit changes nothing
await web3.eth.sendTransaction({ to: app.address, from: user2, value: ETH(32) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(178))
assertBn(await app.getBufferedEther(), ETH(82))
assertBn(await validatorRegistration.totalCalls(), 3)
Expand All @@ -795,7 +795,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await operators.reportStoppedValidators(1, 1, { from: voting })
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(1) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 4, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 4, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(179))
assertBn(await app.getBufferedEther(), ETH(51))
assertBn(await validatorRegistration.totalCalls(), 4)
Expand All @@ -814,7 +814,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await operators.addSigningKeys(0, 1, pad('0x0003', 48), pad('0x01', 96), { from: voting })
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(1) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 5, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 5, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(180))
assertBn(await app.getBufferedEther(), ETH(20))
assertBn(await validatorRegistration.totalCalls(), 5)
Expand All @@ -833,7 +833,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await operators.setNodeOperatorActive(2, true, { from: voting })
await web3.eth.sendTransaction({ to: app.address, from: user3, value: ETH(12) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 6, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 6, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(192))
assertBn(await app.getBufferedEther(), ETH(0))
assertBn(await validatorRegistration.totalCalls(), 6)
Expand Down Expand Up @@ -876,7 +876,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
// #1 and #0 get the funds
await web3.eth.sendTransaction({ to: app.address, from: user2, value: ETH(64) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 2, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 2, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(64))
assertBn(await app.getBufferedEther(), ETH(0))
assertBn(await validatorRegistration.totalCalls(), 2)
Expand All @@ -890,7 +890,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody]) => {
await operators.setNodeOperatorActive(2, true, { from: voting })
await web3.eth.sendTransaction({ to: app.address, from: user2, value: ETH(36) })
await app.depositBufferedEther()
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0)})
await checkStat({ depositedValidators: 3, beaconValidators: 0, beaconBalance: ETH(0) })
assertBn(await app.getTotalPooledEther(), ETH(100))
assertBn(await app.getBufferedEther(), ETH(4))
assertBn(await validatorRegistration.totalCalls(), 3)
Expand Down
Loading

0 comments on commit c0685d8

Please sign in to comment.