Skip to content

Commit

Permalink
Adjust e2e transfer and governance tests to match new fee distributio…
Browse files Browse the repository at this point in the history
…n and eliminate ProposerFraction (#1585)
  • Loading branch information
Victor "Nate" Graf authored and celo-ci-bot-user committed Nov 13, 2019
1 parent 9f4c083 commit 413739b
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 258 deletions.
77 changes: 36 additions & 41 deletions packages/celotool/src/e2e-tests/governance_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ describe('governance tests', () => {
return blockNumber % epochSize === 0
}

const assertBalanceChanged = async (
address: string,
blockNumber: number,
expected: BigNumber,
token: any
) => {
const currentBalance = new BigNumber(
await token.methods.balanceOf(address).call({}, blockNumber)
)
const previousBalance = new BigNumber(
await token.methods.balanceOf(address).call({}, blockNumber - 1)
)
assert.isNotNaN(currentBalance)
assert.isNotNaN(previousBalance)
assertAlmostEqual(currentBalance.minus(previousBalance), expected)
}

describe('when the validator set is changing', () => {
let epoch: number
const blockNumbers: number[] = []
Expand Down Expand Up @@ -302,24 +319,8 @@ describe('governance tests', () => {
)
const [group] = await validators.methods.getRegisteredValidatorGroups().call()

const assertBalanceChanged = async (
validator: string,
blockNumber: number,
expected: BigNumber
) => {
const currentBalance = new BigNumber(
await stableToken.methods.balanceOf(validator).call({}, blockNumber)
)
const previousBalance = new BigNumber(
await stableToken.methods.balanceOf(validator).call({}, blockNumber - 1)
)
assert.isNotNaN(currentBalance)
assert.isNotNaN(previousBalance)
assertAlmostEqual(currentBalance.minus(previousBalance), expected)
}

const assertBalanceUnchanged = async (validator: string, blockNumber: number) => {
await assertBalanceChanged(validator, blockNumber, new BigNumber(0))
await assertBalanceChanged(validator, blockNumber, new BigNumber(0), stableToken)
}

const getExpectedTotalPayment = async (validator: string, blockNumber: number) => {
Expand Down Expand Up @@ -359,17 +360,19 @@ describe('governance tests', () => {
await assertBalanceChanged(
validator,
blockNumber,
expectedTotalPayment.minus(groupPayment)
expectedTotalPayment.minus(groupPayment),
stableToken
)
expectedGroupPayment = expectedGroupPayment.plus(groupPayment)
}
await assertBalanceChanged(group, blockNumber, expectedGroupPayment)
await assertBalanceChanged(group, blockNumber, expectedGroupPayment, stableToken)
}
})

it('should distribute epoch rewards at the end of each epoch', async () => {
const lockedGold = await kit._web3Contracts.getLockedGold()
const governance = await kit._web3Contracts.getGovernance()
const gasPriceMinimum = await kit._web3Contracts.getGasPriceMinimum()
const [group] = await validators.methods.getRegisteredValidatorGroups().call()

const assertVotesChanged = async (blockNumber: number, expected: BigNumber) => {
Expand All @@ -382,6 +385,13 @@ describe('governance tests', () => {
assertAlmostEqual(currentVotes.minus(previousVotes), expected)
}

// Returns the gas fee base for a given block, which is distributed to the governance contract.
const blockBaseGasFee = async (blockNumber: number): Promise<BigNumber> => {
const gas = (await web3.eth.getBlock(blockNumber)).gasUsed
const gpm = await gasPriceMinimum.methods.gasPriceMinimum().call({}, blockNumber)
return new BigNumber(gpm).times(new BigNumber(gas))
}

const assertGoldTokenTotalSupplyChanged = async (
blockNumber: number,
expected: BigNumber
Expand All @@ -395,26 +405,12 @@ describe('governance tests', () => {
assertAlmostEqual(currentSupply.minus(previousSupply), expected)
}

const assertBalanceChanged = async (
address: string,
blockNumber: number,
expected: BigNumber
) => {
const currentBalance = new BigNumber(
await goldToken.methods.balanceOf(address).call({}, blockNumber)
)
const previousBalance = new BigNumber(
await goldToken.methods.balanceOf(address).call({}, blockNumber - 1)
)
assertAlmostEqual(currentBalance.minus(previousBalance), expected)
}

const assertLockedGoldBalanceChanged = async (blockNumber: number, expected: BigNumber) => {
await assertBalanceChanged(lockedGold.options.address, blockNumber, expected)
await assertBalanceChanged(lockedGold.options.address, blockNumber, expected, goldToken)
}

const assertGovernanceBalanceChanged = async (blockNumber: number, expected: BigNumber) => {
await assertBalanceChanged(governance.options.address, blockNumber, expected)
await assertBalanceChanged(governance.options.address, blockNumber, expected, goldToken)
}

const assertVotesUnchanged = async (blockNumber: number) => {
Expand All @@ -429,10 +425,6 @@ describe('governance tests', () => {
await assertLockedGoldBalanceChanged(blockNumber, new BigNumber(0))
}

const assertGovernanceBalanceUnchanged = async (blockNumber: number) => {
await assertGovernanceBalanceChanged(blockNumber, new BigNumber(0))
}

const getStableTokenSupplyChange = async (blockNumber: number) => {
const currentSupply = new BigNumber(
await stableToken.methods.totalSupply().call({}, blockNumber)
Expand Down Expand Up @@ -477,13 +469,16 @@ describe('governance tests', () => {
.plus(stableTokenSupplyChange.div(exchangeRate))
await assertVotesChanged(blockNumber, expectedEpochReward)
await assertLockedGoldBalanceChanged(blockNumber, expectedEpochReward)
await assertGovernanceBalanceChanged(blockNumber, expectedInfraReward)
await assertGovernanceBalanceChanged(
blockNumber,
expectedInfraReward.plus(await blockBaseGasFee(blockNumber))
)
await assertGoldTokenTotalSupplyChanged(blockNumber, expectedGoldTotalSupplyChange)
} else {
await assertVotesUnchanged(blockNumber)
await assertGoldTokenTotalSupplyUnchanged(blockNumber)
await assertLockedGoldBalanceUnchanged(blockNumber)
await assertGovernanceBalanceUnchanged(blockNumber)
await assertGovernanceBalanceChanged(blockNumber, await blockBaseGasFee(blockNumber))
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/e2e-tests/sync_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('sync tests', function(this: any) {
const instance: GethInstanceConfig = gethConfig.instances[0]
await killInstance(instance)
await initAndStartGeth(hooks.gethBinaryPath, instance)
await sleep(60) // wait for round change / resync
await sleep(120) // wait for round change / resync
const address = (await web3.eth.getAccounts())[0]
const currentBlock = await web3.eth.getBlock('latest')
for (let i = 0; i < gethConfig.instances.length; i++) {
Expand Down
Loading

0 comments on commit 413739b

Please sign in to comment.