hypercore 9.12.0 → 10.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test-node.yml +3 -4
- package/README.md +131 -404
- package/__snapshots__/test/storage.js.snapshot.cjs +15 -0
- package/examples/announce.js +19 -0
- package/examples/basic.js +10 -0
- package/examples/http.js +123 -0
- package/examples/lookup.js +20 -0
- package/index.js +365 -1600
- package/lib/bitfield.js +113 -285
- package/lib/block-encryption.js +68 -0
- package/lib/block-store.js +58 -0
- package/lib/core.js +468 -0
- package/lib/extensions.js +76 -0
- package/lib/merkle-tree.js +1110 -0
- package/lib/messages.js +571 -0
- package/lib/mutex.js +39 -0
- package/lib/oplog.js +224 -0
- package/lib/protocol.js +525 -0
- package/lib/random-iterator.js +46 -0
- package/lib/remote-bitfield.js +24 -0
- package/lib/replicator.js +857 -0
- package/lib/streams.js +39 -0
- package/package.json +44 -45
- package/test/basic.js +59 -471
- package/test/bitfield.js +48 -133
- package/test/core.js +290 -0
- package/test/encodings.js +18 -0
- package/test/encryption.js +123 -0
- package/test/extension.js +71 -0
- package/test/helpers/index.js +23 -0
- package/test/merkle-tree.js +518 -0
- package/test/mutex.js +137 -0
- package/test/oplog.js +399 -0
- package/test/preload.js +72 -0
- package/test/replicate.js +227 -824
- package/test/sessions.js +173 -0
- package/test/storage.js +31 -0
- package/test/streams.js +39 -146
- package/test/user-data.js +47 -0
- package/bench/all.sh +0 -65
- package/bench/copy-64kb-blocks.js +0 -51
- package/bench/helpers/read-throttled.js +0 -27
- package/bench/helpers/read.js +0 -47
- package/bench/helpers/write.js +0 -29
- package/bench/read-16kb-blocks-proof-throttled.js +0 -1
- package/bench/read-16kb-blocks-proof.js +0 -1
- package/bench/read-16kb-blocks-throttled.js +0 -1
- package/bench/read-16kb-blocks.js +0 -1
- package/bench/read-512b-blocks.js +0 -1
- package/bench/read-64kb-blocks-linear-batch.js +0 -18
- package/bench/read-64kb-blocks-linear.js +0 -18
- package/bench/read-64kb-blocks-proof.js +0 -1
- package/bench/read-64kb-blocks.js +0 -1
- package/bench/replicate-16kb-blocks.js +0 -19
- package/bench/replicate-64kb-blocks.js +0 -19
- package/bench/write-16kb-blocks.js +0 -1
- package/bench/write-512b-blocks.js +0 -1
- package/bench/write-64kb-blocks-static.js +0 -1
- package/bench/write-64kb-blocks.js +0 -1
- package/example.js +0 -23
- package/lib/cache.js +0 -26
- package/lib/crypto.js +0 -5
- package/lib/replicate.js +0 -829
- package/lib/safe-buffer-equals.js +0 -6
- package/lib/storage.js +0 -421
- package/lib/tree-index.js +0 -183
- package/test/ack.js +0 -306
- package/test/audit.js +0 -36
- package/test/cache.js +0 -93
- package/test/compat.js +0 -209
- package/test/copy.js +0 -377
- package/test/default-storage.js +0 -51
- package/test/extensions.js +0 -137
- package/test/get.js +0 -64
- package/test/head.js +0 -65
- package/test/helpers/create-tracking-ram.js +0 -27
- package/test/helpers/create.js +0 -6
- package/test/helpers/replicate.js +0 -4
- package/test/seek.js +0 -234
- package/test/selections.js +0 -95
- package/test/set-uploading-downloading.js +0 -91
- package/test/stats.js +0 -77
- package/test/timeouts.js +0 -22
- package/test/tree-index.js +0 -841
- package/test/update.js +0 -156
- package/test/value-encoding.js +0 -52
package/test/tree-index.js
DELETED
|
@@ -1,841 +0,0 @@
|
|
|
1
|
-
var tape = require('tape')
|
|
2
|
-
var flat = require('flat-tree')
|
|
3
|
-
var tree = require('../lib/tree-index')
|
|
4
|
-
|
|
5
|
-
tape('set and get', function (t) {
|
|
6
|
-
var index = tree()
|
|
7
|
-
|
|
8
|
-
t.same(index.get(0), false, '0 is not set')
|
|
9
|
-
t.same(index.set(0), true, 'set 0 mutates')
|
|
10
|
-
t.same(index.get(0), true, '0 is set')
|
|
11
|
-
t.same(index.set(0), false, 'no mutations')
|
|
12
|
-
t.same(index.set(2), true, 'set 2 mutates')
|
|
13
|
-
t.same(index.get(2), true, '2 is set')
|
|
14
|
-
t.same(index.get(1), true, 'parent of 0 and 2 is set')
|
|
15
|
-
|
|
16
|
-
index = tree()
|
|
17
|
-
for (var i = 0; i < 32; i += 2) index.set(i)
|
|
18
|
-
t.same(index.get(7), true, 'ancestor is set')
|
|
19
|
-
t.same(index.get(23), true, 'ancestor is set')
|
|
20
|
-
t.same(index.get(15), true, 'ancestor is set')
|
|
21
|
-
|
|
22
|
-
t.end()
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
tape('digest', function (t) {
|
|
26
|
-
var index = tree()
|
|
27
|
-
t.same(index.digest(0), parseInt('0', 2), 'has nothing')
|
|
28
|
-
|
|
29
|
-
index = tree()
|
|
30
|
-
index.set(0)
|
|
31
|
-
t.same(index.digest(0), parseInt('1', 2), 'has all')
|
|
32
|
-
|
|
33
|
-
index = tree()
|
|
34
|
-
index.set(1)
|
|
35
|
-
t.same(index.digest(0), parseInt('101', 2), 'rooted, no sibling, has parent')
|
|
36
|
-
|
|
37
|
-
index = tree()
|
|
38
|
-
index.set(2)
|
|
39
|
-
t.same(index.digest(0), parseInt('10', 2), 'not rooted, has sibling')
|
|
40
|
-
|
|
41
|
-
index = tree()
|
|
42
|
-
index.set(1)
|
|
43
|
-
index.set(2)
|
|
44
|
-
t.same(index.digest(0), parseInt('1', 2), 'has all')
|
|
45
|
-
|
|
46
|
-
index = tree()
|
|
47
|
-
index.set(3)
|
|
48
|
-
index.set(2)
|
|
49
|
-
t.same(index.digest(0), parseInt('1011', 2), 'rooted, has sibling, no uncle, has grand parent')
|
|
50
|
-
|
|
51
|
-
index = tree()
|
|
52
|
-
index.set(5)
|
|
53
|
-
t.same(index.digest(1), parseInt('10', 2), 'not rooted, has sibling')
|
|
54
|
-
|
|
55
|
-
t.end()
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
tape('verified by', function (t) {
|
|
59
|
-
var index = tree()
|
|
60
|
-
t.same(index.verifiedBy(0), 0)
|
|
61
|
-
|
|
62
|
-
index.set(0)
|
|
63
|
-
t.same(index.verifiedBy(0), 2)
|
|
64
|
-
index.set(2)
|
|
65
|
-
t.same(index.verifiedBy(0), 4)
|
|
66
|
-
index.set(5)
|
|
67
|
-
t.same(index.verifiedBy(0), 8)
|
|
68
|
-
index.set(8)
|
|
69
|
-
t.same(index.verifiedBy(0), 10)
|
|
70
|
-
|
|
71
|
-
index = tree()
|
|
72
|
-
index.set(10)
|
|
73
|
-
index.set(8)
|
|
74
|
-
index.set(13)
|
|
75
|
-
index.set(3)
|
|
76
|
-
index.set(17)
|
|
77
|
-
t.same(index.verifiedBy(10), 20)
|
|
78
|
-
|
|
79
|
-
index = tree()
|
|
80
|
-
index.set(7)
|
|
81
|
-
index.set(16)
|
|
82
|
-
index.set(18)
|
|
83
|
-
index.set(21)
|
|
84
|
-
index.set(25)
|
|
85
|
-
index.set(28)
|
|
86
|
-
t.same(index.verifiedBy(16), 30)
|
|
87
|
-
t.same(index.verifiedBy(18), 30)
|
|
88
|
-
t.same(index.verifiedBy(17), 30)
|
|
89
|
-
|
|
90
|
-
t.end()
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
tape('proof without a digest', function (t) {
|
|
94
|
-
var index = tree()
|
|
95
|
-
t.same(index.proof(0), null)
|
|
96
|
-
|
|
97
|
-
index.set(0)
|
|
98
|
-
t.same(index.proof(0), { nodes: [], verifiedBy: 2 })
|
|
99
|
-
index.set(2)
|
|
100
|
-
t.same(index.proof(0), { nodes: [2], verifiedBy: 4 })
|
|
101
|
-
index.set(5)
|
|
102
|
-
t.same(index.proof(0), { nodes: [2, 5], verifiedBy: 8 })
|
|
103
|
-
index.set(8)
|
|
104
|
-
t.same(index.proof(0), { nodes: [2, 5, 8], verifiedBy: 10 })
|
|
105
|
-
|
|
106
|
-
index = tree()
|
|
107
|
-
index.set(10)
|
|
108
|
-
index.set(8)
|
|
109
|
-
index.set(13)
|
|
110
|
-
index.set(3)
|
|
111
|
-
index.set(17)
|
|
112
|
-
t.same(index.proof(10), { nodes: [8, 13, 3, 17], verifiedBy: 20 })
|
|
113
|
-
|
|
114
|
-
index = tree()
|
|
115
|
-
index.set(7)
|
|
116
|
-
index.set(16)
|
|
117
|
-
index.set(18)
|
|
118
|
-
index.set(21)
|
|
119
|
-
index.set(25)
|
|
120
|
-
index.set(28)
|
|
121
|
-
t.same(index.proof(16), { nodes: [18, 21, 7, 25, 28], verifiedBy: 30 })
|
|
122
|
-
t.same(index.proof(18), { nodes: [16, 21, 7, 25, 28], verifiedBy: 30 })
|
|
123
|
-
t.same(index.proof(17), { nodes: [21, 7, 25, 28], verifiedBy: 30 })
|
|
124
|
-
|
|
125
|
-
t.end()
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
tape('proof with a digest', function (t) {
|
|
129
|
-
var index = tree()
|
|
130
|
-
t.same(index.proof(0), null)
|
|
131
|
-
|
|
132
|
-
index.set(0)
|
|
133
|
-
index.set(2)
|
|
134
|
-
t.same(index.proof(0, { digest: 1 }), { nodes: [], verifiedBy: 0 })
|
|
135
|
-
index.set(5)
|
|
136
|
-
t.same(index.proof(0, { digest: parseInt('10', 2) }), { nodes: [5], verifiedBy: 8 })
|
|
137
|
-
t.same(index.proof(0, { digest: parseInt('110', 2) }), { nodes: [], verifiedBy: 8 })
|
|
138
|
-
index.set(8)
|
|
139
|
-
t.same(index.proof(0, { digest: parseInt('101', 2) }), { nodes: [2], verifiedBy: 0 })
|
|
140
|
-
t.same(index.proof(0, { digest: parseInt('10', 2) }), { nodes: [5, 8], verifiedBy: 10 })
|
|
141
|
-
|
|
142
|
-
index = tree()
|
|
143
|
-
index.set(10)
|
|
144
|
-
index.set(8)
|
|
145
|
-
index.set(13)
|
|
146
|
-
index.set(3)
|
|
147
|
-
index.set(17)
|
|
148
|
-
t.same(index.proof(10, { digest: parseInt('1000001', 2) }), { nodes: [8, 13, 3, 17], verifiedBy: 20 })
|
|
149
|
-
t.same(index.proof(10, { digest: parseInt('10001', 2) }), { nodes: [8, 13, 3], verifiedBy: 0 })
|
|
150
|
-
t.same(index.proof(10, { digest: parseInt('1001', 2) }), { nodes: [8, 13], verifiedBy: 0 })
|
|
151
|
-
t.same(index.proof(10, { digest: parseInt('1000', 2) }), { nodes: [8, 13, 17], verifiedBy: 20 })
|
|
152
|
-
|
|
153
|
-
index = tree()
|
|
154
|
-
index.set(7)
|
|
155
|
-
index.set(16)
|
|
156
|
-
index.set(18)
|
|
157
|
-
index.set(21)
|
|
158
|
-
index.set(25)
|
|
159
|
-
index.set(28)
|
|
160
|
-
t.same(index.proof(16, { digest: 1 }), { nodes: [], verifiedBy: 0 })
|
|
161
|
-
t.same(index.proof(18, { digest: parseInt('100', 2) }), { nodes: [16, 7, 25, 28], verifiedBy: 30 })
|
|
162
|
-
t.same(index.proof(18, { digest: parseInt('10', 2) }), { nodes: [21, 7, 25, 28], verifiedBy: 30 })
|
|
163
|
-
t.same(index.proof(17, { digest: parseInt('101', 2) }), { nodes: [21], verifiedBy: 0 })
|
|
164
|
-
|
|
165
|
-
t.end()
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
tape('digest sanity checks', function (t) {
|
|
169
|
-
var index = tree()
|
|
170
|
-
index.set(0)
|
|
171
|
-
index.proof(0, { digest: 999999999999999 })
|
|
172
|
-
t.pass('huge digest did not crash')
|
|
173
|
-
t.end()
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
// tests below was generated by a randomizer triggering different replication edge cases
|
|
177
|
-
|
|
178
|
-
tape('chaos monkey test #1', function (t) {
|
|
179
|
-
var source = tree()
|
|
180
|
-
var clone = tree()
|
|
181
|
-
var i = 0
|
|
182
|
-
|
|
183
|
-
source.set(0)
|
|
184
|
-
copy(0, source, clone, t)
|
|
185
|
-
for (i = 0; i < 20; i += 2) source.set(i)
|
|
186
|
-
copy(9, source, clone, t)
|
|
187
|
-
for (i = 0; i < 28; i += 2) source.set(i)
|
|
188
|
-
copy(13, source, clone, t)
|
|
189
|
-
for (i = 0; i < 44; i += 2) source.set(i)
|
|
190
|
-
copy(20, source, clone, t)
|
|
191
|
-
for (i = 0; i < 4400; i += 2) source.set(i)
|
|
192
|
-
copy(2000, source, clone, t)
|
|
193
|
-
for (i = 0; i < 4444; i += 2) source.set(i)
|
|
194
|
-
copy(2010, source, clone, t)
|
|
195
|
-
copy(2200, source, clone, t)
|
|
196
|
-
t.end()
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
tape('chaos monkey test #2', function (t) {
|
|
200
|
-
var source = tree()
|
|
201
|
-
var a = tree()
|
|
202
|
-
var b = tree()
|
|
203
|
-
|
|
204
|
-
source.set(0)
|
|
205
|
-
source.set(2)
|
|
206
|
-
source.set(4)
|
|
207
|
-
copy(2, source, a, t)
|
|
208
|
-
copy(2, a, b, t)
|
|
209
|
-
t.end()
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
tape('chaos monkey test #3', function (t) {
|
|
213
|
-
var source = tree()
|
|
214
|
-
var a = tree()
|
|
215
|
-
var b = tree()
|
|
216
|
-
|
|
217
|
-
source.set(0)
|
|
218
|
-
source.set(2)
|
|
219
|
-
source.set(4)
|
|
220
|
-
source.set(6)
|
|
221
|
-
source.set(8)
|
|
222
|
-
copy(2, source, b, t)
|
|
223
|
-
source.set(10)
|
|
224
|
-
source.set(12)
|
|
225
|
-
copy(5, source, b, t)
|
|
226
|
-
source.set(14)
|
|
227
|
-
source.set(16)
|
|
228
|
-
copy(5, b, a, t)
|
|
229
|
-
copy(2, b, a, t)
|
|
230
|
-
copy(0, source, b, t)
|
|
231
|
-
copy(7, source, b, t)
|
|
232
|
-
copy(3, source, a, t)
|
|
233
|
-
copy(7, source, a, t)
|
|
234
|
-
source.set(18)
|
|
235
|
-
source.set(20)
|
|
236
|
-
copy(10, source, a, t)
|
|
237
|
-
t.end()
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
tape('chaos monkey test #4', function (t) {
|
|
241
|
-
var source = tree()
|
|
242
|
-
var a = tree()
|
|
243
|
-
var b = tree()
|
|
244
|
-
|
|
245
|
-
source.set(0)
|
|
246
|
-
source.set(2)
|
|
247
|
-
source.set(4)
|
|
248
|
-
copy(1, source, a, t)
|
|
249
|
-
copy(0, source, a, t)
|
|
250
|
-
source.set(6)
|
|
251
|
-
source.set(8)
|
|
252
|
-
source.set(10)
|
|
253
|
-
copy(2, source, a, t)
|
|
254
|
-
copy(5, source, a, t)
|
|
255
|
-
source.set(12)
|
|
256
|
-
copy(1, a, b, t)
|
|
257
|
-
source.set(14)
|
|
258
|
-
copy(7, source, a, t)
|
|
259
|
-
copy(2, a, b, t)
|
|
260
|
-
source.set(16)
|
|
261
|
-
copy(8, source, a, t)
|
|
262
|
-
source.set(18)
|
|
263
|
-
copy(9, source, b, t)
|
|
264
|
-
source.set(20)
|
|
265
|
-
source.set(22)
|
|
266
|
-
copy(8, a, b, t)
|
|
267
|
-
source.set(24)
|
|
268
|
-
source.set(26)
|
|
269
|
-
source.set(28)
|
|
270
|
-
copy(4, source, b, t)
|
|
271
|
-
source.set(30)
|
|
272
|
-
copy(11, source, a, t)
|
|
273
|
-
source.set(32)
|
|
274
|
-
source.set(34)
|
|
275
|
-
source.set(36)
|
|
276
|
-
copy(3, source, b, t)
|
|
277
|
-
copy(6, source, a, t)
|
|
278
|
-
copy(11, source, b, t)
|
|
279
|
-
source.set(38)
|
|
280
|
-
source.set(40)
|
|
281
|
-
source.set(42)
|
|
282
|
-
source.set(44)
|
|
283
|
-
source.set(46)
|
|
284
|
-
copy(21, source, a, t)
|
|
285
|
-
source.set(48)
|
|
286
|
-
copy(20, source, a, t)
|
|
287
|
-
copy(16, source, b, t)
|
|
288
|
-
source.set(50)
|
|
289
|
-
copy(21, a, b, t)
|
|
290
|
-
t.end()
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
tape('chaos monkey test #5', function (t) {
|
|
294
|
-
var source = tree()
|
|
295
|
-
var a = tree()
|
|
296
|
-
var b = tree()
|
|
297
|
-
|
|
298
|
-
source.set(0)
|
|
299
|
-
copy(0, source, b, t)
|
|
300
|
-
source.set(2)
|
|
301
|
-
copy(0, b, a, t)
|
|
302
|
-
copy(1, source, b, t)
|
|
303
|
-
source.set(4)
|
|
304
|
-
copy(1, b, a, t)
|
|
305
|
-
copy(2, source, b, t)
|
|
306
|
-
source.set(6)
|
|
307
|
-
source.set(8)
|
|
308
|
-
source.set(10)
|
|
309
|
-
source.set(12)
|
|
310
|
-
copy(2, b, a, t)
|
|
311
|
-
source.set(14)
|
|
312
|
-
copy(6, source, b, t)
|
|
313
|
-
source.set(16)
|
|
314
|
-
copy(8, source, a, t)
|
|
315
|
-
copy(4, source, a, t)
|
|
316
|
-
source.set(18)
|
|
317
|
-
copy(4, source, b, t)
|
|
318
|
-
source.set(20)
|
|
319
|
-
copy(6, source, a, t)
|
|
320
|
-
copy(5, source, b, t)
|
|
321
|
-
copy(10, source, a, t)
|
|
322
|
-
copy(3, source, a, t)
|
|
323
|
-
source.set(22)
|
|
324
|
-
source.set(24)
|
|
325
|
-
copy(12, source, a, t)
|
|
326
|
-
copy(11, source, a, t)
|
|
327
|
-
source.set(26)
|
|
328
|
-
source.set(28)
|
|
329
|
-
copy(5, b, a, t)
|
|
330
|
-
copy(10, a, b, t)
|
|
331
|
-
source.set(30)
|
|
332
|
-
copy(3, a, b, t)
|
|
333
|
-
source.set(32)
|
|
334
|
-
copy(13, source, a, t)
|
|
335
|
-
source.set(34)
|
|
336
|
-
source.set(36)
|
|
337
|
-
copy(7, source, a, t)
|
|
338
|
-
copy(18, source, a, t)
|
|
339
|
-
copy(16, source, a, t)
|
|
340
|
-
source.set(38)
|
|
341
|
-
source.set(40)
|
|
342
|
-
source.set(42)
|
|
343
|
-
source.set(44)
|
|
344
|
-
source.set(46)
|
|
345
|
-
source.set(48)
|
|
346
|
-
source.set(50)
|
|
347
|
-
source.set(52)
|
|
348
|
-
source.set(54)
|
|
349
|
-
copy(11, a, b, t)
|
|
350
|
-
copy(25, source, a, t)
|
|
351
|
-
source.set(56)
|
|
352
|
-
source.set(58)
|
|
353
|
-
source.set(60)
|
|
354
|
-
copy(25, a, b, t)
|
|
355
|
-
source.set(62)
|
|
356
|
-
source.set(64)
|
|
357
|
-
source.set(66)
|
|
358
|
-
source.set(68)
|
|
359
|
-
source.set(70)
|
|
360
|
-
source.set(72)
|
|
361
|
-
copy(7, source, b, t)
|
|
362
|
-
copy(27, source, a, t)
|
|
363
|
-
source.set(74)
|
|
364
|
-
copy(22, source, a, t)
|
|
365
|
-
source.set(76)
|
|
366
|
-
source.set(78)
|
|
367
|
-
source.set(80)
|
|
368
|
-
source.set(82)
|
|
369
|
-
source.set(84)
|
|
370
|
-
copy(12, a, b, t)
|
|
371
|
-
source.set(86)
|
|
372
|
-
source.set(88)
|
|
373
|
-
source.set(90)
|
|
374
|
-
source.set(92)
|
|
375
|
-
source.set(94)
|
|
376
|
-
copy(41, source, a, t)
|
|
377
|
-
source.set(96)
|
|
378
|
-
source.set(98)
|
|
379
|
-
copy(22, a, b, t)
|
|
380
|
-
source.set(100)
|
|
381
|
-
source.set(102)
|
|
382
|
-
copy(47, source, a, t)
|
|
383
|
-
source.set(104)
|
|
384
|
-
copy(40, source, a, t)
|
|
385
|
-
copy(47, source, b, t)
|
|
386
|
-
source.set(106)
|
|
387
|
-
source.set(108)
|
|
388
|
-
source.set(110)
|
|
389
|
-
copy(13, source, b, t)
|
|
390
|
-
source.set(112)
|
|
391
|
-
source.set(114)
|
|
392
|
-
copy(35, source, b, t)
|
|
393
|
-
copy(40, a, b, t)
|
|
394
|
-
source.set(116)
|
|
395
|
-
source.set(118)
|
|
396
|
-
source.set(120)
|
|
397
|
-
source.set(122)
|
|
398
|
-
copy(52, source, a, t)
|
|
399
|
-
copy(28, source, a, t)
|
|
400
|
-
copy(18, a, b, t)
|
|
401
|
-
t.end()
|
|
402
|
-
})
|
|
403
|
-
|
|
404
|
-
tape('chaos monkey test #6', function (t) {
|
|
405
|
-
var source = tree()
|
|
406
|
-
var a = tree()
|
|
407
|
-
var b = tree()
|
|
408
|
-
|
|
409
|
-
source.set(0)
|
|
410
|
-
source.set(2)
|
|
411
|
-
copy(1, source, b, t)
|
|
412
|
-
copy(0, source, a, t)
|
|
413
|
-
source.set(4)
|
|
414
|
-
copy(1, b, a, t)
|
|
415
|
-
source.set(6)
|
|
416
|
-
source.set(8)
|
|
417
|
-
source.set(10)
|
|
418
|
-
copy(4, source, b, t)
|
|
419
|
-
source.set(12)
|
|
420
|
-
copy(4, b, a, t)
|
|
421
|
-
copy(3, source, b, t)
|
|
422
|
-
source.set(14)
|
|
423
|
-
copy(6, source, a, t)
|
|
424
|
-
copy(6, a, b, t)
|
|
425
|
-
copy(5, source, a, t)
|
|
426
|
-
copy(5, source, b, t)
|
|
427
|
-
source.set(16)
|
|
428
|
-
copy(3, source, a, t)
|
|
429
|
-
source.set(18)
|
|
430
|
-
copy(8, source, a, t)
|
|
431
|
-
copy(7, source, a, t)
|
|
432
|
-
copy(2, source, a, t)
|
|
433
|
-
copy(9, source, a, t)
|
|
434
|
-
source.set(20)
|
|
435
|
-
source.set(22)
|
|
436
|
-
copy(0, a, b, t)
|
|
437
|
-
copy(8, a, b, t)
|
|
438
|
-
source.set(24)
|
|
439
|
-
source.set(26)
|
|
440
|
-
source.set(28)
|
|
441
|
-
source.set(30)
|
|
442
|
-
source.set(32)
|
|
443
|
-
copy(2, source, b, t)
|
|
444
|
-
source.set(34)
|
|
445
|
-
copy(12, source, a, t)
|
|
446
|
-
copy(11, source, a, t)
|
|
447
|
-
copy(9, source, b, t)
|
|
448
|
-
copy(15, source, a, t)
|
|
449
|
-
source.set(36)
|
|
450
|
-
copy(12, source, b, t)
|
|
451
|
-
source.set(38)
|
|
452
|
-
copy(13, source, b, t)
|
|
453
|
-
source.set(40)
|
|
454
|
-
copy(11, a, b, t)
|
|
455
|
-
source.set(42)
|
|
456
|
-
source.set(44)
|
|
457
|
-
source.set(46)
|
|
458
|
-
copy(21, source, a, t)
|
|
459
|
-
source.set(48)
|
|
460
|
-
source.set(50)
|
|
461
|
-
copy(20, source, a, t)
|
|
462
|
-
copy(21, source, b, t)
|
|
463
|
-
source.set(52)
|
|
464
|
-
source.set(54)
|
|
465
|
-
copy(13, b, a, t)
|
|
466
|
-
source.set(56)
|
|
467
|
-
source.set(58)
|
|
468
|
-
source.set(60)
|
|
469
|
-
source.set(62)
|
|
470
|
-
source.set(64)
|
|
471
|
-
source.set(66)
|
|
472
|
-
source.set(68)
|
|
473
|
-
copy(15, source, b, t)
|
|
474
|
-
copy(22, source, a, t)
|
|
475
|
-
source.set(70)
|
|
476
|
-
copy(26, source, a, t)
|
|
477
|
-
source.set(72)
|
|
478
|
-
copy(35, source, b, t)
|
|
479
|
-
source.set(74)
|
|
480
|
-
copy(7, a, b, t)
|
|
481
|
-
source.set(76)
|
|
482
|
-
source.set(78)
|
|
483
|
-
copy(26, a, b, t)
|
|
484
|
-
copy(34, source, b, t)
|
|
485
|
-
copy(29, source, a, t)
|
|
486
|
-
source.set(80)
|
|
487
|
-
source.set(82)
|
|
488
|
-
copy(22, a, b, t)
|
|
489
|
-
copy(29, a, b, t)
|
|
490
|
-
copy(31, source, b, t)
|
|
491
|
-
source.set(84)
|
|
492
|
-
source.set(86)
|
|
493
|
-
source.set(88)
|
|
494
|
-
copy(25, source, b, t)
|
|
495
|
-
copy(36, source, b, t)
|
|
496
|
-
source.set(90)
|
|
497
|
-
source.set(92)
|
|
498
|
-
source.set(94)
|
|
499
|
-
copy(31, source, a, t)
|
|
500
|
-
source.set(96)
|
|
501
|
-
source.set(98)
|
|
502
|
-
source.set(100)
|
|
503
|
-
copy(10, source, a, t)
|
|
504
|
-
source.set(102)
|
|
505
|
-
copy(34, source, a, t)
|
|
506
|
-
source.set(104)
|
|
507
|
-
copy(28, source, a, t)
|
|
508
|
-
copy(35, b, a, t)
|
|
509
|
-
source.set(106)
|
|
510
|
-
source.set(108)
|
|
511
|
-
source.set(110)
|
|
512
|
-
copy(28, source, b, t)
|
|
513
|
-
source.set(112)
|
|
514
|
-
source.set(114)
|
|
515
|
-
copy(45, source, b, t)
|
|
516
|
-
source.set(116)
|
|
517
|
-
source.set(118)
|
|
518
|
-
copy(19, source, a, t)
|
|
519
|
-
source.set(120)
|
|
520
|
-
source.set(122)
|
|
521
|
-
copy(44, source, a, t)
|
|
522
|
-
source.set(124)
|
|
523
|
-
source.set(126)
|
|
524
|
-
source.set(128)
|
|
525
|
-
source.set(130)
|
|
526
|
-
source.set(132)
|
|
527
|
-
copy(40, source, a, t)
|
|
528
|
-
source.set(134)
|
|
529
|
-
copy(54, source, b, t)
|
|
530
|
-
copy(54, b, a, t)
|
|
531
|
-
source.set(136)
|
|
532
|
-
source.set(138)
|
|
533
|
-
source.set(140)
|
|
534
|
-
source.set(142)
|
|
535
|
-
copy(25, b, a, t)
|
|
536
|
-
source.set(144)
|
|
537
|
-
source.set(146)
|
|
538
|
-
source.set(148)
|
|
539
|
-
source.set(150)
|
|
540
|
-
copy(32, source, a, t)
|
|
541
|
-
copy(48, source, b, t)
|
|
542
|
-
source.set(152)
|
|
543
|
-
copy(45, b, a, t)
|
|
544
|
-
copy(17, source, a, t)
|
|
545
|
-
source.set(154)
|
|
546
|
-
source.set(156)
|
|
547
|
-
source.set(158)
|
|
548
|
-
source.set(160)
|
|
549
|
-
source.set(162)
|
|
550
|
-
source.set(164)
|
|
551
|
-
source.set(166)
|
|
552
|
-
copy(60, source, b, t)
|
|
553
|
-
source.set(168)
|
|
554
|
-
source.set(170)
|
|
555
|
-
copy(61, source, b, t)
|
|
556
|
-
source.set(172)
|
|
557
|
-
copy(19, source, b, t)
|
|
558
|
-
source.set(174)
|
|
559
|
-
copy(18, source, a, t)
|
|
560
|
-
copy(60, source, a, t)
|
|
561
|
-
source.set(176)
|
|
562
|
-
copy(16, source, a, t)
|
|
563
|
-
source.set(178)
|
|
564
|
-
copy(88, source, b, t)
|
|
565
|
-
copy(74, source, b, t)
|
|
566
|
-
source.set(180)
|
|
567
|
-
source.set(182)
|
|
568
|
-
source.set(184)
|
|
569
|
-
source.set(186)
|
|
570
|
-
source.set(188)
|
|
571
|
-
copy(73, source, b, t)
|
|
572
|
-
source.set(190)
|
|
573
|
-
source.set(192)
|
|
574
|
-
source.set(194)
|
|
575
|
-
source.set(196)
|
|
576
|
-
source.set(198)
|
|
577
|
-
source.set(200)
|
|
578
|
-
copy(67, source, a, t)
|
|
579
|
-
source.set(202)
|
|
580
|
-
copy(94, source, a, t)
|
|
581
|
-
source.set(204)
|
|
582
|
-
copy(51, source, a, t)
|
|
583
|
-
source.set(206)
|
|
584
|
-
copy(103, source, b, t)
|
|
585
|
-
copy(41, source, a, t)
|
|
586
|
-
source.set(208)
|
|
587
|
-
copy(20, a, b, t)
|
|
588
|
-
copy(76, source, a, t)
|
|
589
|
-
source.set(210)
|
|
590
|
-
source.set(212)
|
|
591
|
-
source.set(214)
|
|
592
|
-
source.set(216)
|
|
593
|
-
source.set(218)
|
|
594
|
-
source.set(220)
|
|
595
|
-
copy(53, source, a, t)
|
|
596
|
-
source.set(222)
|
|
597
|
-
source.set(224)
|
|
598
|
-
copy(58, source, b, t)
|
|
599
|
-
source.set(226)
|
|
600
|
-
source.set(228)
|
|
601
|
-
source.set(230)
|
|
602
|
-
source.set(232)
|
|
603
|
-
source.set(234)
|
|
604
|
-
source.set(236)
|
|
605
|
-
copy(100, source, a, t)
|
|
606
|
-
copy(85, source, a, t)
|
|
607
|
-
source.set(238)
|
|
608
|
-
copy(41, a, b, t)
|
|
609
|
-
source.set(240)
|
|
610
|
-
copy(93, source, b, t)
|
|
611
|
-
source.set(242)
|
|
612
|
-
source.set(244)
|
|
613
|
-
source.set(246)
|
|
614
|
-
copy(100, a, b, t)
|
|
615
|
-
copy(63, source, b, t)
|
|
616
|
-
source.set(248)
|
|
617
|
-
source.set(250)
|
|
618
|
-
copy(30, source, b, t)
|
|
619
|
-
source.set(252)
|
|
620
|
-
copy(88, b, a, t)
|
|
621
|
-
t.end()
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
tape('chaos monkey test #7', function (t) {
|
|
625
|
-
var source = tree()
|
|
626
|
-
var a = tree()
|
|
627
|
-
var b = tree()
|
|
628
|
-
|
|
629
|
-
source.set(0)
|
|
630
|
-
copy(0, source, b, t)
|
|
631
|
-
source.set(2)
|
|
632
|
-
source.set(4)
|
|
633
|
-
source.set(6)
|
|
634
|
-
copy(1, source, b, t)
|
|
635
|
-
source.set(8)
|
|
636
|
-
source.set(10)
|
|
637
|
-
source.set(12)
|
|
638
|
-
source.set(14)
|
|
639
|
-
source.set(16)
|
|
640
|
-
copy(1, b, a, t)
|
|
641
|
-
source.set(18)
|
|
642
|
-
source.set(20)
|
|
643
|
-
source.set(22)
|
|
644
|
-
source.set(24)
|
|
645
|
-
source.set(26)
|
|
646
|
-
source.set(28)
|
|
647
|
-
source.set(30)
|
|
648
|
-
copy(3, source, a, t)
|
|
649
|
-
source.set(32)
|
|
650
|
-
copy(4, source, b, t)
|
|
651
|
-
source.set(34)
|
|
652
|
-
source.set(36)
|
|
653
|
-
source.set(38)
|
|
654
|
-
source.set(40)
|
|
655
|
-
source.set(42)
|
|
656
|
-
source.set(44)
|
|
657
|
-
copy(0, b, a, t)
|
|
658
|
-
source.set(46)
|
|
659
|
-
copy(4, b, a, t)
|
|
660
|
-
source.set(48)
|
|
661
|
-
source.set(50)
|
|
662
|
-
source.set(52)
|
|
663
|
-
source.set(54)
|
|
664
|
-
copy(27, source, a, t)
|
|
665
|
-
source.set(56)
|
|
666
|
-
source.set(58)
|
|
667
|
-
source.set(60)
|
|
668
|
-
source.set(62)
|
|
669
|
-
source.set(64)
|
|
670
|
-
source.set(66)
|
|
671
|
-
source.set(68)
|
|
672
|
-
source.set(70)
|
|
673
|
-
source.set(72)
|
|
674
|
-
source.set(74)
|
|
675
|
-
source.set(76)
|
|
676
|
-
source.set(78)
|
|
677
|
-
source.set(80)
|
|
678
|
-
source.set(82)
|
|
679
|
-
source.set(84)
|
|
680
|
-
source.set(86)
|
|
681
|
-
source.set(88)
|
|
682
|
-
source.set(90)
|
|
683
|
-
source.set(92)
|
|
684
|
-
source.set(94)
|
|
685
|
-
source.set(96)
|
|
686
|
-
source.set(98)
|
|
687
|
-
source.set(100)
|
|
688
|
-
source.set(102)
|
|
689
|
-
copy(7, source, a, t)
|
|
690
|
-
source.set(104)
|
|
691
|
-
source.set(106)
|
|
692
|
-
source.set(108)
|
|
693
|
-
copy(41, source, a, t)
|
|
694
|
-
source.set(110)
|
|
695
|
-
copy(7, a, b, t)
|
|
696
|
-
source.set(112)
|
|
697
|
-
source.set(114)
|
|
698
|
-
source.set(116)
|
|
699
|
-
source.set(118)
|
|
700
|
-
copy(48, source, b, t)
|
|
701
|
-
source.set(120)
|
|
702
|
-
copy(59, source, b, t)
|
|
703
|
-
copy(30, source, b, t)
|
|
704
|
-
source.set(122)
|
|
705
|
-
source.set(124)
|
|
706
|
-
copy(49, source, b, t)
|
|
707
|
-
source.set(126)
|
|
708
|
-
source.set(128)
|
|
709
|
-
copy(10, source, b, t)
|
|
710
|
-
source.set(130)
|
|
711
|
-
source.set(132)
|
|
712
|
-
copy(10, b, a, t)
|
|
713
|
-
source.set(134)
|
|
714
|
-
source.set(136)
|
|
715
|
-
source.set(138)
|
|
716
|
-
source.set(140)
|
|
717
|
-
source.set(142)
|
|
718
|
-
source.set(144)
|
|
719
|
-
copy(13, source, b, t)
|
|
720
|
-
source.set(146)
|
|
721
|
-
source.set(148)
|
|
722
|
-
source.set(150)
|
|
723
|
-
source.set(152)
|
|
724
|
-
source.set(154)
|
|
725
|
-
source.set(156)
|
|
726
|
-
source.set(158)
|
|
727
|
-
source.set(160)
|
|
728
|
-
copy(6, source, b, t)
|
|
729
|
-
source.set(162)
|
|
730
|
-
source.set(164)
|
|
731
|
-
source.set(166)
|
|
732
|
-
source.set(168)
|
|
733
|
-
copy(53, source, a, t)
|
|
734
|
-
source.set(170)
|
|
735
|
-
source.set(172)
|
|
736
|
-
source.set(174)
|
|
737
|
-
source.set(176)
|
|
738
|
-
source.set(178)
|
|
739
|
-
source.set(180)
|
|
740
|
-
source.set(182)
|
|
741
|
-
source.set(184)
|
|
742
|
-
copy(48, b, a, t)
|
|
743
|
-
source.set(186)
|
|
744
|
-
source.set(188)
|
|
745
|
-
source.set(190)
|
|
746
|
-
copy(81, source, a, t)
|
|
747
|
-
source.set(192)
|
|
748
|
-
source.set(194)
|
|
749
|
-
copy(9, source, b, t)
|
|
750
|
-
source.set(196)
|
|
751
|
-
source.set(198)
|
|
752
|
-
copy(69, source, b, t)
|
|
753
|
-
source.set(200)
|
|
754
|
-
source.set(202)
|
|
755
|
-
source.set(204)
|
|
756
|
-
copy(23, source, a, t)
|
|
757
|
-
source.set(206)
|
|
758
|
-
source.set(208)
|
|
759
|
-
source.set(210)
|
|
760
|
-
copy(80, source, b, t)
|
|
761
|
-
source.set(212)
|
|
762
|
-
copy(74, source, b, t)
|
|
763
|
-
source.set(214)
|
|
764
|
-
copy(41, a, b, t)
|
|
765
|
-
source.set(216)
|
|
766
|
-
source.set(218)
|
|
767
|
-
copy(76, source, a, t)
|
|
768
|
-
source.set(220)
|
|
769
|
-
copy(24, source, a, t)
|
|
770
|
-
source.set(222)
|
|
771
|
-
copy(85, source, a, t)
|
|
772
|
-
source.set(224)
|
|
773
|
-
source.set(226)
|
|
774
|
-
copy(53, a, b, t)
|
|
775
|
-
t.end()
|
|
776
|
-
})
|
|
777
|
-
|
|
778
|
-
tape('chaos monkey randomized', function (t) {
|
|
779
|
-
var blocks = 0
|
|
780
|
-
var source = tree()
|
|
781
|
-
var peers = [source, tree(), tree(), tree(), tree(), tree(), tree(), tree(), tree()]
|
|
782
|
-
|
|
783
|
-
for (var i = 0; i < 5000; i++) {
|
|
784
|
-
if (Math.random() < 0.3) {
|
|
785
|
-
var next = blocks++
|
|
786
|
-
source.set(2 * next)
|
|
787
|
-
source.have = source.have || []
|
|
788
|
-
source.have.push(next)
|
|
789
|
-
}
|
|
790
|
-
if (Math.random() < 0.5) {
|
|
791
|
-
var a = peers[(Math.random() * peers.length) | 0]
|
|
792
|
-
var b = peers[(Math.random() * peers.length) | 0]
|
|
793
|
-
|
|
794
|
-
if (!a.have || a === b) continue
|
|
795
|
-
var want = a.have[(a.have.length * Math.random()) | 0]
|
|
796
|
-
if (b.have && b.have.indexOf(want) > -1) continue
|
|
797
|
-
|
|
798
|
-
copy(want, a, b, t)
|
|
799
|
-
b.have = b.have || []
|
|
800
|
-
if (b.have.indexOf(want) === -1) b.have.push(want)
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
t.end()
|
|
804
|
-
})
|
|
805
|
-
|
|
806
|
-
function copy (block, from, to, t) {
|
|
807
|
-
var proof = from.proof(2 * block, { digest: to.digest(2 * block) })
|
|
808
|
-
var i = 0
|
|
809
|
-
|
|
810
|
-
if (proof.roots) {
|
|
811
|
-
for (i = 0; i < proof.roots.length; i++) {
|
|
812
|
-
if (!to.set(proof.roots[i])) t.fail('duplicate root (' + proof.roots[i] + ')')
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
for (i = 0; i < proof.nodes.length; i++) {
|
|
817
|
-
if (!to.set(proof.nodes[i])) t.fail('duplicate node (' + proof.nodes[i] + ')')
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
to.set(2 * block)
|
|
821
|
-
|
|
822
|
-
if (proof.verifiedBy) {
|
|
823
|
-
var roots = flat.fullRoots(proof.verifiedBy)
|
|
824
|
-
|
|
825
|
-
for (i = 0; i < roots.length; i++) {
|
|
826
|
-
if (!to.get(roots[i])) t.fail('missing root for ' + block + ' (' + roots[i] + ')')
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
var tmp = 2 * block
|
|
830
|
-
for (i = 0; i < 40; i++) {
|
|
831
|
-
if (roots.indexOf(tmp) > -1) {
|
|
832
|
-
t.pass('copied and verified block ' + block)
|
|
833
|
-
return
|
|
834
|
-
}
|
|
835
|
-
tmp = flat.parent(tmp)
|
|
836
|
-
if (!to.get(tmp)) break
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
t.fail('does not validate')
|
|
840
|
-
}
|
|
841
|
-
}
|