This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: timeline and close checking (#55)
* feat: add test to validate timeline presence * feat: add test and docs for close and timeline * feat: add filter test * docs: dont reference go, it's not relevant
- Loading branch information
Showing
6 changed files
with
113 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
|
||
module.exports = (common) => { | ||
const upgrader = { | ||
_upgrade (multiaddrConnection) { | ||
return multiaddrConnection | ||
}, | ||
upgradeOutbound (multiaddrConnection) { | ||
return upgrader._upgrade(multiaddrConnection) | ||
}, | ||
upgradeInbound (multiaddrConnection) { | ||
return upgrader._upgrade(multiaddrConnection) | ||
} | ||
} | ||
|
||
describe('filter', () => { | ||
let addrs | ||
let transport | ||
|
||
before(async () => { | ||
({ addrs, transport } = await common.setup({ upgrader })) | ||
}) | ||
|
||
after(() => common.teardown && common.teardown()) | ||
|
||
it('filters addresses', () => { | ||
const filteredAddrs = transport.filter(addrs) | ||
expect(filteredAddrs).to.eql(addrs) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
/** | ||
* A tick is considered valid if it happened between now | ||
* and `ms` milliseconds ago | ||
* @param {number} date Time in ticks | ||
* @param {number} ms max milliseconds that should have expired | ||
* @returns {boolean} | ||
*/ | ||
isValidTick: function isValidTick (date, ms = 5000) { | ||
const now = Date.now() | ||
if (date > now - ms && date <= now) return true | ||
return false | ||
} | ||
} |