Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix(bootstrap:add): prevent duplicate inserts #893

Merged
merged 4 commits into from
Jul 3, 2017
Merged

Conversation

kenshyx
Copy link
Contributor

@kenshyx kenshyx commented Jun 30, 2017

Closes #892

const insertPosition = res.Peers.indexOf(validIp4)
expect(insertPosition).to.not.equal(-1)
const duplicatePosition = res.Peers.indexOf(validIp4, insertPosition + 1)
expect(duplicatePosition).to.equal(-1)
Copy link
Member

Choose a reason for hiding this comment

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

Add a expectation about that the bootstrap list should now only have one element in it as well.

Copy link
Contributor Author

@kenshyx kenshyx Jun 30, 2017

Choose a reason for hiding this comment

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

Line 46 verifies if the newly added peer was inserted. The bootstrap list contains the default peer list from https://github.com/ipfs/js-ipfs/tree/master/src/init-files + the ones added manually so it won't have only one element.

Copy link
Member

Choose a reason for hiding this comment

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

As far as I can tell, you're asserting that validIp4 is not missing from the list of peers, but never asserting that the amount of peers are correct in the test-case. Ideal, minimal test-case would start with a empty bootstrap list, add the same address twice and assert that the list only contain once element.

Copy link
Member

@victorb victorb Jun 30, 2017

Choose a reason for hiding this comment

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

That way, this test would also be protected against future changes (additions/removal of peers) to the default bootstrap list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, how do I set the bootstrap list to be empty without calling rm for the default bootstrap list?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that was what I thought... @kenshyx then you can remove the .rm call and just add the two addresses.

Copy link
Member

Choose a reason for hiding this comment

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

@kenshyx is doing rm because the previous tests add up to the bootstrap peers pool

expect(insertPosition).to.not.equal(-1)
expect(res.Peers.length).to.equal(1)
})
})
Copy link
Member

Choose a reason for hiding this comment

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

Please write tests for core too. The ideal would be getting interface-ipfs-core tests for bootstrap - https://github.com/ipfs/interface-ipfs-core/tree/master/src so that we match expectations on js-ipfs-api and js-ipfs.

@daviddias
Copy link
Member

I'll go ahead and merge this. Let's not forget about the standardization of API and tests though - ipfs-inactive/interface-js-ipfs-core#97

@daviddias daviddias merged commit ce504cd into ipfs:master Jul 3, 2017
MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this pull request May 22, 2020
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants