Skip to content

Commit

Permalink
test gas usage against worst case scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
se3000 committed May 22, 2020
1 parent 23fdade commit 42072cd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.

Large diffs are not rendered by default.

@@ -1,5 +1,5 @@
GETH_VERSION: 1.9.12
flux_aggregator_wrapper: ../../../evm-contracts/abi/v0.6/FluxAggregator.json f1e5411a1c2c97a2f14a986f158a752bb3a13cb410ffdd674a8dba1afb53cf67
flux_aggregator_wrapper: ../../../evm-contracts/abi/v0.6/FluxAggregator.json 20e1368b958a1f79f1159b7fd6344bc5b2d6954f181ad39c6b67461357fe76f8
link_token_interface: ./generation/../../../../evm-test-helpers/src/LinkToken.json a16bfa4690d25769959dd59034f03d101a46ecbf7e774a57ca6874f8352c8568
solidity_request_id: ../../../evm-contracts/abi/v0.6/VRFRequestIDBaseTestHelper.json f0216e71d1bfeb6f85efe231e3ba9e751fb23b04b2a0d233b5edbd010d9488ec
solidity_verifier_wrapper: ../../../evm-contracts/abi/v0.6/VRFTestHelper.json 1b1736395f3b4c1fb90eab2fcadd0529a0f093ccb279fda1d0759a7164ef5674
Expand Down
2 changes: 1 addition & 1 deletion evm-contracts/src/v0.6/dev/FluxAggregator.sol
Expand Up @@ -81,7 +81,7 @@ contract FluxAggregator is AggregatorInterface, Owned {
* funds without the owner's intervention.)
*/
uint256 constant private RESERVE_ROUNDS = 2;
uint256 constant private MAX_ORACLE_COUNT = 100;
uint256 constant private MAX_ORACLE_COUNT = 77;

uint32 private reportingRoundId;
uint32 internal latestRoundId;
Expand Down
45 changes: 31 additions & 14 deletions evm-contracts/test/v0.6/FluxAggregator.test.ts
Expand Up @@ -1052,7 +1052,7 @@ describe('FluxAggregator', () => {
})
})

const limit = 100
const limit = 77
describe(`when adding more than ${limit} oracles`, () => {
let oracles: ethers.Wallet[]

Expand Down Expand Up @@ -1081,28 +1081,45 @@ describe('FluxAggregator', () => {
addresses = oracles.slice(50, 100).map(o => o.address)
await aggregator
.connect(personas.Carol)
.addOracles(addresses, addresses, 1, 100, rrDelay)
.addOracles(addresses, addresses, 1, oracles.length, rrDelay)
})

it('not use too much gas', async () => {
let tx: any
let receipt: any
let i: any

let txs = []
for (i = 0; i < limit; i++) {
tx = await aggregator
.connect(oracles[i])
.submit(nextRound, Math.floor(Math.random() * 10000))
txs.push(tx)
assert.deepEqual(
// test adveserial quickselect algo
[2, 4, 6, 8, 10, 12, 14, 16, 1, 9, 5, 11, 3, 13, 7, 15],
adverserialQuickselectList(16),
)
const inputs = adverserialQuickselectList(limit)
for (let i = 0; i < limit; i++) {
tx = await aggregator.connect(oracles[i]).submit(nextRound, inputs[i])
}
assert(!!tx)
if (!!tx) {
receipt = await tx.wait()
assert.isAbove(500_000, receipt.gasUsed.toNumber())
if (tx) {
const receipt = await tx.wait()
assert.isAbove(400_000, receipt.gasUsed.toNumber())
}
})

function adverserialQuickselectList(len: number): number[] {
const xs: number[] = []
const pi: number[] = []
for (let i = 0; i < len; i++) {
pi[i] = i
xs[i] = 0
}

for (let l = len; l > 0; l--) {
const pivot = Math.floor((l - 1) / 2)
xs[pi[pivot]] = l
const temp = pi[l - 1]
pi[l - 1] = pi[pivot]
pi[pivot] = temp
}
return xs
}

it('reverts when another oracle is added', async () => {
await matchers.evmRevert(
aggregator
Expand Down

0 comments on commit 42072cd

Please sign in to comment.