Skip to content

Commit

Permalink
Merge pull request #193 from ensdomains/FET-1573_pagination_issue
Browse files Browse the repository at this point in the history
FET-1573 pagination issue
  • Loading branch information
storywithoutend authored Nov 10, 2024
2 parents 0781da0 + f8c39e9 commit f3b3a86
Show file tree
Hide file tree
Showing 19 changed files with 1,242 additions and 458 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Release
on:
release:
types: [published]

jobs:
release:
name: Release
permissions:
id-token: write
contents: write
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
NPM_CONFIG_PROVENANCE: true
run: |
pnpm config set //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
pnpm -F @ensdomains/ensjs publish
pnpm -F @ensdomains/ensjs publish --no-git-checks
- name: Push changes
run: git push
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.18.2
97 changes: 57 additions & 40 deletions packages/ens-test-env/src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const awaitCommand = async (name, command) => {
deploy.stdout.pipe(outPrepender).pipe(process.stdout)
}
deploy.stderr.pipe(errPrepender).pipe(process.stderr)
deploy.stderr.on('data', cleanup.bind(null, { exit: true }))
return new Promise((resolve) => deploy.on('exit', () => resolve()))
}

Expand Down Expand Up @@ -188,6 +189,7 @@ export const main = async (_config, _options, justKill) => {
const compose = await getCompose()

try {
console.log('Starting anvil...')
await compose.upOne('anvil', opts)
} catch (e) {
console.error('e: ', e)
Expand Down Expand Up @@ -279,11 +281,62 @@ export const main = async (_config, _options, justKill) => {

if (options.graph) {
try {
console.log('Starting graph-node...')
await compose.upOne('graph-node', opts)

await waitOn({ resources: ['http://localhost:8040'] })

const latestBlock = await rpcFetch('eth_getBlockByNumber', ['latest', false])
const latestBlockNumber = parseInt(latestBlock.result.number, 16)
if (Number.isNaN(latestBlockNumber)) {
console.error('Failed to fetch latest block number')
return cleanup(undefined, 0)
}
console.log('latest block number:', latestBlockNumber)

let indexArray = []
const getCurrentIndex = async () =>
fetch('http://localhost:8000/subgraphs/name/graphprotocol/ens', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
{
_meta {
block {
number
}
}
}
`,
variables: {},
}),
})
.then((res) => res.json())
.then((res) => {
if (res.errors) return 0
return res.data._meta.block.number
})
.catch(() => 0)
do {
const index = await getCurrentIndex()
console.log('subgraph index:', index)
indexArray.push(await getCurrentIndex())
if (indexArray.length > 10) indexArray.shift()
await new Promise((resolve) => setTimeout(resolve, 1000))
if (indexArray.every((i) => i === indexArray[0]) && indexArray.length === 10) {
console.error('Subgraph failed to launch properly')
return cleanup(undefined, 0)
}
} while (
indexArray[indexArray.length - 1] < latestBlockNumber
)
console.log('Starting remaining docker containers...')
await compose.upAll(opts)
} catch {}

await waitOn({ resources: ['http://localhost:8040'] })

if (options.save) {
const internalHashes = [
{
Expand Down Expand Up @@ -336,48 +389,12 @@ export const main = async (_config, _options, justKill) => {
'http-get://localhost:8000/subgraphs/name/graphprotocol/ens',
],
})
await new Promise((resolve) => setTimeout(resolve, 100))
}
}

await new Promise((resolve) => setTimeout(resolve, 100))

if (!options.save && cmdsToRun.length > 0 && options.scripts) {
if (options.graph) {
let indexArray = []
const getCurrentIndex = async () =>
fetch('http://localhost:8000/subgraphs/name/graphprotocol/ens', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
{
_meta {
block {
number
}
}
}
`,
variables: {},
}),
})
.then((res) => res.json())
.then((res) => {
if (res.errors) return 0
return res.data._meta.block.number
})
.catch(() => 0)
do {
indexArray.push(await getCurrentIndex())
if (indexArray.length > 10) indexArray.shift()
await new Promise((resolve) => setTimeout(resolve, 100))
} while (
!indexArray.every((i) => i === indexArray[0]) ||
indexArray.length < 2 ||
indexArray[0] === 0
)
}
/**
* @type {import('concurrently').ConcurrentlyResult['result']}
**/
Expand Down
221 changes: 221 additions & 0 deletions packages/ensjs/deploy/00_register_concurrently.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-await-in-loop */
// eslint-disable-next-line @typescript-eslint/naming-convention
const { BigNumber } = require('ethers')
const { ethers } = require('hardhat')
const {
makeNameGenerator: makeWrappedNameGenerator,
} = require('../utils/wrappedNameGenerator.cjs')
const {
makeNameGenerator: makeLegacyNameGenerator,
} = require('../utils/legacyNameGenerator.cjs')
const { makeNonceManager } = require('../utils/nonceManager.cjs')
const { encodeFuses } = require('../dist/cjs/utils/fuses')
const { MAX_DATE_INT } = require('../dist/cjs/utils/consts')

const DURATION = 31556000

/**
* @type {{
* label: string
* namedOwner: string
* namedAddr?: string
* type: 'wrapped' | 'legacy'
* data?: any[]
* reverseRecord?: boolean
* fuses?: number
* subnames?: {
* label: string
* namedOwner: string
* fuses?: number
* expiry?: number
* }[]
* duration?: number | BigNumber
* }[]}
*/

const names = [
...Array.from({ length: 2 }, (_, index) => ({
label: `concurrent-legacy-name-${index}`,
type: 'legacy',
namedOwner: 'owner4',
reverseRecord: true,
duration: DURATION,
})),
...Array.from({ length: 2 }, (_, index) => ({
label: `concurrent-wrapped-name-${index}`,
type: 'wrapped',
namedOwner: 'owner4',
fuses: encodeFuses({
input: {
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
duration: DURATION,
subnames: [
{
label: `xyz`,
namedOwner: 'owner4',
type: 'wrapped',
expiry: MAX_DATE_INT,
fuses: encodeFuses({
input: {
parent: {
named: ['PARENT_CANNOT_CONTROL'],
},
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
},
],
})),
]

/**
* @type {import('hardhat-deploy/types').DeployFunction}
*/
const func = async function (hre) {
const { network } = hre

const nonceManager = await makeNonceManager(hre)
const wrappedNameGenerator = await makeWrappedNameGenerator(hre, nonceManager)
const legacyNameGenerator = await makeLegacyNameGenerator(hre, nonceManager)

await network.provider.send('evm_setAutomine', [false])

// Commit
const commitTxs = await Promise.all(
names.map(
({
label,
type,
namedOwner,
namedAddr = namedOwner,
data = [],
reverseRecord = false,
fuses = 0,
duration = 31536000,
}) => {
console.log(`Committing commitment for ${label}.eth...`)
if (type === 'legacy')
return legacyNameGenerator.commit({
label,
namedOwner,
namedAddr,
})
return wrappedNameGenerator.commit({
label,
namedOwner,
data,
reverseRecord,
fuses,
duration,
})
},
),
)

network.provider.send('evm_mine')
await Promise.all(
commitTxs.map(async (tx) => {
return tx.wait()
}),
)

const oldTimestamp = (await ethers.provider.getBlock('latest')).timestamp
await network.provider.send('evm_setNextBlockTimestamp', [oldTimestamp + 60])
await network.provider.send('evm_increaseTime', [300])
await network.provider.send('evm_mine')

// Register
const registerTxs = await Promise.all(
names.map(
({
label,
type,
namedOwner,
namedAddr = namedOwner,
data = [],
reverseRecord = false,
fuses = 0,
duration = 31536000,
}) => {
if (type === 'legacy')
return legacyNameGenerator.register({
label,
namedOwner,
namedAddr,
duration,
})
return wrappedNameGenerator.register({
label,
namedOwner,
data,
reverseRecord,
fuses,
duration,
})
},
),
)

await network.provider.send('evm_mine')
await Promise.all(
registerTxs.map(async (tx) => {
return tx.wait()
}),
)

await network.provider.send('evm_setAutomine', [true])

// Create subnames
for (const {
label,
namedOwner,
type,
subnames,
} of names) {
if (!subnames) continue
console.log(`Setting subnames for ${label}.eth...`)
for (const {
label: subnameLabel,
namedOwner: namedSubnameOwner,
fuses: subnameFuses = 0,
expiry: subnameExpiry = BigNumber.from(2).pow(64).sub(1),
} of subnames) {
let setSubnameTx
if (type === 'legacy')
setSubnameTx = await legacyNameGenerator.subname({
label,
namedOwner,
subnameLabel,
namedSubnameOwner,
})
else
setSubnameTx = await wrappedNameGenerator.subname({
label,
namedOwner,
subnameLabel,
namedSubnameOwner,
subnameFuses,
subnameExpiry,
})
console.log(` - ${subnameLabel} (tx: ${setSubnameTx.hash})...`)
await setSubnameTx.wait()
}
}

await network.provider.send('evm_mine')
return true
}

func.id = 'register-concurrent-names'
func.tags = ['register-concurrent-names']
func.dependencies = ['ETHRegistrarController', 'register-wrapped-names']
func.runAtTheEnd = true

module.exports = func
Loading

0 comments on commit f3b3a86

Please sign in to comment.