@leofcoin/peernet 1.1.78 → 1.1.80
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/exports/browser/{browser-P2HFBJsB.js → browser-DQJ6xf_F.js} +3 -3
- package/exports/browser/browser-store.js +168 -22
- package/exports/browser/{client-5mPwJbpC.js → client-Depp28gl.js} +66 -32
- package/exports/browser/{peernet-x3p3hKA5.js → identity-CQ_ieRiz.js} +2236 -13421
- package/exports/browser/identity.d.ts +1 -1
- package/exports/browser/identity.js +1 -0
- package/exports/browser/{index-fC0k-d_O.js → index-BeqbCwUk.js} +1 -2
- package/exports/browser/{index-00QxgDks.js → index-DqPlTtAJ.js} +7 -9
- package/exports/browser/{messages-rdtq6jgH.js → messages-RYLqPGkg.js} +3 -2
- package/exports/browser/peernet-B7TZP-Wg.js +13220 -0
- package/exports/browser/peernet.d.ts +8 -8
- package/exports/browser/peernet.js +3 -2
- package/exports/identity.js +92 -0
- package/exports/peernet.js +25 -101
- package/exports/store.js +9 -2
- package/exports/types/identity.d.ts +1 -1
- package/exports/types/peernet.d.ts +8 -8
- package/package.json +34 -25
- package/rollup.config.js +2 -2
- package/src/peernet.ts +16 -12
- package/test/peernet.test.js +159 -0
- package/tsconfig.json +2 -4
- /package/exports/browser/{browser-AyxSBUXj.js → browser-pguCHlVu.js} +0 -0
- /package/exports/browser/{qr-scanner-worker.min-RaSiJc_R.js → qr-scanner-worker.min-Dy0qkKA4.js} +0 -0
- /package/exports/browser/{value-wzPYMxsX.js → value-C3vAp-wb.js} +0 -0
- /package/exports/{messages-T3M-Ff1E.js → messages-CRhtDipD.js} +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import Peernet from '../exports/peernet.js'
|
|
2
|
+
import Identity from '../exports/identity.js'
|
|
3
|
+
import { expect } from 'chai'
|
|
4
|
+
import sinon from 'sinon'
|
|
5
|
+
import networks from '@leofcoin/networks'
|
|
6
|
+
|
|
7
|
+
const network = networks.leofcoin.peach
|
|
8
|
+
|
|
9
|
+
let options
|
|
10
|
+
let password
|
|
11
|
+
options = {
|
|
12
|
+
network: 'leofcoin:peach',
|
|
13
|
+
stars: network.stars,
|
|
14
|
+
root: '.testnet',
|
|
15
|
+
version: '1.0.0',
|
|
16
|
+
storePrefix: 'test'
|
|
17
|
+
}
|
|
18
|
+
password = 'password'
|
|
19
|
+
const peernet = await new Peernet(options, password)
|
|
20
|
+
|
|
21
|
+
describe('Peernet', async () => {
|
|
22
|
+
// beforeEach(async () => {
|
|
23
|
+
// })
|
|
24
|
+
|
|
25
|
+
it('should initialize with the correct network', () => {
|
|
26
|
+
expect(peernet.network).to.equal('leofcoin:peach')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should initialize with the correct version', () => {
|
|
30
|
+
expect(peernet.version).to.equal('1.0.0')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should initialize with the correct store prefix', () => {
|
|
34
|
+
expect(peernet.storePrefix).to.equal('test')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should have an identity instance', () => {
|
|
38
|
+
expect(peernet.identity).to.be.instanceOf(Identity)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should have a DHT instance', () => {
|
|
42
|
+
expect(peernet.dht).to.not.be.undefined
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should start the client', async () => {
|
|
46
|
+
const startSpy = sinon.spy(peernet, 'start')
|
|
47
|
+
await peernet.start()
|
|
48
|
+
expect(startSpy.calledOnce).to.be.true
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should add a proto', () => {
|
|
52
|
+
const protoName = 'test-proto'
|
|
53
|
+
const proto = {}
|
|
54
|
+
peernet.addProto(protoName, proto)
|
|
55
|
+
expect(globalThis.peernet.protos[protoName]).to.equal(proto)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('should add a codec', () => {
|
|
59
|
+
const codec = { name: 'test-codec' }
|
|
60
|
+
const addCodecSpy = sinon.spy(peernet, 'addCodec')
|
|
61
|
+
peernet.addCodec(codec)
|
|
62
|
+
expect(addCodecSpy.calledOnceWith(codec)).to.be.true
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should select an account', async () => {
|
|
66
|
+
const account = 'test-account'
|
|
67
|
+
const selectAccountSpy = sinon.spy(peernet.identity, 'selectAccount')
|
|
68
|
+
await peernet.selectAccount(account)
|
|
69
|
+
expect(selectAccountSpy.calledOnceWith(account)).to.be.true
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should prepare a message', () => {
|
|
73
|
+
const data = { message: 'test' }
|
|
74
|
+
const prepareMessageSpy = sinon.spy(peernet._messageHandler, 'prepareMessage')
|
|
75
|
+
peernet.prepareMessage(data)
|
|
76
|
+
expect(prepareMessageSpy.calledOnceWith(data)).to.be.true
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('should get peers', () => {
|
|
80
|
+
const peers = peernet.peers
|
|
81
|
+
expect(peers).to.be.an('array')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should get connections', () => {
|
|
85
|
+
const connections = peernet.connections
|
|
86
|
+
expect(connections).to.be.an('object')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('should get a connection by id', () => {
|
|
90
|
+
const id = 'test-id'
|
|
91
|
+
const connection = peernet.getConnection(id)
|
|
92
|
+
expect(connection).to.be.undefined // Assuming no connections are established in the test
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// it('should handle DHT', async () => {
|
|
96
|
+
// const peer = {}
|
|
97
|
+
// const id = 'test-id'
|
|
98
|
+
// const proto = { decoded: { hash: 'test-hash', store: 'test-store' } }
|
|
99
|
+
// const handleDHTSpy = sinon.spy(peernet, 'handleDHT')
|
|
100
|
+
// await peernet.handleDHT(peer, id, proto)
|
|
101
|
+
// expect(handleDHTSpy.calledOnceWith(peer, id, proto)).to.be.true
|
|
102
|
+
// })
|
|
103
|
+
|
|
104
|
+
it('should handle data', async () => {
|
|
105
|
+
const peer = {}
|
|
106
|
+
const id = 'test-id'
|
|
107
|
+
const proto = { decoded: { hash: 'test-hash', store: 'test-store' } }
|
|
108
|
+
const handleDataSpy = sinon.spy(peernet, 'handleData')
|
|
109
|
+
await peernet.handleData(peer, id, proto)
|
|
110
|
+
expect(handleDataSpy.calledOnceWith(peer, id, proto)).to.be.true
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should handle request', async () => {
|
|
114
|
+
const peer = {}
|
|
115
|
+
const id = 'test-id'
|
|
116
|
+
const proto = { decoded: { request: 'test-request' } }
|
|
117
|
+
const handleRequestSpy = sinon.spy(peernet, 'handleRequest')
|
|
118
|
+
await peernet.handleRequest(peer, id, proto)
|
|
119
|
+
expect(handleRequestSpy.calledOnceWith(peer, id, proto)).to.be.true
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('should walk the network', async () => {
|
|
123
|
+
const hash = 'test-hash'
|
|
124
|
+
const walkSpy = sinon.spy(peernet, 'walk')
|
|
125
|
+
await peernet.walk(hash)
|
|
126
|
+
expect(walkSpy.calledOnceWith(hash)).to.be.true
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// it('should find providers for a hash', async () => {
|
|
130
|
+
// const hash = 'test-hash'
|
|
131
|
+
// const providers = await peernet.providersFor(hash)
|
|
132
|
+
// expect(providers).to.be.undefined // Assuming no providers are found in the test
|
|
133
|
+
// })
|
|
134
|
+
|
|
135
|
+
// it('should request data', async () => {
|
|
136
|
+
// const hash = 'test-hash'
|
|
137
|
+
// const requestDataSpy = sinon.spy(peernet, 'requestData')
|
|
138
|
+
// await peernet.requestData(hash, 'data')
|
|
139
|
+
// expect(requestDataSpy.calledOnceWith(hash, 'data')).to.be.true
|
|
140
|
+
// })
|
|
141
|
+
|
|
142
|
+
it('should publish data', async () => {
|
|
143
|
+
const topic = 'test-topic'
|
|
144
|
+
const data = 'test-data'
|
|
145
|
+
const publishSpy = sinon.spy(peernet, 'publish')
|
|
146
|
+
await peernet.publish(topic, data)
|
|
147
|
+
expect(publishSpy.calledOnceWith(topic, data)).to.be.true
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('should subscribe to a topic', async () => {
|
|
151
|
+
const topic = 'test-topic'
|
|
152
|
+
const callback = sinon.spy()
|
|
153
|
+
const subscribeSpy = sinon.spy(peernet, 'subscribe')
|
|
154
|
+
await peernet.subscribe(topic, callback)
|
|
155
|
+
expect(subscribeSpy.calledOnceWith(topic, callback)).to.be.true
|
|
156
|
+
|
|
157
|
+
process.exit()
|
|
158
|
+
})
|
|
159
|
+
})
|
package/tsconfig.json
CHANGED
|
File without changes
|
/package/exports/browser/{qr-scanner-worker.min-RaSiJc_R.js → qr-scanner-worker.min-Dy0qkKA4.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|