Skip to content

Commit

Permalink
Fix e2e transfer test flakiness due to epoch rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
Or Neeman committed Jun 16, 2021
1 parent 9a3382a commit 7b323df
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/celotool/src/e2e-tests/transfer_tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable-next-line: no-reference (Required to make this work w/ ts-node)
import { CeloTxPending, CeloTxReceipt, TransactionResult } from '@celo/connect'
import { CeloContract, ContractKit, newKitFromWeb3 } from '@celo/contractkit'
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
import { CeloTokenType, EachCeloToken, StableToken, Token } from '@celo/contractkit/lib/celo-tokens'
import { eqAddress } from '@celo/utils/lib/address'
import { toFixed } from '@celo/utils/lib/fixidity'
Expand Down Expand Up @@ -158,13 +158,13 @@ describe('Transfer tests', function (this: any) {

let currentGethInstance: GethInstanceConfig

let governanceAddress: string // set later on using the contract itself
const validatorAddress = '0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95'
const DEF_FROM_PK = 'f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d'
const FromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631'

// Arbitrary addresses.
const txFeeRecipientAddress = '0x5555555555555555555555555555555555555555'
const governanceAddress = '0x00000000000000000000000000000000DeaDBeef'
const ToAddress = '0xbBae99F0E1EE565404465638d40827b54D343638'
const gatewayFeeRecipientAddress = '0x4f5f8a3f45d179553e7b95119ce296010f50f6f1'

Expand Down Expand Up @@ -239,13 +239,17 @@ describe('Transfer tests', function (this: any) {
3
)

// Install an arbitrary address as the goverance address to act as the infrastructure fund.
// This is chosen instead of full migration for speed and to avoid the need for a governance
// proposal, as all contracts are owned by governance once the migration is complete.
const registry = await kit._web3Contracts.getRegistry()
const tx = registry.methods.setAddressFor(CeloContract.Governance, governanceAddress)
const gas = await tx.estimateGas({ from: validatorAddress })
await tx.send({ from: validatorAddress, gas })
governanceAddress = (await kit._web3Contracts.getGovernance()).options.address
// The tests below check the balance of the governance contract (i.e. the community fund)
// before and after transactions to verify the correct amount has been received from the fees.
// This causes flakiness due to the fund also receiving epoch rewards (if the epoch change is
// between the blocks the balance checker uses as its before and after the test will fail due
// to the unexpected change from the epoch rewards).
// To avoid this, we set the community fund's fraction of epoch rewards to zero.
// Another option would have been to make the epoch size large enough so no epoch changes happen
// during the test.
const epochRewards = await kit._web3Contracts.getEpochRewards()
await epochRewards.methods.setCommunityRewardFraction(0).send({ from: validatorAddress })

// Give the account we will send transfers as sufficient gold and dollars.
const startBalance = TransferAmount.times(500)
Expand Down

0 comments on commit 7b323df

Please sign in to comment.