git ssb

4+

Dominic / scuttlebot



Commit 4250819350e538b6f5b1c63433e0b4b3f27ff6be

update block tests to use new obv based api

Dominic Tarr committed on 5/28/2017, 10:32:53 AM
Parent: e1e0ab885aaa57a0630e5ff36031bec1c3f845f4

Files changed

test/block.jschanged
test/block2.jschanged
test/block3.jschanged
test/block.jsView
@@ -10,8 +10,16 @@
1010 .use(require('../plugins/replicate'))
1111
1212 var toAddress = require('../lib/util').toAddress
1313
14+function once (fn) {
15+ var called = 0
16+ return function () {
17+ if(called++) throw new Error('called :'+called+' times!')
18+ return fn.apply(this, arguments)
19+ }
20+}
21+
1422 // alice, bob, and carol all follow each other,
1523 // but then bob offends alice, and she blocks him.
1624 // this means that:
1725 //
@@ -35,16 +43,21 @@
3543 })
3644
3745 tape('alice blocks bob, and bob cannot connect to alice', function (t) {
3846
47+ console.log({
48+ alice: alice.id,
49+ bob: bob.id,
50+ carol: carol.id
51+ })
52+
3953 //in the beginning alice and bob follow each other
4054 cont.para([
4155 cont(alice.publish)(u.follow(bob.id)),
4256 cont(bob .publish)(u.follow(alice.id)),
4357 cont(carol.publish)(u.follow(alice.id))
4458 ]) (function (err) {
4559 if(err) throw err
46-
4760 var n = 3, rpc
4861
4962 bob.connect(alice.getAddress(), function (err, _rpc) {
5063 if(err) throw err
@@ -54,24 +67,23 @@
5467 })
5568
5669 //get the next messages that are replicated to alice and bob,
5770 //and check that these are the correct follow messages.
58- var bobCancel = bob.post(function (op) {
71+ var bobCancel = bob.post(once(function (op) {
5972 console.log('BOB_POST', op)
6073 //should be the alice's follow(bob) message.
61- t.equal(op.value.author, alice.id)
62- t.equal(op.value.content.contact, bob.id)
74+ t.equal(op.value.author, alice.id, 'bob expected message from alice')
75+ t.equal(op.value.content.contact, bob.id, 'bob expected message to be about bob')
6376 next()
64- })
77+ }), false)
6578
66- var aliceCancel = alice.post(function (op) {
79+ var aliceCancel = alice.post(once(function (op) {
6780 console.log('ALICE_POST', op)
6881 //should be the bob's follow(alice) message.
69- t.equal(op.value.author, bob.id)
70- t.equal(op.value.content.contact, alice.id)
82+ t.equal(op.value.author, bob.id, 'alice expected to receive a message from bob')
83+ t.equal(op.value.content.contact, alice.id, 'alice expected received message to be about alice')
7184 next()
72- })
73-
85+ }), false)
7486 function next () {
7587 if(--n) return
7688
7789 rpc.close(true, function () {
@@ -82,68 +94,61 @@
8294 alice.publish(u.block(bob.id))
8395 (function (err) {
8496 if(err) throw err
8597
86- t.ok(alice.friends.get({source: alice.id, dest: bob.id, graph: 'flag'}))
98+ alice.friends.get(null, function (err, g) {
99+ if(err) throw err
100+ t.equal(g[alice.id][bob.id], false)
87101
88- pull(
89- alice.links({
90- source: alice.id,
91- dest: bob.id,
92- rel: 'contact',
93- values: true
94- }),
95- pull.filter(function (op) {
96- return op.value.content.flagged != null
97- }),
98- pull.collect(function (err, ary) {
99- if(err) throw err
100- console.log(ary)
101- t.ok(flagged = ary.pop().value.content.flagged, 'alice did block bob')
102+ pull(
103+ alice.links({
104+ source: alice.id,
105+ dest: bob.id,
106+ rel: 'contact',
107+ values: true
108+ }),
109+ pull.filter(function (op) {
110+ return op.value.content.flagged != null
111+ }),
112+ pull.collect(function (err, ary) {
113+ if(err) throw err
114+ console.log(ary)
115+ t.ok(flagged = ary.pop().value.content.flagged, 'alice did block bob')
102116
103- //since bob is blocked, he should not be able to connect
104- bob.connect(alice.getAddress(), function (err, rpc) {
105- t.ok(err, 'bob is blocked, should fail to connect to alice')
117+ //since bob is blocked, he should not be able to connect
118+ bob.connect(alice.getAddress(), function (err, rpc) {
119+ t.ok(err, 'bob is blocked, should fail to connect to alice')
106120
107121
108- carol.post(function (msg) {
109- console.log('CAROL RECV', msg, alice.id)
110- if(msg.author === alice.id) {
111- if(msg.sequence == 2)
112- t.end()
113- }
114- })
122+ carol.post(function (msg) {
123+ console.log('CAROL RECV', msg, alice.id)
124+ if(msg.author === alice.id) {
125+ if(msg.sequence == 2)
126+ t.end()
127+ }
128+ })
115129
116- //but carol, should, because she is not blocked.
117- carol.connect(alice.getAddress(), function (err, rpc) {
118- if(err) throw err
119- console.log('CAROL CONNECTED TO ALICE', carol.id, alice.id)
120-// pull(
121-// alice.createHistoryStream({id: alice.id, seq: 0}),
122-// pull.collect(console.log)
123-// )
130+ //but carol, should, because she is not blocked.
131+ carol.connect(alice.getAddress(), function (err, rpc) {
132+ if(err) throw err
133+ console.log('CAROL CONNECTED TO ALICE', carol.id, alice.id)
134+ rpc.on('closed', function () {
135+ pull(
136+ carol.createHistoryStream({id: alice.id, seq: 0, live: false}),
137+ pull.collect(function (err, ary) {
138+ if(err) throw err
124139
125- rpc.on('closed', function () {
126- pull(
127- carol.createHistoryStream({id: alice.id, seq: 0, live: false}),
128- pull.collect(function (err, ary) {
129- if(err) throw err
130-
131- t.ok(ary.length, 'carol replicated data from alice')
132- console.log(alice.id, carol.id, err, ary)
133- t.end()
134- })
135- )
140+ t.ok(ary.length, 'carol replicated data from alice')
141+ console.log(alice.id, carol.id, err, ary)
142+ t.end()
143+ })
144+ )
145+ })
136146 })
137147 })
138-// carol.once('replicate:finish', function (vclock) {
139-// t.equal(vclock[alice.id], 2)
140-// //in next test, bob connects to carol...
141-// t.end()
142-// })
143148 })
144- })
145- )
149+ )
150+ })
146151 })
147152 })
148153 }
149154 })
@@ -177,7 +182,4 @@
177182
178183
179184
180185
181-
182-
183-
test/block2.jsView
@@ -52,9 +52,9 @@
5252
5353 t.equal(op.value.content.contact, bob.id)
5454 alice.publish(u.block(bob.id))
5555 (function (err) { if(err) throw err })
56- })
56+ }, false)
5757
5858 })
5959 })
6060
test/block3.jsView
@@ -77,11 +77,8 @@
7777 t.equal(op.value.author, alice.id)
7878 t.equal(op.value.content.contact, bob.id)
7979 alice.publish(u.block(bob.id))
8080 (function (err) { if(err) throw err })
81- })
81+ }, false)
8282 })
8383 })
8484
85-
86-
87-

Built with git-ssb-web