Skip to content

Commit

Permalink
feat: new measurement field car_too_large (#128)
Browse files Browse the repository at this point in the history
* feat: record the measurement field `car_too_large`
* feat: return `carTooLarge` in measurement details
* feat: `car_too_large` in published measurements

Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos authored Nov 7, 2023
1 parent 4de9704 commit f118355
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const createMeasurement = async (req, res, client, getCurrentRound) => {
validate(measurement, 'endAt', { type: 'date', required: false })
validate(measurement, 'byteLength', { type: 'number', required: false })
validate(measurement, 'attestation', { type: 'string', required: false })
validate(measurement, 'carTooLarge', { type: 'boolean', required: false })

const inetGroup = await mapRequestToInetGroup(client, req)

Expand All @@ -78,10 +79,11 @@ const createMeasurement = async (req, res, client, getCurrentRound) => {
byte_length,
attestation,
inet_group,
car_too_large,
completed_at_round
)
VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16
)
RETURNING id
`, [
Expand All @@ -99,6 +101,7 @@ const createMeasurement = async (req, res, client, getCurrentRound) => {
measurement.byteLength,
measurement.attestation,
inetGroup,
measurement.carTooLarge ?? false,
round
])
json(res, { id: rows[0].id })
Expand Down Expand Up @@ -129,6 +132,7 @@ const getMeasurement = async (req, res, client, measurementId) => {
firstByteAt: resultRow.first_byte_at,
endAt: resultRow.end_at,
byteLength: resultRow.byte_length,
carTooLarge: resultRow.car_too_large,
attestation: resultRow.attestation,
publishedAs: resultRow.published_as
})
Expand Down
1 change: 1 addition & 0 deletions migrations/025.do.add-car-too-large.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE measurements ADD COLUMN car_too_large BOOLEAN NOT NULL DEFAULT FALSE;
1 change: 1 addition & 0 deletions spark-publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const publish = async ({
byte_length,
attestation,
inet_group,
car_too_large,
cid,
provider_address,
protocol
Expand Down
6 changes: 5 additions & 1 deletion spark-publish/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('integration', () => {
byteLength: 100,
attestation: 'json.sig',
inetGroup: 'MTIzNDU2Nzg',
carTooLarge: true,
round: 42
}

Expand All @@ -118,10 +119,11 @@ describe('integration', () => {
byte_length,
attestation,
inet_group,
car_too_large,
completed_at_round
)
VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16
)
`, [
measurementRecorded.sparkVersion,
Expand All @@ -138,6 +140,7 @@ describe('integration', () => {
measurementRecorded.byteLength,
measurementRecorded.attestation,
measurementRecorded.inetGroup,
measurementRecorded.carTooLarge,
measurementRecorded.round
])

Expand Down Expand Up @@ -202,6 +205,7 @@ describe('integration', () => {
assert.strictEqual(published.spark_version, measurementRecorded.sparkVersion)
assert.strictEqual(published.cid, measurementRecorded.cid)
assert.strictEqual(published.inet_group, measurementRecorded.inetGroup)
assert.strictEqual(published.car_too_large, measurementRecorded.carTooLarge)
// TODO: test other fields

// We are publishing records with invalid wallet addresses too
Expand Down
3 changes: 3 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('Routes', () => {
firstByteAt: new Date(),
endAt: new Date(),
byteLength: 100,
carTooLarge: true,
attestation: 'json.sig'
}

Expand Down Expand Up @@ -160,6 +161,7 @@ describe('Routes', () => {
assert.strictEqual(measurementRow.completed_at_round, currentSparkRoundNumber.toString())
assert.strictEqual(measurementRow.published_as, null)
assert.match(measurementRow.inet_group, /^.{12}$/)
assert.strictEqual(measurementRow.car_too_large, true)
})

it('allows older format with walletAddress', async () => {
Expand Down Expand Up @@ -243,6 +245,7 @@ describe('Routes', () => {
assert.strictEqual(body.byteLength, retrieval.byteLength)
assert.strictEqual(body.attestation, retrieval.attestation)
assert.strictEqual(body.publishedAs, null)
assert.strictEqual(body.carTooLarge, false)
})
})

Expand Down

0 comments on commit f118355

Please sign in to comment.