Skip to content

Commit

Permalink
Support manual list of verified contracts. (l2beat#913)
Browse files Browse the repository at this point in the history
* Support manual list of verified contracts.

* Fix typo.
  • Loading branch information
adamiak committed Nov 7, 2022
1 parent 779384d commit 0d67ad2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/config/scripts/checkVerifiedContracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Logger, LogLevel } from '@l2beat/common'
import { EthereumAddress } from '@l2beat/types'
import { config as dotenv } from 'dotenv'

import { bridges, layer2s } from '../../src'
Expand All @@ -7,6 +8,7 @@ import {
getUniqueContractsForAllProjects,
} from './addresses'
import { getEtherscanClient } from './etherscan'
import manuallyVerified from './manuallyVerified.json'
import {
loadPreviouslyVerifiedContracts,
saveResult,
Expand Down Expand Up @@ -37,6 +39,7 @@ export async function main() {
const addressVerificationMap = await verifyContracts(
addresses,
previouslyVerified,
new Set(manuallyVerified.map(EthereumAddress)),
etherscanClient,
workersCount,
logger,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
17 changes: 8 additions & 9 deletions packages/config/scripts/checkVerifiedContracts/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ import { VerificationMap } from './output'
export async function verifyContracts(
addresses: EthereumAddress[],
previouslyVerified: Set<EthereumAddress>,
manuallyVerified: Set<EthereumAddress>,
etherscanClient: EtherscanClient,
workersCount: number,
logger: Logger,
): Promise<VerificationMap> {
logger.info(`Processing ${addresses.length} addresses.`)
const result: VerificationMap = {}

// Copy previously verified contracts directly to result
addresses
.filter((a) => previouslyVerified.has(a))
.forEach((a) => (result[a.toString()] = true))

const { taskQueue, queueStatus } = prepareTaskQueueWithQuickFail(
async (address: EthereumAddress) => {
logger.info(`Checking ${address.toString()}...`)
Expand All @@ -29,10 +25,13 @@ export async function verifyContracts(
workersCount,
)

// Only check contracts that were not already verified
addresses
.filter((a) => !previouslyVerified.has(a))
.forEach((a) => taskQueue.addToBack(a))
addresses.forEach((address) => {
if (previouslyVerified.has(address) || manuallyVerified.has(address)) {
result[address.toString()] = true
} else {
taskQueue.addToBack(address)
}
})

await taskQueue.waitTilEmpty()
if (queueStatus.errorOccurred) {
Expand Down
8 changes: 8 additions & 0 deletions packages/config/test/checkVerifiedContracts/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ describe('checkVerifiedContracts:tasks', () => {
'0x2222222222222222222222222222222222222222',
'0x3333333333333333333333333333333333333333',
'0x4444444444444444444444444444444444444444',
'0x5555555555555555555555555555555555555555',
].map(EthereumAddress),
// previously verified:
new Set([
EthereumAddress('0x3333333333333333333333333333333333333333'),
]),
// manually verified:
new Set([
EthereumAddress('0x5555555555555555555555555555555555555555'),
]),
EthereumClientMock as unknown as EtherscanClient,
2,
Logger.SILENT,
Expand All @@ -36,6 +42,7 @@ describe('checkVerifiedContracts:tasks', () => {
'0x2222222222222222222222222222222222222222': false,
'0x3333333333333333333333333333333333333333': true,
'0x4444444444444444444444444444444444444444': false,
'0x5555555555555555555555555555555555555555': true,
})
})

Expand All @@ -54,6 +61,7 @@ describe('checkVerifiedContracts:tasks', () => {
'0x4444444444444444444444444444444444444444',
].map(EthereumAddress),
new Set(),
new Set(),
EthereumClientMock as unknown as EtherscanClient,
2,
Logger.SILENT,
Expand Down

0 comments on commit 0d67ad2

Please sign in to comment.