Skip to content

Commit

Permalink
test/bonding: Document IVotes layer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Aug 25, 2023
1 parent 4246474 commit e602ab9
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions test/unit/BondingVotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,35 @@ describe("BondingVotes", () => {
})
})

/**
* These tests mock the internal checkpointing logic from `BondingVotes` and tests only the methods from the
* `IVotes` interface that are expected to proxy to that internal implementation. It deploys a new BondingVotes
* contract (BondingVotesERC5805Harness) which has a mocked implementation of those internal functions, with a
* corresponding implementation here in the `mock` object.
*/
describe("IVotes", () => {
const currentRound = 1000

// redefine it here to avoid overriding top-level var
let bondingVotes

const currentRound = 1000
// Same implementation as the BondingVotesERC5805Mock
const mock = {
getBondingStateAt: (_account, _round) => {
const intAddr = BigNumber.from(_account)

// lowest 4 bytes of address + _round
const amount = intAddr.mask(32).add(_round)
// (_account << 4) | _round
const delegateAddress = intAddr.shl(4).mask(160).or(_round)

return [
amount.toNumber(),
ethers.utils.getAddress(delegateAddress.toHexString())
]
},
getTotalActiveStakeAt: _round => 4 * _round
}

before(async () => {
const HarnessFac = await ethers.getContractFactory(
Expand All @@ -1187,24 +1211,6 @@ describe("BondingVotes", () => {
)
})

// Same implementation as the BondingVotesERC5805Mock
const mock = {
getBondingStateAt: (_account, _round) => {
const intAddr = BigNumber.from(_account)

// lowest 4 bytes of address + _round
const amount = intAddr.mask(32).add(_round)
// (_account << 4) | _round
const delegateAddress = intAddr.shl(4).mask(160).or(_round)

return [
amount.toNumber(),
ethers.utils.getAddress(delegateAddress.toHexString())
]
},
getTotalActiveStakeAt: _round => 4 * _round
}

it("ensure harness was deployed", async () => {
assert.equal(
await fixture.controller.getContract(
Expand Down

0 comments on commit e602ab9

Please sign in to comment.