Skip to content

Commit 94a2176

Browse files
committed
test(address): Method getMetrics add tests + docs
1 parent fa25a94 commit 94a2176

File tree

5 files changed

+187
-8
lines changed

5 files changed

+187
-8
lines changed

dist/web3data.min.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,12 +2508,17 @@
25082508
}).then(onFulfilled$1, onError$1)
25092509
}
25102510

2511-
// TODO: Needs tests
2512-
getMetrics(filterOptions) {
2511+
/**
2512+
* Get metrics for all addresses that have exist publicly for a given blockchain. Default metrics are for Ethereum over a 24h period.
2513+
*
2514+
* @returns The address metrics.
2515+
* @example
2516+
* const metrics = await web3data.address.getMetrics(ADDRESS)
2517+
*/
2518+
getMetrics() {
25132519
return get$1(this.web3data, {
25142520
endpoint: ENDPOINT,
2515-
subendpoint: 'metrics/latest',
2516-
filterOptions
2521+
subendpoint: 'metrics/latest'
25172522
}).then(onFulfilled$1, onError$1)
25182523
}
25192524
}

docs/api.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,32 @@ const usage = await web3data.address.getUsage(ADDRESS)
635635

636636

637637

638+
#### getMetrics()
639+
640+
641+
Get metrics for all addresses that have exist publicly for a given blockchain. Default metrics are for Ethereum over a 24h period.
642+
643+
644+
645+
646+
647+
648+
##### Examples
649+
650+
```javascript
651+
const metrics = await web3data.address.getMetrics(ADDRESS)
652+
```
653+
654+
655+
##### Returns
656+
657+
658+
- The address metrics.
659+
660+
661+
662+
663+
638664
### src/block.js
639665

640666

src/address.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,17 @@ Returns null if no address is found.
354354
}).then(onFulfilled, onError)
355355
}
356356

357-
// TODO: Needs tests
358-
getMetrics(filterOptions) {
357+
/**
358+
* Get metrics for all addresses that have exist publicly for a given blockchain. Default metrics are for Ethereum over a 24h period.
359+
*
360+
* @returns The address metrics.
361+
* @example
362+
* const metrics = await web3data.address.getMetrics(ADDRESS)
363+
*/
364+
getMetrics() {
359365
return get(this.web3data, {
360366
endpoint: ENDPOINT,
361-
subendpoint: 'metrics/latest',
362-
filterOptions
367+
subendpoint: 'metrics/latest'
363368
}).then(onFulfilled, onError)
364369
}
365370
}

test/address.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,9 @@ test('Successfully gets historical address balance + paginates properly', async
411411
const balance = await t.context.web3data.address.getBalance(ADDRESS, {startDate: 1506184430, page: 0, size: SIZE})
412412
t.is(balance.data.length, SIZE)
413413
})
414+
415+
/*********** Test getMetrics() ***********/
416+
test('Successfully calls getMetrics()', async t => {
417+
const metrics = await t.context.web3data.address.getMetrics(ADDRESS)
418+
t.true(metrics.hasProp('activeTotal'))
419+
})

test/recordings/address_745154899/recording.har

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,6 +5645,143 @@
56455645
"ssl": -1,
56465646
"wait": 8871
56475647
}
5648+
},
5649+
{
5650+
"_id": "e1f374bf9423c8263c7cfd0cdcaaf4b1",
5651+
"_order": 0,
5652+
"cache": {},
5653+
"request": {
5654+
"bodySize": 0,
5655+
"cookies": [],
5656+
"headers": [
5657+
{
5658+
"name": "accept",
5659+
"value": "application/json, text/plain, */*"
5660+
},
5661+
{
5662+
"name": "user-agent",
5663+
"value": "axios/0.19.0"
5664+
},
5665+
{
5666+
"name": "host",
5667+
"value": "web3api.io"
5668+
}
5669+
],
5670+
"headersSize": 202,
5671+
"httpVersion": "HTTP/1.1",
5672+
"method": "GET",
5673+
"queryString": [],
5674+
"url": "https://web3api.io/api/v2/addresses/metrics/latest?x-api-key="
5675+
},
5676+
"response": {
5677+
"bodySize": 134,
5678+
"content": {
5679+
"mimeType": "application/json; charset=utf-8",
5680+
"size": 134,
5681+
"text": "{\"status\":200,\"title\":\"OK\",\"description\":\"Successful request\",\"payload\":{\"activeTotal\":\"264780\",\"activeAverage\":\"11032.500000000000\"}}"
5682+
},
5683+
"cookies": [
5684+
{
5685+
"expires": "2019-11-07T22:08:12.000Z",
5686+
"name": "AWSALB",
5687+
"path": "/",
5688+
"value": "ZhcDnXPuJeoqPtdayNQCVkuk5JGsocmKwvMZkwtIDjEVi99xa3Jku+Zt1ERa2tkMqNWGHu3XCrXWbGfFpbuVNYQZDrlDLwmgmHfRteZFay8WpVDquOM4K30CwEFz"
5689+
}
5690+
],
5691+
"headers": [
5692+
{
5693+
"name": "hasprop"
5694+
},
5695+
{
5696+
"name": "values"
5697+
},
5698+
{
5699+
"name": "content-type",
5700+
"value": "application/json; charset=utf-8"
5701+
},
5702+
{
5703+
"name": "content-length",
5704+
"value": "134"
5705+
},
5706+
{
5707+
"name": "connection",
5708+
"value": "close"
5709+
},
5710+
{
5711+
"name": "date",
5712+
"value": "Thu, 31 Oct 2019 22:08:12 GMT"
5713+
},
5714+
{
5715+
"name": "x-amzn-requestid",
5716+
"value": "6321b92f-65f3-415c-9ad7-af31033c766f"
5717+
},
5718+
{
5719+
"name": "access-control-allow-origin",
5720+
"value": "*"
5721+
},
5722+
{
5723+
"name": "x-response-time",
5724+
"value": "52.973ms"
5725+
},
5726+
{
5727+
"name": "x-amzn-remapped-content-length",
5728+
"value": "134"
5729+
},
5730+
{
5731+
"name": "x-amzn-remapped-connection",
5732+
"value": "keep-alive"
5733+
},
5734+
{
5735+
"_fromType": "array",
5736+
"name": "set-cookie",
5737+
"value": "AWSALB=ZhcDnXPuJeoqPtdayNQCVkuk5JGsocmKwvMZkwtIDjEVi99xa3Jku+Zt1ERa2tkMqNWGHu3XCrXWbGfFpbuVNYQZDrlDLwmgmHfRteZFay8WpVDquOM4K30CwEFz; Expires=Thu, 07 Nov 2019 22:08:12 GMT; Path=/"
5738+
},
5739+
{
5740+
"name": "x-amz-apigw-id",
5741+
"value": "Ccsz9GemIAMF5ew="
5742+
},
5743+
{
5744+
"name": "etag",
5745+
"value": "W/\"86-lcssCvRUZ6KvQ5iZkswDv0U0IHg\""
5746+
},
5747+
{
5748+
"name": "x-amzn-remapped-date",
5749+
"value": "Thu, 31 Oct 2019 22:08:12 GMT"
5750+
},
5751+
{
5752+
"name": "x-cache",
5753+
"value": "Miss from cloudfront"
5754+
},
5755+
{
5756+
"name": "via",
5757+
"value": "1.1 5ab5dc09da67e3ea794ec8a82992cc89.cloudfront.net (CloudFront)"
5758+
},
5759+
{
5760+
"name": "x-amz-cf-pop",
5761+
"value": "HIO50-C1"
5762+
},
5763+
{
5764+
"name": "x-amz-cf-id",
5765+
"value": "owFRnbI3_gogSz9v_3wW0r_0LZhLWnRrcoia1f9mjX0l1Vl-7y4cew=="
5766+
}
5767+
],
5768+
"headersSize": 1050,
5769+
"httpVersion": "HTTP/1.1",
5770+
"redirectURL": "",
5771+
"status": 200,
5772+
"statusText": "OK"
5773+
},
5774+
"startedDateTime": "2019-10-31T22:08:12.120Z",
5775+
"time": 536,
5776+
"timings": {
5777+
"blocked": -1,
5778+
"connect": -1,
5779+
"dns": -1,
5780+
"receive": 0,
5781+
"send": 0,
5782+
"ssl": -1,
5783+
"wait": 536
5784+
}
56485785
}
56495786
],
56505787
"pages": [],

0 commit comments

Comments
 (0)