holepunch-hop 0.4.5 → 0.5.0
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/.vscode/settings.json +3 -0
- package/package.json +11 -5
- package/src/adapters/timeConvertor.js +3 -0
- package/src/index.js +45 -10
- package/src/{peers.js → network/peers.js} +507 -136
- package/src/{bees.js → storage/bees.js} +142 -60
- package/src/{drive.js → storage/drive.js} +2 -3
- package/src/{fileParser.js → storage/fileParser.js} +7 -1
- package/test/datacommands/files/data/jan3-bitcoin.csv +17 -0
- package/test/datacommands/files/large-csv.test.js +7 -0
- package/test/datacommands/files/small-csv.test.js +76 -0
- package/test/datacommands/ledger/save-get-ledger.test.js +117 -0
- package/test/datacommands/results/save-get-results.test.js +122 -0
- package/test/holepunch-initiate.test.js +47 -0
- package/test/multipers/ten-peers-network.test.js +437 -0
- package/test/setup-bee-holepunch.test.js +45 -0
- package/test/setup-holepunch.test.js +14 -13
- package/test/threepers/peer3-geninvite-after.test.js +439 -0
- package/test/threepers/three-peers.test.js +159 -0
- package/test/threepers/two-then-three.test.js +434 -0
- package/test/twopeers/peerClient-Server.test.js +243 -0
- package/test/twopeers/reconnect-peers.test.js +257 -0
- package/test/twopeers/reconnect-serverthen-conerr.test.js +304 -0
- package/test/twopeers/reconnect-then-conerr.test.js +309 -0
- package/test/twopeers/two-peer-one-disconnect.test.js +162 -0
- package/test/twopeers/two-peer-server-disconnect.test.js +167 -0
- package/vitest.config.js +8 -0
- /package/src/{kbledger.js → ledger/kbledger.js} +0 -0
|
@@ -22,6 +22,7 @@ class HyperBee extends EventEmitter {
|
|
|
22
22
|
this.liveBees = {}
|
|
23
23
|
this.confirmPubLibList = {}
|
|
24
24
|
this.repPublicHolder = {}
|
|
25
|
+
this.activeBees = []
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -86,7 +87,7 @@ class HyperBee extends EventEmitter {
|
|
|
86
87
|
valueEncoding: 'json' // same options as above
|
|
87
88
|
})
|
|
88
89
|
await this.dbBentochat.ready()
|
|
89
|
-
beePubkeys.push({store:'bentochat', privacy: 'private', pubkey: b4a.toString(
|
|
90
|
+
beePubkeys.push({store:'bentochat', privacy: 'private', pubkey: b4a.toString(core14.key, 'hex')})
|
|
90
91
|
|
|
91
92
|
|
|
92
93
|
const core4 = this.store.get({ name: 'hopresults' })
|
|
@@ -113,6 +114,7 @@ class HyperBee extends EventEmitter {
|
|
|
113
114
|
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
114
115
|
valueEncoding: 'json' // same options as above
|
|
115
116
|
})
|
|
117
|
+
|
|
116
118
|
await this.dbBentocues.ready()
|
|
117
119
|
beePubkeys.push({store:'bentocues', privacy: 'public', pubkey: b4a.toString(core7.key, 'hex')})
|
|
118
120
|
// open the cues library
|
|
@@ -128,7 +130,15 @@ class HyperBee extends EventEmitter {
|
|
|
128
130
|
valueEncoding: 'json' // same options as above
|
|
129
131
|
})
|
|
130
132
|
await this.dbBentomodels.ready()
|
|
131
|
-
beePubkeys.push({store:'bentomodels', privacy: 'public', pubkey: b4a.toString(
|
|
133
|
+
beePubkeys.push({store:'bentomodels', privacy: 'public', pubkey: b4a.toString(core13.key, 'hex')})
|
|
134
|
+
|
|
135
|
+
const core15 = this.store.get({ name: 'bentoboxes' })
|
|
136
|
+
this.dbBentoBoxes = new Hyperbee(core15, {
|
|
137
|
+
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
138
|
+
valueEncoding: 'json' // same options as above
|
|
139
|
+
})
|
|
140
|
+
await this.dbBentoBoxes.ready()
|
|
141
|
+
beePubkeys.push({store:'bentoboxes', privacy: 'private', pubkey: b4a.toString(core15.key, 'hex')})
|
|
132
142
|
|
|
133
143
|
const core8 = this.store.get({ name: 'bentodecisions' })
|
|
134
144
|
this.dbBentodecisions = new Hyperbee(core8, {
|
|
@@ -138,7 +148,6 @@ class HyperBee extends EventEmitter {
|
|
|
138
148
|
await this.dbBentodecisions.ready()
|
|
139
149
|
beePubkeys.push({store:'bentodecisions', pubkey: b4a.toString(core8.key, 'hex')})
|
|
140
150
|
|
|
141
|
-
|
|
142
151
|
const core9 = this.store.get({ name: 'bentomarkers' })
|
|
143
152
|
this.dbBentomarkers = new Hyperbee(core9, {
|
|
144
153
|
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
@@ -147,7 +156,6 @@ class HyperBee extends EventEmitter {
|
|
|
147
156
|
await this.dbBentomarkers.ready()
|
|
148
157
|
beePubkeys.push({store:'bentomarkers', privacy: 'private', pubkey: b4a.toString(core9.key, 'hex')})
|
|
149
158
|
|
|
150
|
-
|
|
151
159
|
const core10 = this.store.get({ name: 'research' })
|
|
152
160
|
this.dbBentoresearch = new Hyperbee(core10, {
|
|
153
161
|
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
@@ -156,7 +164,6 @@ class HyperBee extends EventEmitter {
|
|
|
156
164
|
await this.dbBentoresearch.ready()
|
|
157
165
|
beePubkeys.push({store:'research', privacy: 'public', pubkey: b4a.toString(core10.key, 'hex')})
|
|
158
166
|
|
|
159
|
-
|
|
160
167
|
const core11 = this.store.get({ name: 'bentoproducts' })
|
|
161
168
|
this.dbBentoproducts = new Hyperbee(core11, {
|
|
162
169
|
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
@@ -181,60 +188,57 @@ class HyperBee extends EventEmitter {
|
|
|
181
188
|
startBeePubkey.data = beePubkeys
|
|
182
189
|
this.liveBees = startBeePubkey
|
|
183
190
|
this.wsocket.send(JSON.stringify(startBeePubkey))
|
|
191
|
+
this.activeBees = beePubkeys
|
|
192
|
+
|
|
193
|
+
// test list of results
|
|
194
|
+
/* let listResults = await this.peerResults()
|
|
195
|
+
console.log(listResults)
|
|
196
|
+
for (let res of listResults) {
|
|
197
|
+
await this.deleteResultsItem(res.key)
|
|
198
|
+
} */
|
|
184
199
|
}
|
|
185
200
|
|
|
201
|
+
/* HOP query results */
|
|
202
|
+
|
|
186
203
|
/**
|
|
187
|
-
* save
|
|
188
|
-
* @method
|
|
204
|
+
* save HOPresults
|
|
205
|
+
* @method saveHOPresults
|
|
189
206
|
*
|
|
190
207
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
// go query the key are return the info. to ensure data save asplanned.
|
|
194
|
-
let saveCheck = await this.getPublicLibrary(refContract.data.hash)
|
|
195
|
-
let returnMessage = {}
|
|
196
|
-
returnMessage.stored = true
|
|
197
|
-
returnMessage.type = refContract.reftype
|
|
198
|
-
returnMessage.key = saveCheck.key
|
|
199
|
-
returnMessage.contract = saveCheck.value
|
|
200
|
-
return returnMessage
|
|
208
|
+
saveHOPresults = async function (refContract) {
|
|
209
|
+
await this.dbHOPresults.put(refContract.hash, refContract.data)
|
|
201
210
|
}
|
|
202
|
-
|
|
203
211
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
let saveCheck = await this.getPeerLibrary(refContract.data.hash)
|
|
212
|
-
let returnMessage = {}
|
|
213
|
-
returnMessage.stored = true
|
|
214
|
-
returnMessage.type = refContract.reftype
|
|
215
|
-
returnMessage.key = saveCheck.key
|
|
216
|
-
returnMessage.contract = saveCheck.value
|
|
217
|
-
return returnMessage
|
|
212
|
+
peerResults = async function () {
|
|
213
|
+
const nodeData = this.dbHOPresults.createReadStream()
|
|
214
|
+
let resData = []
|
|
215
|
+
for await (const { key, value } of nodeData) {
|
|
216
|
+
resData.push({ key, value })
|
|
217
|
+
}
|
|
218
|
+
return resData
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
/**
|
|
221
|
-
*
|
|
222
|
-
* @method
|
|
222
|
+
* lookup results per dataprint hash
|
|
223
|
+
* @method peerResultsItem
|
|
223
224
|
*
|
|
224
225
|
*/
|
|
225
|
-
|
|
226
|
-
await this.
|
|
226
|
+
peerResultsItem = async function (key) {
|
|
227
|
+
const resultData = await this.dbHOPresults.get(key)
|
|
228
|
+
return resultData
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
/**
|
|
230
|
-
*
|
|
231
|
-
* @method
|
|
232
|
+
* delete results
|
|
233
|
+
* @method deleteResultsItem
|
|
232
234
|
*
|
|
233
235
|
*/
|
|
234
|
-
|
|
235
|
-
await this.dbHOPresults.
|
|
236
|
+
deleteResultsItem = async function (key) {
|
|
237
|
+
const resultData = await this.dbHOPresults.del(key)
|
|
238
|
+
return resultData
|
|
236
239
|
}
|
|
237
240
|
|
|
241
|
+
|
|
238
242
|
/** CHAT */
|
|
239
243
|
|
|
240
244
|
/**
|
|
@@ -392,6 +396,53 @@ class HyperBee extends EventEmitter {
|
|
|
392
396
|
return deleteInfo
|
|
393
397
|
}
|
|
394
398
|
|
|
399
|
+
/** BENTOBOXES */
|
|
400
|
+
/**
|
|
401
|
+
* save model
|
|
402
|
+
* @method saveModel
|
|
403
|
+
*/
|
|
404
|
+
saveBentoBox = async function (boxInfo) {
|
|
405
|
+
await this.dbBentoBoxes.put(boxInfo.id, boxInfo.data)
|
|
406
|
+
let checkSave = await this.getBentoBox(boxInfo.id)
|
|
407
|
+
return checkSave
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* get one cue by id
|
|
412
|
+
* @method getModel
|
|
413
|
+
*
|
|
414
|
+
*/
|
|
415
|
+
getBentoBox = async function (key) {
|
|
416
|
+
const nodeData = await this.dbBentoBoxes.get(key)
|
|
417
|
+
return nodeData
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* get all cuees
|
|
422
|
+
* @method getModelHistory
|
|
423
|
+
*
|
|
424
|
+
*/
|
|
425
|
+
getBentoBoxHistory = async function (key) {
|
|
426
|
+
const boxHistory = await this.dbBentoBoxes.createReadStream()
|
|
427
|
+
let boxData = []
|
|
428
|
+
for await (const { key, value } of boxHistory) {
|
|
429
|
+
boxData.push({ key, value })
|
|
430
|
+
}
|
|
431
|
+
return boxData
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* delete nxp ref contract from peer library
|
|
436
|
+
* @method deleteBentoBox
|
|
437
|
+
*/
|
|
438
|
+
deleteBentoBox = async function (box) {
|
|
439
|
+
const deleteStatus = await this.dbBentoBoxes.del(box.id)
|
|
440
|
+
let deleteInfo = {}
|
|
441
|
+
deleteInfo.id = box.id
|
|
442
|
+
return deleteInfo
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
|
|
395
446
|
/** MODELS */
|
|
396
447
|
/**
|
|
397
448
|
* save model
|
|
@@ -698,6 +749,42 @@ class HyperBee extends EventEmitter {
|
|
|
698
749
|
return nodeData
|
|
699
750
|
}
|
|
700
751
|
|
|
752
|
+
//** */ public library **//
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* save pair in keystore public network library
|
|
756
|
+
* @method savePubliclibrary
|
|
757
|
+
*
|
|
758
|
+
*/
|
|
759
|
+
savePubliclibrary = async function (refContract) {
|
|
760
|
+
await this.dbPublicLibrary.put(refContract.data.hash, refContract.data.contract)
|
|
761
|
+
// go query the key are return the info. to ensure data save asplanned.
|
|
762
|
+
let saveCheck = await this.getPublicLibrary(refContract.data.hash)
|
|
763
|
+
let returnMessage = {}
|
|
764
|
+
returnMessage.stored = true
|
|
765
|
+
returnMessage.type = refContract.reftype
|
|
766
|
+
returnMessage.key = saveCheck.key
|
|
767
|
+
returnMessage.contract = saveCheck.value
|
|
768
|
+
return returnMessage
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* save pair in keystore db
|
|
774
|
+
* @method savePeerLibrary
|
|
775
|
+
*
|
|
776
|
+
*/
|
|
777
|
+
savePeerLibrary = async function (refContract) {
|
|
778
|
+
await this.dbPeerLibrary.put(refContract.data.hash, refContract.data.contract)
|
|
779
|
+
let saveCheck = await this.getPeerLibrary(refContract.data.hash)
|
|
780
|
+
let returnMessage = {}
|
|
781
|
+
returnMessage.stored = true
|
|
782
|
+
returnMessage.type = refContract.reftype
|
|
783
|
+
returnMessage.key = saveCheck.key
|
|
784
|
+
returnMessage.contract = saveCheck.value
|
|
785
|
+
return returnMessage
|
|
786
|
+
}
|
|
787
|
+
|
|
701
788
|
/**
|
|
702
789
|
* lookup specific result UUID
|
|
703
790
|
* @method getPublicLibrary
|
|
@@ -776,6 +863,16 @@ class HyperBee extends EventEmitter {
|
|
|
776
863
|
return moduleData
|
|
777
864
|
}
|
|
778
865
|
|
|
866
|
+
/* COHERENCE LEDGER Knowledge Bundle Ledger */
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* save kbledger entry
|
|
870
|
+
* @method saveKBLentry
|
|
871
|
+
*
|
|
872
|
+
*/
|
|
873
|
+
saveKBLentry = async function (ledgerEntry) {
|
|
874
|
+
await this.dbKBledger.put(ledgerEntry.data, ledgerEntry.hash)
|
|
875
|
+
}
|
|
779
876
|
|
|
780
877
|
/**
|
|
781
878
|
* get all kbl entries
|
|
@@ -792,30 +889,15 @@ class HyperBee extends EventEmitter {
|
|
|
792
889
|
}
|
|
793
890
|
|
|
794
891
|
/**
|
|
795
|
-
* lookup
|
|
796
|
-
* @method
|
|
797
|
-
*
|
|
798
|
-
*/
|
|
799
|
-
peerResultsItem = async function (dataPrint) {
|
|
800
|
-
const resultsData = this.dbKBledger.get(dataPrint.resultuuid)
|
|
801
|
-
return resultsData
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* lookup specific result UUID
|
|
806
|
-
* @method peerResults
|
|
892
|
+
* lookup coherence ledger per results id
|
|
893
|
+
* @method peerLedgerProof
|
|
807
894
|
*
|
|
808
895
|
*/
|
|
809
|
-
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
for await (const { key, value } of nodeData) {
|
|
813
|
-
resData.push({ key, value })
|
|
814
|
-
}
|
|
815
|
-
return resData
|
|
896
|
+
peerLedgerProof = async function (dataPrint) {
|
|
897
|
+
const ledgerData = await this.dbKBledger.get(dataPrint.resultuuid)
|
|
898
|
+
return ledgerData
|
|
816
899
|
}
|
|
817
900
|
|
|
818
|
-
|
|
819
901
|
/**
|
|
820
902
|
* get stream data for keystore db
|
|
821
903
|
* @method getStreamHyperbeeDB
|
|
@@ -13,7 +13,7 @@ import fs from 'fs'
|
|
|
13
13
|
import Hyperdrive from 'hyperdrive'
|
|
14
14
|
import b4a from 'b4a'
|
|
15
15
|
import Fileparser from './fileParser.js'
|
|
16
|
-
import SqliteAdapter from '
|
|
16
|
+
import SqliteAdapter from '../adapters/sqliteDatabase.js'
|
|
17
17
|
import csv from 'csv-parser'
|
|
18
18
|
import { DateTime, Interval } from 'luxon'
|
|
19
19
|
import * as chrono from 'chrono-node'
|
|
@@ -54,12 +54,11 @@ class HypDrive extends EventEmitter {
|
|
|
54
54
|
// One for a file metadata Hyperbee, and one for a content Hypercore
|
|
55
55
|
this.drive = new Hyperdrive(this.core)
|
|
56
56
|
await this.drive.ready()
|
|
57
|
-
|
|
58
57
|
let startDrivePubkey = {}
|
|
59
58
|
startDrivePubkey.type = 'account'
|
|
60
59
|
startDrivePubkey.action = 'drive-pubkey'
|
|
61
60
|
startDrivePubkey.data = b4a.toString(this.drive.key, 'hex')
|
|
62
|
-
this.wsocket.send(JSON.stringify(startDrivePubkey))
|
|
61
|
+
// this.wsocket.send(JSON.stringify(startDrivePubkey))
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
|
|
@@ -18,7 +18,7 @@ import events from 'events'
|
|
|
18
18
|
import axios from 'axios'
|
|
19
19
|
import csv from 'csv-parser'
|
|
20
20
|
import crypto from 'crypto'
|
|
21
|
-
import TimeConvert from '
|
|
21
|
+
import TimeConvert from '../adapters/timeConvertor.js'
|
|
22
22
|
import { DateTime, Interval } from 'luxon'
|
|
23
23
|
import * as chrono from 'chrono-node'
|
|
24
24
|
|
|
@@ -162,6 +162,8 @@ FileParser.prototype.TEMPwebJSONparse = function (fjData) {
|
|
|
162
162
|
*
|
|
163
163
|
*/
|
|
164
164
|
FileParser.prototype.TEMPwebCSVparse = function (fData) {
|
|
165
|
+
console.log('tem csv file data')
|
|
166
|
+
console.log(fData[0])
|
|
165
167
|
// match name row number
|
|
166
168
|
let lcounter = 0
|
|
167
169
|
let match = ''
|
|
@@ -178,10 +180,14 @@ FileParser.prototype.TEMPwebCSVparse = function (fData) {
|
|
|
178
180
|
// pairData.timestamp = splitRow[2]
|
|
179
181
|
// pairData.price = splitRow[5]
|
|
180
182
|
// console.log(pairData)
|
|
183
|
+
console.log('looop')
|
|
184
|
+
console.log(splitRow)
|
|
181
185
|
if (splitRow[1] !== undefined) {
|
|
182
186
|
extractCol.push(splitRow[fData.context.id])
|
|
183
187
|
// assume data column for now and parse to mills seconds
|
|
184
188
|
let testCH1 = chrono.parseDate(splitRow[fData.context.timestamp])
|
|
189
|
+
console.log('pare chonon date')
|
|
190
|
+
console.log(testCH1)
|
|
185
191
|
let parseDate = this.convertTime.testDataExtact(testCH1)
|
|
186
192
|
// let parseDate = DateTime.fromISO(splitRow[0])
|
|
187
193
|
// let millDate = parseDate.toMillis()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
datetime,tz_cd,price,volume,source,site_no
|
|
2
|
+
2009-01-03 01:30,PST,0,0,bitcoin,0
|
|
3
|
+
2010-01-03 01:30,PST,0,0,bitcoin,0
|
|
4
|
+
2011-01-03 01:30,PST,0.3,14300,bitcoin,0
|
|
5
|
+
2012-01-03 01:30,PST,4.9,125170,bitcoin,0
|
|
6
|
+
2013-01-03 01:30,PST,13.4,18030,bitcoin,0
|
|
7
|
+
2014-01-03 01:30,PST,884.3,9710,bitcoin,0
|
|
8
|
+
2015-01-03 01:30,PST,287.1,47370,bitcoin,0
|
|
9
|
+
2016-01-03 01:30,PST,430.7,54830,bitcoin,0
|
|
10
|
+
2017-01-03 01:30,PST,1033.3,547900,bitcoin,0
|
|
11
|
+
2018-01-03 01:31,PST,15156.6,106540,bitcoin,0
|
|
12
|
+
2019-01-03 01:32,PST,3780.1,468450,bitcoin,0
|
|
13
|
+
2020-01-03 01:33,PST,7343.1,938290,bitcoin,0
|
|
14
|
+
2021-01-03 01:34,PST,32958.9,155210,bitcoin,0
|
|
15
|
+
2022-01-03 01:35,PST,46430.2,41060,bitcoin,0
|
|
16
|
+
2023-01-03 01:36,PST,16674.2,178730,bitcoin,0
|
|
17
|
+
2024-01-03 01:37,PST,42836.1,117650,bitcoin,0
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
|
+
import Corestore from 'corestore'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import os from 'os'
|
|
6
|
+
import Hyperswarm from 'hyperswarm'
|
|
7
|
+
import goodbye from 'graceful-goodbye'
|
|
8
|
+
import b4a from 'b4a'
|
|
9
|
+
import DriveWorker from '../../../src/storage/drive.js'
|
|
10
|
+
|
|
11
|
+
// Get the path to the test data directory
|
|
12
|
+
const testDataPath = path.join(__dirname, 'data')
|
|
13
|
+
const testCSVPath = path.join(testDataPath, 'jan3-bitcoin.csv')
|
|
14
|
+
|
|
15
|
+
describe('CSV File Operations Tests', () => {
|
|
16
|
+
let store
|
|
17
|
+
let swarm
|
|
18
|
+
let clientDrive
|
|
19
|
+
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
|
|
22
|
+
store = new Corestore(os.homedir() + '/.test-file-store')
|
|
23
|
+
swarm = new Hyperswarm()
|
|
24
|
+
// make replication possible
|
|
25
|
+
swarm.on('connection', conn => store.replicate(conn))
|
|
26
|
+
goodbye(() => swarm.destroy())
|
|
27
|
+
|
|
28
|
+
// Create HypDrive instance
|
|
29
|
+
clientDrive = new DriveWorker(store, swarm)
|
|
30
|
+
|
|
31
|
+
// Initialize drive
|
|
32
|
+
await clientDrive.setupHyperdrive()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
afterEach(async () => {
|
|
36
|
+
// Clean up
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should save and retrieve small CSV file', async () => {
|
|
40
|
+
// 1. Read the actual CSV file
|
|
41
|
+
const csvContent = fs.readFileSync(testCSVPath, 'utf-8')
|
|
42
|
+
const csvFileName = path.basename(testCSVPath)
|
|
43
|
+
|
|
44
|
+
// 2. Save CSV file
|
|
45
|
+
await clientDrive.hyperdriveFilesave('text/csv', csvFileName, csvContent)
|
|
46
|
+
|
|
47
|
+
// 3. Verify file is saved
|
|
48
|
+
const clientFileContent = await clientDrive.drive.get('text/csv/' + csvFileName)
|
|
49
|
+
expect(clientFileContent.toString()).toBe(csvContent)
|
|
50
|
+
|
|
51
|
+
// 4. Verify file metadata
|
|
52
|
+
const fileInfo = await clientDrive.drive.entry('text/csv/' + csvFileName)
|
|
53
|
+
expect(fileInfo).toBeDefined()
|
|
54
|
+
expect(fileInfo.value.blob).toBeDefined()
|
|
55
|
+
expect(fileInfo.value.blob.byteLength).toBe(csvContent.length)
|
|
56
|
+
|
|
57
|
+
// 5. Verify file structure (headers)
|
|
58
|
+
const fileLines = csvContent.split('\n')
|
|
59
|
+
const headers = fileLines[0].split(',')
|
|
60
|
+
expect(headers.length).toBeGreaterThan(0)
|
|
61
|
+
expect(headers[0]).toBeDefined()
|
|
62
|
+
|
|
63
|
+
// 6. Verify specific 2015 entry
|
|
64
|
+
const entry2015 = fileLines[7] // 7th line (0-indexed)
|
|
65
|
+
expect(entry2015).toBe('2015-01-03 01:30,PST,287.1,47370,bitcoin,0')
|
|
66
|
+
|
|
67
|
+
// 7. Verify specific values in 2015 entry
|
|
68
|
+
const entryValues = entry2015.split(',')
|
|
69
|
+
expect(entryValues[0]).toBe('2015-01-03 01:30')
|
|
70
|
+
expect(entryValues[1]).toBe('PST')
|
|
71
|
+
expect(entryValues[2]).toBe('287.1')
|
|
72
|
+
expect(entryValues[3]).toBe('47370')
|
|
73
|
+
expect(entryValues[4]).toBe('bitcoin')
|
|
74
|
+
expect(entryValues[5]).toBe('0')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
|
2
|
+
import Corestore from 'corestore'
|
|
3
|
+
import Hyperswarm from 'hyperswarm'
|
|
4
|
+
import Hyperbee from 'hyperbee'
|
|
5
|
+
import b4a from 'b4a'
|
|
6
|
+
import hashObject from 'object-hash'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
import os from 'os'
|
|
9
|
+
import goodbye from 'graceful-goodbye'
|
|
10
|
+
import BeeWorker from '../../../src/storage/bees.js'
|
|
11
|
+
|
|
12
|
+
// Get the path to the test data directory
|
|
13
|
+
const testDataPath = path.join(__dirname, 'data')
|
|
14
|
+
|
|
15
|
+
describe('Hyperbee Ledger Tests', () => {
|
|
16
|
+
let store
|
|
17
|
+
let swarm
|
|
18
|
+
let bee
|
|
19
|
+
|
|
20
|
+
beforeAll(async () => {
|
|
21
|
+
console.log('start of before each')
|
|
22
|
+
store = new Corestore(os.homedir() + '/.test-ledger-store')
|
|
23
|
+
swarm = new Hyperswarm()
|
|
24
|
+
// make replication possible
|
|
25
|
+
swarm.on('connection', conn => store.replicate(conn))
|
|
26
|
+
goodbye(() => swarm.destroy())
|
|
27
|
+
|
|
28
|
+
// Additional wait for full initialization
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, 4000))
|
|
30
|
+
console.log('wait afoter')
|
|
31
|
+
// Create BeeWorker instance
|
|
32
|
+
bee = new BeeWorker(store, swarm)
|
|
33
|
+
// await bee.setupHyperbee() vitest have issues starting so many core at once
|
|
34
|
+
const core5 = store.get({ name: 'kbledger' })
|
|
35
|
+
bee.dbKBledger = new Hyperbee(core5, {
|
|
36
|
+
keyEncoding: 'utf-8',
|
|
37
|
+
valueEncoding: 'json'
|
|
38
|
+
})
|
|
39
|
+
await bee.dbKBledger.ready()
|
|
40
|
+
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
afterAll(async () => {
|
|
44
|
+
console.log('Cleaning up test environment')
|
|
45
|
+
// await swarm.destroy()
|
|
46
|
+
await bee.dbKBledger.close()
|
|
47
|
+
bee = null
|
|
48
|
+
store = null
|
|
49
|
+
// swarm = null
|
|
50
|
+
}, 20000) // 20 second timeout for cleanup
|
|
51
|
+
|
|
52
|
+
it('should perform basic Hyperbee operations', async () => {
|
|
53
|
+
// Test data
|
|
54
|
+
console.log('start of test')
|
|
55
|
+
const testHash = 'test-hash'
|
|
56
|
+
const testData = { message: 'Hello Hyperbee!' }
|
|
57
|
+
|
|
58
|
+
// 1. Put data
|
|
59
|
+
await bee.dbKBledger.put(testHash, testData)
|
|
60
|
+
|
|
61
|
+
// 2. Get data
|
|
62
|
+
const result = await bee.dbKBledger.get(testHash)
|
|
63
|
+
expect(result.value).toEqual(testData)
|
|
64
|
+
|
|
65
|
+
// 3. Batch operations with 32-byte keys
|
|
66
|
+
let res1 = { bbid: '1212121212', data: { value: [1, 2, 3] }}
|
|
67
|
+
let res2 = { bbid: '3232323232', data: { value: [4, 5, 6] }}
|
|
68
|
+
const batch = bee.dbKBledger.batch()
|
|
69
|
+
const key1 = hashObject(res1)
|
|
70
|
+
const key2 = hashObject(res2)
|
|
71
|
+
await batch.put(key1, res1)
|
|
72
|
+
await batch.put(key2, res2)
|
|
73
|
+
await batch.flush()
|
|
74
|
+
|
|
75
|
+
// 4. CreateReadStream
|
|
76
|
+
const stream = bee.dbKBledger.createReadStream()
|
|
77
|
+
const entries = []
|
|
78
|
+
for await (const entry of stream) {
|
|
79
|
+
entries.push(entry)
|
|
80
|
+
}
|
|
81
|
+
expect(entries.length).toBeGreaterThan(0)
|
|
82
|
+
|
|
83
|
+
// 5. Check version
|
|
84
|
+
expect(bee.dbKBledger.version).toBeGreaterThan(0)
|
|
85
|
+
|
|
86
|
+
// 6. Verify batch operations
|
|
87
|
+
const result1 = await bee.dbKBledger.get(key1)
|
|
88
|
+
expect(result1.key).toEqual(key1)
|
|
89
|
+
const result2 = await bee.dbKBledger.get(key2)
|
|
90
|
+
expect(result2.key).toEqual(key2)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should handle key value operations', async () => {
|
|
94
|
+
// Test data
|
|
95
|
+
console.log('start of test2')
|
|
96
|
+
let res1 = { bbid: '1212121212', data: { value: [1, 2, 3] }}
|
|
97
|
+
let res2 = { bbid: '3232323232', data: { value: [4, 5, 6] }}
|
|
98
|
+
const key1 = hashObject(res1)
|
|
99
|
+
const key2 = hashObject(res2)
|
|
100
|
+
|
|
101
|
+
// Put multiple values
|
|
102
|
+
await bee.dbKBledger.put(key1, res1)
|
|
103
|
+
await bee.dbKBledger.put(key2, res2)
|
|
104
|
+
|
|
105
|
+
// Get values
|
|
106
|
+
const result1 = await bee.dbKBledger.get(key1)
|
|
107
|
+
const result2 = await bee.dbKBledger.get(key2)
|
|
108
|
+
expect(result1.value.data.value[0]).toEqual(1)
|
|
109
|
+
expect(result2.value.data.value[0]).toEqual(4)
|
|
110
|
+
|
|
111
|
+
// Delete value
|
|
112
|
+
await bee.dbKBledger.del(key1)
|
|
113
|
+
const deletedResult = await bee.dbKBledger.get(key1)
|
|
114
|
+
expect(deletedResult).toBeNull()
|
|
115
|
+
console.log('end of test2')
|
|
116
|
+
})
|
|
117
|
+
})
|