forked from ensdomains/ens-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wikiCheck.js
130 lines (104 loc) · 3.7 KB
/
wikiCheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const https = require('https')
const fs = require('fs')
const path = require('path')
const SUPPORTED_CHAINS = ['mainnet', 'sepolia', 'holesky']
//Updates to the wiki take 5 minutes to show up on this URL
const WIKI_DEPLOYMENTS_URL =
'https://raw.githubusercontent.com/wiki/ensdomains/ens-contracts/ENS-Contract-Deployments.md'
const getRawWikiData = (url) => {
return new Promise((resolve, reject) => {
https.get(url, (res) => {
let data = ''
res.on('data', (chunk) => {
data += chunk
})
res.on('end', () => {
resolve(data)
})
res.on('error', (err) => {
reject(err)
})
})
})
}
const getChainDeploymentsFromWiki = (chainIndex, lines) => {
const chainName = SUPPORTED_CHAINS[chainIndex]
const indexOfChain = lines.findIndex((line) => line.includes(chainName))
const indexOfNextChain = lines.findIndex(
(line, index) => index > indexOfChain && line.includes('#'),
)
const startOfChainDeployments = indexOfChain + 3
if (indexOfNextChain === -1) {
//If no next chain, then we are at the end of the file
const chainDeployments = lines.slice(startOfChainDeployments, lines.length)
return chainDeployments
}
const chainDeployments = lines.slice(
startOfChainDeployments,
indexOfNextChain,
)
return chainDeployments
}
const checkDeployment = (
chainName,
deploymentFilenames,
wikiDeployments,
i,
) => {
const deploymentFilename = deploymentFilenames[i]
const wikiDeploymentString = wikiDeployments.find((wikiDeployment) => {
const wikiDeploymentName = wikiDeployment.split('|')[1].trim()
const match = wikiDeploymentName.match(
new RegExp(`${deploymentFilename.split('.')[0].trim()}`),
)
return match && match?.[0] === match?.input
})
const wikiDeploymentAddress = wikiDeploymentString.substring(
wikiDeploymentString.indexOf('[') + 1,
wikiDeploymentString.lastIndexOf(']'),
)
const wikiEtherscanAddress = wikiDeploymentString.substring(
wikiDeploymentString.lastIndexOf('/') + 1,
wikiDeploymentString.lastIndexOf(')'),
)
const deployment = require(`./deployments/${chainName}/${deploymentFilename}`)
if (deployment.address !== wikiDeploymentAddress) {
throw new Error(
`Deployment ${i} in wiki and in the repository do not match for ${chainName}. Wiki: ${wikiDeploymentAddress}, Deployment: ${deployment.address}`,
)
}
if (deployment.address !== wikiEtherscanAddress) {
throw new Error(
`Etherscan address ${i} in wiki and in the repository do not match for ${chainName}. Wiki Etherscan: ${wikiEtherscanAddress}, Deployment: ${deployment.address}`,
)
}
}
const checkChain = async (chainIndex, lines) => {
const chainName = SUPPORTED_CHAINS[chainIndex]
const directoryPath = path.join(__dirname, 'deployments', chainName)
let deploymentFilenames = []
const files = await fs.promises.readdir(directoryPath)
const jsonFiles = files.filter(
(file) => path.extname(file).toLowerCase() === '.json',
)
//Don't include migrations file
deploymentFilenames = jsonFiles.slice(1)
const wikiDeployments = getChainDeploymentsFromWiki(chainIndex, lines)
if (wikiDeployments.length !== deploymentFilenames.length) {
throw new Error(
`Number of deployments in wiki and in the repository do not match for ${SUPPORTED_CHAINS[chainIndex]}`,
)
}
for (let i = 0; i < wikiDeployments.length; i++) {
checkDeployment(chainName, deploymentFilenames, wikiDeployments, i)
}
}
const run = async () => {
const data = await getRawWikiData(WIKI_DEPLOYMENTS_URL)
const lines = data.split('\n')
for (let i = 0; i < SUPPORTED_CHAINS.length; i++) {
await checkChain(i, lines)
}
console.log('All deployments match')
}
run()