Skip to content

Commit

Permalink
Add hotspots.elected(block) (#156)
Browse files Browse the repository at this point in the history
* Add hotspots.elected(block)

* Add hotspots.elected() for current consensus group

* Change hotspots.elected to a ResourceList

* Update CONTRIBUTING.md
  • Loading branch information
danielcolinjames authored Apr 9, 2021
1 parent 882eaed commit e1e547f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
### How to Contribute to this repository

## Running helium-js locally
1. Clone the repo and navigate into the folder
```zsh
git clone https://github.com/helium/helium-js.git && cd helium-js
```
2. Get everything installed
```zsh
yarn && yarn bootstrap && yarn build
```
3. Run the tests
```zsh
yarn test
```
If everything went well, you should see a list of green lines that say "PASS" in your terminal. That should get you up and running!

## About contributing
We value contributions from the community and will do everything we
can go get them reviewed in a timely fashion. If you have code to send
our way or a bug to report:
Expand Down
10 changes: 10 additions & 0 deletions packages/http/src/resources/Hotspots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ export default class Hotspots {
} = await this.client.get(url)
return new Hotspot(this.client, hotspot)
}

async elected(block?: number): Promise<ResourceList<Hotspot>> {
const url = block === undefined ? '/elected' : `/elected/${block}`
const response = await this.client.get(url)
const {
data: { data: hotspots },
} = response
const data = hotspots.map((h: HTTPHotspotObject) => new Hotspot(this.client, h))
return new ResourceList(data, this.list.bind(this))
}
}
65 changes: 65 additions & 0 deletions packages/http/src/resources/__tests__/Hotspots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,71 @@ describe('get', () => {
})
})

describe('elected', () => {
nock('https://api.helium.io')
.get('/v1/elected/123456')
.reply(200, {
data: [
hotspotFixture({ name: 'previous-consensus-hotspot-1' }),
hotspotFixture({ name: 'previous-consensus-hotspot-2' }),
hotspotFixture({ name: 'previous-consensus-hotspot-3' }),
hotspotFixture({ name: 'previous-consensus-hotspot-4' }),
hotspotFixture({ name: 'previous-consensus-hotspot-5' }),
hotspotFixture({ name: 'previous-consensus-hotspot-6' }),
hotspotFixture({ name: 'previous-consensus-hotspot-7' }),
hotspotFixture({ name: 'previous-consensus-hotspot-8' }),
hotspotFixture({ name: 'previous-consensus-hotspot-9' }),
hotspotFixture({ name: 'previous-consensus-hotspot-10' }),
hotspotFixture({ name: 'previous-consensus-hotspot-11' }),
hotspotFixture({ name: 'previous-consensus-hotspot-12' }),
hotspotFixture({ name: 'previous-consensus-hotspot-13' }),
hotspotFixture({ name: 'previous-consensus-hotspot-14' }),
hotspotFixture({ name: 'previous-consensus-hotspot-15' }),
hotspotFixture({ name: 'previous-consensus-hotspot-16' }),
],
})
nock('https://api.helium.io')
.get('/v1/elected')
.reply(200, {
data: [
hotspotFixture({ name: 'current-consensus-hotspot-1' }),
hotspotFixture({ name: 'current-consensus-hotspot-2' }),
hotspotFixture({ name: 'current-consensus-hotspot-3' }),
hotspotFixture({ name: 'current-consensus-hotspot-4' }),
hotspotFixture({ name: 'current-consensus-hotspot-5' }),
hotspotFixture({ name: 'current-consensus-hotspot-6' }),
hotspotFixture({ name: 'current-consensus-hotspot-7' }),
hotspotFixture({ name: 'current-consensus-hotspot-8' }),
hotspotFixture({ name: 'current-consensus-hotspot-9' }),
hotspotFixture({ name: 'current-consensus-hotspot-10' }),
hotspotFixture({ name: 'current-consensus-hotspot-11' }),
hotspotFixture({ name: 'current-consensus-hotspot-12' }),
hotspotFixture({ name: 'current-consensus-hotspot-13' }),
hotspotFixture({ name: 'current-consensus-hotspot-14' }),
hotspotFixture({ name: 'current-consensus-hotspot-15' }),
hotspotFixture({ name: 'current-consensus-hotspot-16' }),
],
})

it('retrieves elected hotspots at a given block height', async () => {
const client = new Client()
const list = await client.hotspots.elected(123456)
const elected = await list.take(16)
expect(elected.length).toBe(16)
expect(elected[0].name).toBe('previous-consensus-hotspot-1')
expect(elected[elected.length - 1].name).toBe('previous-consensus-hotspot-16')
})

it('retrieves currently elected hotspots', async () => {
const client = new Client()
const list = await client.hotspots.elected()
const elected = await list.take(16)
expect(elected.length).toBe(16)
expect(elected[0].name).toBe('current-consensus-hotspot-1')
expect(elected[elected.length - 1].name).toBe('current-consensus-hotspot-16')
})
})

describe('list', () => {
nock('https://api.helium.io')
.get('/v1/hotspots')
Expand Down

0 comments on commit e1e547f

Please sign in to comment.