Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Unit testing WebRTCTransport #19

Merged
merged 11 commits into from
Sep 2, 2022
Merged

Unit testing WebRTCTransport #19

merged 11 commits into from
Sep 2, 2022

Conversation

John-LittleBearLabs
Copy link
Contributor

Unit tests for Transport class

Also an impl for filter

@@ -39,7 +39,7 @@ export class WebRTCTransport implements Transport, Initializable {
}

filter(multiaddrs: Multiaddr[]): Multiaddr[] {
return [];
return multiaddrs.filter(validMa);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckousik note that this is hiding in here.

@ddimaria ddimaria linked an issue Aug 17, 2022 that may be closed by this pull request
17 tasks
@John-LittleBearLabs John-LittleBearLabs changed the title Jt/transportut Unit testing WebRTCTransport Aug 17, 2022

it('filter gets rid of some invalids and returns a valid', async () => {
let mas: Multiaddr[] = [
'/ip4/1.2.3.4/udp/1234/webrtc/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be of interest to note, I did attempt to test filter in the case where a certhash is present but missing a character.
But filter takes as an argument a Multiaddr, not a string. And the constructor will throw an Error on that input, so you don't even get to call filter in the first place.

@John-LittleBearLabs John-LittleBearLabs marked this pull request as ready for review August 17, 2022 20:33
package.json Outdated
@@ -8,8 +8,8 @@
"type": "module",
"scripts": {
"build": "aegir build",
"test": "aegir test",
"test:browser": "aegir test --target browser",
"clean": "aegir clean ; rm -rf node_modules/ ; rm -f package-lock.json yarn.lock",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious as to why there's a need to remove the lock files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb paranoia on my part. I'm fine with getting rid of that script - don't think anyone else is running it anyhow.

src/sdp.ts Outdated
.replace('%s', ufrag)
.replace('%s', ufrag)
.replace('%s', certhashToFingerprint(ma));
.replaceAll('{IP}', ip(ma))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could avoid this replacing by using builtin string interpolation and/or tagged templates: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this would be a good use of that feature I was unaware of at the time I wrote this ;)

src/transport.ts Outdated
setTimeout(() => {
log.error('Data channel never opened. State was: %s', handshakeDataChannel.readyState.toString());
dataChannelOpenPromise.reject()
}, 10000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible magic number. Can you assign it to a variable? Also, can you comment on the significance of the number chose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a completely arbitrary number. I believe Chinmay used it when he was demonstrating the technique, and I stole it.

10 seconds does work as a timeout in that it's considerably longer than this process should ever take. But also, yes, it would be completely reasonable to name this variable.

@@ -21,11 +23,33 @@ a=max-message-size:100000

describe('SDP creation', () => {
it('handles simple blue sky easily enough', async () => {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests 💯

@ddimaria
Copy link
Collaborator

ddimaria commented Sep 1, 2022

@John-LittleBearLabs just one little comment on a magic number, can merge after that.

@John-LittleBearLabs John-LittleBearLabs merged commit 02adfaa into develop Sep 2, 2022
@github-actions
Copy link

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement webrtc in js-libp2p
2 participants