Skip to content

Commit

Permalink
Remove validateResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed May 2, 2024
1 parent 191f721 commit fba5e1a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
9 changes: 7 additions & 2 deletions packages/ethernaut-retropgf/src/internal/agora/Agora.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class Agora {
return this.createRequest('/spec')
}

async createRequest(endpoint, method = 'GET', body = {}) {
async createRequest(
endpoint,
method = 'GET',
body = {},
successStatus = 200,
) {
const url = `${BASE_URL}${endpoint}`

debug.log(`Requesting ${url}`, 'retropgf')
Expand All @@ -48,7 +53,7 @@ class Agora {

const response = await axios(config)

if (response.status !== 200) {
if (response.status !== successStatus) {
throw new EthernautCliError(
'ethernaut-retropgf',
`Http status error: ${response.status}`,
Expand Down
11 changes: 1 addition & 10 deletions packages/ethernaut-retropgf/src/internal/agora/Auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { validateResponse } = require('./validate')

class Auth {
constructor(agora) {
this.agora = agora
Expand All @@ -10,17 +8,10 @@ class Auth {
}

async verify({ message, signature }) {
await this.agora.createRequest('/auth/verify', 'POST', {
return this.agora.createRequest('/auth/verify', 'POST', {
message,
signature,
})

// TODO: Fix validation
// validateResponse(
// response,
// 200,
// `Error verifying user: ${JSON.stringify(response, null, 2)}`,
// )
}
}

Expand Down
27 changes: 6 additions & 21 deletions packages/ethernaut-retropgf/src/internal/agora/RetroFunding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { validateResponse } = require('./validate')

class RetroFunding {
constructor(agora) {
this.agora = agora
Expand Down Expand Up @@ -30,7 +28,7 @@ class RetroFunding {
ballotContent,
signature,
}) {
const response = await this.agora.createRequest(
return this.agora.createRequest(
`/retrofunding/rounds/${roundId}/ballots/${ballotCasterAddressOrEns}/submit`,
'POST',
{
Expand All @@ -39,8 +37,6 @@ class RetroFunding {
signature,
},
)

validateResponse(response, 200, `Error submitting ballot: ${response}`)
}

async roundProjects({ roundId, limit = 10, offset = 0 }) {
Expand Down Expand Up @@ -76,7 +72,7 @@ class RetroFunding {
commenter,
content,
}) {
const response = await this.agora.createRequest(
return this.agora.createRequest(
`/retrofunding/rounds/${roundId}/impactMetrics/${impactMetricId}/comments`,
'PUT',
{
Expand All @@ -85,21 +81,13 @@ class RetroFunding {
content,
},
)

validateResponse(
response,
200,
`Error commenting on impact metric: ${response}`,
)
}

async deleteImpactMetricComment({ roundId, impactMetricId, commentId }) {
const response = await this.agora.createRequest(
return this.agora.createRequest(
`/retrofunding/rounds/${roundId}/impactMetrics/${impactMetricId}/comments/${commentId}`,
'DELETE',
)

validateResponse(response, 200, `Error deleting comment: ${response}`)
}

async ballotImpactMetrics({
Expand All @@ -121,29 +109,26 @@ class RetroFunding {
impactMetricId,
allocationAmount,
}) {
const response = await this.agora.createRequest(
return this.agora.createRequest(
`/retrofunding/rounds/${roundId}/ballots/${ballotCasterAddressOrEns}/impactMetrics`,
'POST',
{
impactMetricId,
allocationAmount,
},
201,
)

validateResponse(response, 201, `Error creating impact metric: ${response}`)
}

async deleteImpactMetric({
roundId,
ballotCasterAddressOrEns,
impactMetricId,
}) {
const response = await this.agora.createRequest(
return this.agora.createRequest(
`/retrofunding/rounds/${roundId}/ballots/${ballotCasterAddressOrEns}/impactMetrics/${impactMetricId}`,
'DELETE',
)

validateResponse(response, 200, `Error deleting impact metric: ${response}`)
}
}

Expand Down
7 changes: 0 additions & 7 deletions packages/ethernaut-retropgf/src/internal/agora/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ function validateSort(sort, types) {
}
}

function validateResponse(received, expected, message) {
if (received !== expected) {
throw new EthernautCliError('retropgf', message)
}
}

module.exports = {
validateSort,
validateResponse,
}

0 comments on commit fba5e1a

Please sign in to comment.