Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test restarting client after getting excluded #101

Merged
merged 11 commits into from
May 4, 2023
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2020,
ecmaVersion: 2021,
sourceType: 'module',
},
rules: {
Expand Down
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,21 @@ module.exports = {

function start(cb) {
if (cb === undefined) return promisify(start)()
console.log('running start for', ssb.id)

console.log('about to find additions feed')
findOrCreateAdditionsFeed((err) => {
// prettier-ignore
if (err) return cb(clarify(err, 'Error finding or creating additions feed when starting ssb-tribes2'))
console.log('got additions feed')
return cb()
})

console.log('about to find root feed')
ssb.metafeeds.findOrCreate((err, myRoot) => {
// prettier-ignore
if (err) return cb(clarify(err, 'Error getting own root in start()'))
console.log('got root feed')

// check if we've been excluded
pull(
Expand All @@ -503,7 +508,10 @@ module.exports = {
pull.drain(
(msg) => {
const groupId = msg.value.content.recps[0]
ssb.box2.excludeGroupInfo(groupId, null)
ssb.box2.excludeGroupInfo(groupId, (err) => {
// prettier-ignore
if (err) return cb(clarify(err, 'Error on excluding group info after finding exclusion of ourselves'))
})
},
(err) => {
// prettier-ignore
Expand All @@ -528,9 +536,7 @@ module.exports = {
paraMap((msg, cb) => {
pull(
ssb.box2.listGroupIds(),
pull.filter((groupId) =>
groupId === msg.value.content.recps[0]
),
pull.filter((groupId) => groupId === msg.value.content.recps[0]),
pull.take(1),
pull.collect((err, groupIds) => {
// prettier-ignore
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"pull-stream": "^3.7.0",
"set.prototype.difference": "^1.0.2",
"ssb-bfe": "^3.7.0",
"ssb-box2": "^6.1.0",
"ssb-box2": "ssbc/ssb-box2#exclude-keep-readkeys",
"ssb-crut": "^4.6.2",
"ssb-db2": "^6.3.3",
"ssb-meta-feeds": "^0.39.0",
Expand Down
83 changes: 83 additions & 0 deletions test/exclude-members.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,86 @@ test('Can exclude a person in a group with a lot of members', async (t) => {
await p(alice.close)(true)
await Promise.all(peers.map((peer) => p(peer.close)(true)))
})

test("restarting the client doesn't make us rejoin old stuff", async (t) => {
const alice = Testbot({
keys: ssbKeys.generate(null, 'alice'),
mfSeed: Buffer.from(
'000000000000000000000000000000000000000000000000000000000000a1ce',
'hex'
),
})
let bob = Testbot({
name: 'bobrestart',
keys: ssbKeys.generate(null, 'bob'),
mfSeed: Buffer.from(
'0000000000000000000000000000000000000000000000000000000000000b0b',
'hex'
),
Comment on lines +619 to +624
Copy link
Member

Choose a reason for hiding this comment

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

I think extract these as bobConfig and then re-use it below (with { rimraf: false, ...bobConfig }

})

await Promise.all([alice.tribes2.start(), bob.tribes2.start()])

const bobRoot = await p(bob.metafeeds.findOrCreate)()

await replicate(alice, bob).catch(t.error)

const { id: groupId } = await alice.tribes2
.create()
.catch((err) => t.error(err, 'alice failed to create group'))

await alice.tribes2
.addMembers(groupId, [bobRoot.id])
.then(() => t.pass('added bob'))
.catch((err) => t.error(err, 'add bob fail'))

await replicate(alice, bob).catch(t.error)

await bob.tribes2.acceptInvite(groupId)

await replicate(alice, bob).catch(t.error)

await alice.tribes2
.excludeMembers(groupId, [bobRoot.id])
.then(() => t.pass('alice excluded bob'))
.catch((err) => t.error(err, 'remove member fail'))

await replicate(alice, bob).catch(t.error)

t.deepEquals(
await bob.tribes2.get(groupId),
{ id: groupId, excluded: true },
"bob knows he's excluded from the group before restart"
)

// TODO remove probably?
await p(setTimeout)(3000)

await p(bob.close)(true).then(() => t.pass("bob's client was closed"))
bob = Testbot({
rimraf: false,
name: 'bobrestart',
keys: ssbKeys.generate(null, 'bob'),
mfSeed: Buffer.from(
'0000000000000000000000000000000000000000000000000000000000000b0b',
'hex'
),
})
t.pass('bob got a new client')
await bob.tribes2.start().then(() => t.pass('bob restarted'))

t.deepEquals(
await bob.tribes2.get(groupId),
{ id: groupId, excluded: true },
"bob knows he's excluded from the group after restart"
)

// TODO list()

// TODO listInvites()

// TODO acceptInvite()

await p(alice.close)(true)
await p(bob.close)(true)
})