-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathfeed.spec.ts
More file actions
72 lines (52 loc) · 2.6 KB
/
feed.spec.ts
File metadata and controls
72 lines (52 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Dates, Strings, System } from 'cafe-utility'
import { NULL_TOPIC } from '../../src'
import { FeedIndex, PrivateKey, Reference } from '../../src/utils/typed-bytes'
import { batch, makeBee } from '../utils'
const bee = makeBee()
test('POST feed (reader)', async () => {
const privateKey = new PrivateKey(Strings.randomHex(64))
const owner = privateKey.publicKey().address()
const response1 = await bee.uploadData(batch(), 'First update')
const response2 = await bee.uploadData(batch(), 'Second update')
const feedWriter = bee.makeFeedWriter(NULL_TOPIC, privateKey)
const feedReader = bee.makeFeedReader(NULL_TOPIC, owner)
await feedWriter.upload(batch(), response1.reference, { deferred: false })
expect((await feedReader.download()).payload.toUtf8()).toBe('First update')
await feedWriter.upload(batch(), response2.reference, { deferred: false })
await System.waitFor(
async () => {
const payload = (await feedReader.download()).payload.toUtf8()
return payload === 'Second update'
},
Dates.seconds(1),
60,
)
// TODO: this is a reference... should it be auto-resolved?
const reference1 = new Reference((await feedReader.download({ index: 0 })).payload)
expect((await bee.downloadData(reference1)).toUtf8()).toBe('First update')
const reference2 = new Reference((await feedReader.download({ index: 1 })).payload)
expect((await bee.downloadData(reference2)).toUtf8()).toBe('Second update')
expect(await bee.isFeedRetrievable(owner, NULL_TOPIC)).toBe(true)
expect(await bee.isFeedRetrievable(owner, NULL_TOPIC, FeedIndex.fromBigInt(1n))).toBe(true)
})
test('POST feed (manifest)', async () => {
const privateKey = new PrivateKey(Strings.randomHex(64))
const owner = privateKey.publicKey().address()
const manifest = await bee.createFeedManifest(batch(), NULL_TOPIC, owner)
const response1 = await bee.uploadFile(batch(), 'First update')
const response2 = await bee.uploadFile(batch(), 'Second update')
const feedWriter = bee.makeFeedWriter(NULL_TOPIC, privateKey)
await feedWriter.upload(batch(), response1.reference, { deferred: false })
expect((await bee.downloadFile(manifest)).data.toUtf8()).toBe('First update')
await feedWriter.upload(batch(), response2.reference, { deferred: false })
await System.waitFor(
async () => {
const payload = (await bee.downloadFile(manifest)).data.toUtf8()
return payload === 'Second update'
},
Dates.seconds(1),
60,
)
expect(await bee.isFeedRetrievable(owner, NULL_TOPIC)).toBe(true)
expect(await bee.isFeedRetrievable(owner, NULL_TOPIC, FeedIndex.fromBigInt(1n))).toBe(true)
})