2022-08-25 15:57:26 +02:00
|
|
|
import addressApi from '../api/address'
|
|
|
|
import nameApi from '../api/name'
|
2022-08-25 16:37:06 +02:00
|
|
|
import profileApi from '../api/profile'
|
2023-01-11 09:49:16 +01:00
|
|
|
import { ensTextApi } from '../api/text'
|
2022-08-25 15:57:26 +02:00
|
|
|
import { createServer } from 'vercel-node-server'
|
|
|
|
import listen from 'test-listen'
|
|
|
|
// import express from 'express'
|
|
|
|
// import request from 'supertest'
|
|
|
|
import axios from 'axios'
|
|
|
|
// import type { VercelRequest, VercelResponse } from '@vercel/node'
|
|
|
|
import { assert } from 'chai'
|
|
|
|
|
2022-08-25 18:02:29 +02:00
|
|
|
let server: any
|
2022-08-25 15:57:26 +02:00
|
|
|
let url: string
|
|
|
|
const name = 'jellymcjellyfish.eth'
|
|
|
|
const accountId = '0x99840Df5Cb42faBE0Feb8811Aaa4BC99cA6C84e0'
|
2022-08-25 17:46:33 +02:00
|
|
|
const invalid = 'lkdfjslkdfjpeoijf3423'
|
2022-08-25 15:57:26 +02:00
|
|
|
|
|
|
|
describe('Testing ENS proxy API endpoints', function () {
|
2022-08-25 17:39:17 +02:00
|
|
|
this.timeout(25000)
|
2022-08-25 15:57:26 +02:00
|
|
|
|
|
|
|
it('Requesting address should return the expected response', async () => {
|
|
|
|
server = createServer(addressApi)
|
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
})
|
2022-08-25 17:46:33 +02:00
|
|
|
assert(response.status === 200)
|
2022-08-25 15:57:26 +02:00
|
|
|
assert(response.data.address === accountId)
|
|
|
|
})
|
|
|
|
it('Requesting ENS name should return the expected response', async () => {
|
|
|
|
server = createServer(nameApi)
|
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
accountId
|
|
|
|
}
|
|
|
|
})
|
2022-08-25 17:46:33 +02:00
|
|
|
assert(response.status === 200)
|
2022-08-25 15:57:26 +02:00
|
|
|
assert(response.data.name === name)
|
|
|
|
})
|
2022-08-25 17:39:17 +02:00
|
|
|
it('Requesting text records should return the expected response', async () => {
|
2023-01-11 09:49:16 +01:00
|
|
|
server = createServer(ensTextApi)
|
2022-08-25 17:39:17 +02:00
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
})
|
2022-08-25 17:46:33 +02:00
|
|
|
assert(response.status === 200)
|
2022-08-25 17:39:17 +02:00
|
|
|
assert(
|
|
|
|
response.data.records[0].value === 'https://oceanprotocol.com',
|
|
|
|
'Wrong URL'
|
|
|
|
)
|
|
|
|
assert(
|
|
|
|
response.data.records[1].value ===
|
|
|
|
'https://raw.githubusercontent.com/oceanprotocol/art/main/logo/favicon-white.png',
|
|
|
|
'Wrong avatar'
|
|
|
|
)
|
|
|
|
assert(response.data.records[2].value === 'oceanprotocol', 'Wrong link 1')
|
|
|
|
assert(response.data.records[3].value === 'oceanprotocol', 'wrong link 2')
|
|
|
|
|
|
|
|
assert(response.data.records[0].key === 'url', 'Wrong URL')
|
|
|
|
assert(response.data.records[1].key === 'avatar', 'Wrong avatar')
|
|
|
|
assert(response.data.records[2].key === 'com.twitter', 'Wrong link 1')
|
|
|
|
assert(response.data.records[3].key === 'com.github', 'wrong link 2')
|
|
|
|
})
|
|
|
|
|
2022-08-25 16:37:06 +02:00
|
|
|
it('Requesting user profile should return the expected response', async () => {
|
|
|
|
server = createServer(profileApi)
|
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
address: accountId
|
|
|
|
}
|
|
|
|
})
|
2022-08-25 17:39:17 +02:00
|
|
|
|
2022-08-25 17:46:33 +02:00
|
|
|
assert(response.status === 200)
|
2022-08-25 16:37:06 +02:00
|
|
|
assert(response.data.profile.name === name)
|
|
|
|
assert(
|
|
|
|
response.data.profile.avatar ===
|
|
|
|
'https://metadata.ens.domains/mainnet/avatar/jellymcjellyfish.eth'
|
|
|
|
)
|
|
|
|
assert(response.data.profile.links[0].value === 'https://oceanprotocol.com')
|
2022-08-25 17:39:17 +02:00
|
|
|
assert(response.data.profile.links[1].value === 'oceanprotocol')
|
2022-08-25 16:37:06 +02:00
|
|
|
assert(response.data.profile.links[2].value === 'oceanprotocol')
|
2022-08-25 17:39:17 +02:00
|
|
|
|
|
|
|
assert(response.data.profile.links[0].key === 'url')
|
|
|
|
assert(response.data.profile.links[1].key === 'com.twitter')
|
|
|
|
assert(response.data.profile.links[2].key === 'com.github')
|
2022-08-25 16:37:06 +02:00
|
|
|
})
|
2022-08-25 17:46:33 +02:00
|
|
|
|
2022-08-25 17:52:07 +02:00
|
|
|
// Tests with incorrect address or name
|
2022-08-25 17:46:33 +02:00
|
|
|
|
|
|
|
it('Requesting address should return status 200 with invalid name', async () => {
|
|
|
|
server = createServer(addressApi)
|
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
name: invalid
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert(response.status === 200)
|
|
|
|
})
|
|
|
|
it('Requesting name should return status 200 with invalid accountId', async () => {
|
|
|
|
server = createServer(nameApi)
|
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
accountId: invalid
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert(response.status === 200)
|
|
|
|
})
|
|
|
|
it('Requesting text records should return status 200 with invalid name', async () => {
|
2023-01-11 09:49:16 +01:00
|
|
|
server = createServer(ensTextApi)
|
2022-08-25 17:46:33 +02:00
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
name: invalid
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert(response.status === 200)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Requesting profile should return status 200 with invalid name', async () => {
|
|
|
|
server = createServer(profileApi)
|
|
|
|
url = await listen(server)
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
address: invalid
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
assert(response.status === 200)
|
|
|
|
})
|
2022-08-25 15:57:26 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
server.close()
|
|
|
|
})
|