Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ensdomains/ensjs-v3 into sendName-u…
Browse files Browse the repository at this point in the history
…pdate
  • Loading branch information
LeonmanRolls committed Nov 6, 2022
2 parents 0f00815 + a410832 commit 156abf9
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 25 deletions.
5 changes: 3 additions & 2 deletions packages/ens-test-env/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ensdomains/ens-test-env",
"type": "module",
"version": "0.3.4",
"version": "0.3.5",
"files": [
"src"
],
Expand All @@ -17,10 +17,11 @@
"commander": "^9.3.0",
"concurrently": "^7.1.0",
"docker-compose": "^0.23.17",
"dotenv": "^16.0.0",
"dotenv": "^16.0.1",
"fs-extra": "^10.0.1",
"ganache": "^7.0.4",
"got": "^12.0.2",
"js-yaml": "^4.1.0",
"lz4": "^0.6.5",
"node-fetch": "^3.2.3",
"progress-stream": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/ens-test-env/src/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ services:
extra_hosts:
- 'host.docker.internal:host-gateway'
ipfs:
image: ipfs/go-ipfs:v0.4.23
image: ipfs/kubo:v0.16.0
ports:
- '5001:5001'
volumes:
- $DATA_FOLDER/ipfs:/data/ipfs
postgres:
image: postgres:14
image: postgres:14-alpine
ports:
- '5432:5432'
command: ['postgres', '-cshared_preload_libraries=pg_stat_statements']
Expand Down
19 changes: 19 additions & 0 deletions packages/ens-test-env/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { emitKeypressEvents } from 'readline'
import { URL as URLClass } from 'url'
import { main as fetchData } from './fetch-data.js'
import { main as manager } from './manager.js'
import { main as subgraph } from './subgraph.js'

let config
const program = new Command()
Expand Down Expand Up @@ -115,4 +116,22 @@ program
await fetchData('compress', config)
})

program
.command('subgraph')
.description('Saves the deployment addresses to a subgraph file')
.option('-d, --directory <path>', 'The subgraph directory', '../ens-subgraph')
.option(
'--env <path>',
'The environment file with the deployment addresses',
'.env.local',
)
.option(
'--var <name>',
'The variable name in the environment file',
'DEPLOYMENT_ADDRESSES',
)
.action(async (options) => {
subgraph(options)
})

program.parse(process.argv)
40 changes: 40 additions & 0 deletions packages/ens-test-env/src/subgraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { config } from 'dotenv'
import fs from 'fs'
import yaml from 'js-yaml'
import path from 'path'

export const main = (options) => {
const directory = path.resolve(process.cwd(), options.directory)
const fileName = path.resolve(directory, 'subgraph.yaml')
const file = yaml.load(fs.readFileSync(fileName, 'utf8'))

config({ path: path.resolve(process.cwd(), options.env) })

const parsed = JSON.parse(process.env[options.var])
const addresses = Object.keys(parsed).reduce(
(acc, key) => ({ ...acc, [key.toLowerCase()]: parsed[key] }),
{},
)
const addressKeys = Object.keys(addresses)
// eslint-disable-next-line no-restricted-syntax
for (const s of file.dataSources) {
s.network = 'mainnet'
if (s.source.startBlock) s.source.startBlock = 0
// eslint-disable-next-line no-continue
if (!s.source.address) continue
let sourceName = s.name.toLowerCase()
if (sourceName.endsWith('old')) {
sourceName = sourceName.replace(/(.*)old/, 'legacy$1')
}
if (sourceName === 'baseregistrar') {
sourceName = 'baseregistrarimplementation'
}
if (addressKeys.includes(sourceName)) {
s.source.address = addresses[sourceName]
} else {
throw new Error(`Couldn't lookup contract: ${sourceName}, ${s.name}`)
}
}

fs.writeFileSync(fileName, yaml.dump(file))
}
Binary file modified packages/ensjs/archive.tar.lz4
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ensdomains/ensjs",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"description": "ENS javascript library for contract interaction",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
Expand Down Expand Up @@ -69,7 +69,7 @@
"ver": "pnpm version --no-workspaces-update"
},
"dependencies": {
"@ensdomains/address-encoder": "0.2.16",
"@ensdomains/address-encoder": "^0.2.18",
"@ensdomains/content-hash": "^2.5.7",
"@ensdomains/dnsprovejs": "^0.4.1",
"@ensdomains/dnssecoraclejs": "^0.2.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/ensjs/src/functions/getProfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('getProfile', () => {
it('should return a profile object with specified records', async () => {
const result = await ensInstance.getProfile(
'0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
{ texts: ['description', 'url'], coinTypes: ['ETC', '0'] },
{ texts: ['description', 'url'], coinTypes: ['ETC_LEGACY', '0'] },
)
expect(result).toBeDefined()
if (result) {
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('getProfile', () => {
it('should return a profile object with specified records', async () => {
const result = await ensInstance.getProfile('with-profile.eth', {
texts: ['description', 'url'],
coinTypes: ['ETC', '0'],
coinTypes: ['ETC_LEGACY', '0'],
})
expect((result as any).address).toBe(
'0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
Expand Down
8 changes: 4 additions & 4 deletions packages/ensjs/src/functions/getSpecificRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ describe('getSpecificRecord', () => {
expect((result as any).addr).toBe(
'0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
)
expect((result as any).coin).toBe('ETC')
expect((result as any).coin).toBe('ETC_LEGACY')
})
it('should return the correct address based on a coin ID input as a string', async () => {
const result = await ensInstance.getAddr('with-profile.eth', '61')
expect((result as any).addr).toBe(
'0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
)
expect((result as any).coin).toBe('ETC')
expect((result as any).coin).toBe('ETC_LEGACY')
})
it('should return the correct address based on a coin name', async () => {
const result = await ensInstance.getAddr('with-profile.eth', 'ETC')
const result = await ensInstance.getAddr('with-profile.eth', 'ETC_LEGACY')
expect((result as any).addr).toBe(
'0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
)
expect((result as any).coin).toBe('ETC')
expect((result as any).coin).toBe('ETC_LEGACY')
})
it('should return null for a non-existent coin', async () => {
const result = await ensInstance.getAddr('with-profile.eth', 'BNB')
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/setRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('setRecord', () => {
const tx = await ensInstance.setRecord('test123.eth', {
type: 'addr',
record: {
key: 'ETC',
key: 'ETC_LEGACY',
value: '0x42D63ae25990889E35F215bC95884039Ba354115',
},
addressOrIndex: 1,
Expand Down
5 changes: 4 additions & 1 deletion packages/ensjs/src/functions/setRecords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ describe('setRecords', () => {
const tx = await ensInstance.setRecords('test123.eth', {
records: {
coinTypes: [
{ key: 'ETC', value: '0x42D63ae25990889E35F215bC95884039Ba354115' },
{
key: 'ETC_LEGACY',
value: '0x42D63ae25990889E35F215bC95884039Ba354115',
},
],
texts: [{ key: 'foo', value: 'bar' }],
},
Expand Down
26 changes: 15 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 156abf9

Please sign in to comment.