This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade to new ipfs-block and blockservice
- Loading branch information
1 parent
eb9b9f1
commit 1dd4dd2
Showing
11 changed files
with
177 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,42 @@ | ||
/* eslint-env mocha */ | ||
/* global self */ | ||
|
||
'use strict' | ||
|
||
const series = require('async/series') | ||
const Store = require('idb-pull-blob-store') | ||
const _ = require('lodash') | ||
const IPFSRepo = require('ipfs-repo') | ||
const repoContext = require.context('buffer!./test-repo', true) | ||
const pull = require('pull-stream') | ||
|
||
const basePath = 'ipfs' + Math.random() | ||
|
||
const idb = self.indexedDB || | ||
self.mozIndexedDB || | ||
self.webkitIndexedDB || | ||
self.msIndexedDB | ||
|
||
idb.deleteDatabase('ipfs') | ||
idb.deleteDatabase('ipfs/blocks') | ||
idb.deleteDatabase(basePath) | ||
idb.deleteDatabase(basePath + '/blocks') | ||
|
||
describe('Browser tests', () => { | ||
const path = 'ipfs' + Math.random() | ||
describe('Browser', () => { | ||
const repo = new IPFSRepo(basePath) | ||
|
||
before((done) => { | ||
const repoData = [] | ||
|
||
repoContext.keys().forEach((key) => { | ||
repoData.push({ | ||
key: key.replace('./', ''), | ||
value: repoContext(key) | ||
}) | ||
}) | ||
|
||
const mainBlob = new Store(path) | ||
const blocksBlob = new Store(path + '/blocks') | ||
series([ | ||
(cb) => repo.init({}, cb), | ||
(cb) => repo.open(cb) | ||
], done) | ||
}) | ||
|
||
series(repoData.map((file) => (cb) => { | ||
if (_.startsWith(file.key, 'datastore/')) { | ||
return cb() | ||
after((done) => { | ||
series([ | ||
(cb) => repo.close(cb), | ||
(cb) => { | ||
idb.deleteDatabase(basePath) | ||
idb.deleteDatabase(basePath + '/blocks') | ||
cb() | ||
} | ||
|
||
const blocks = _.startsWith(file.key, 'blocks/') | ||
const blob = blocks ? blocksBlob : mainBlob | ||
const key = blocks ? file.key.replace(/^blocks\//, '') : file.key | ||
|
||
pull( | ||
pull( | ||
pull.values([file.value]), | ||
blob.write(key, cb) | ||
) | ||
) | ||
}), done) | ||
], done) | ||
}) | ||
|
||
const repo = new IPFSRepo(path, {stores: Store}) | ||
|
||
require('./dag-node-test')(repo) | ||
require('./dag-link-test')(repo) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const ncp = require('ncp').ncp | ||
const rimraf = require('rimraf') | ||
const IPFSRepo = require('ipfs-repo') | ||
const series = require('async/series') | ||
const os = require('os') | ||
|
||
describe('Node.js', () => { | ||
const repoExample = process.cwd() + '/test/test-repo' | ||
const repoTests = os.tmpDir() + '/t-r-' + Date.now() | ||
const repo = new IPFSRepo(repoTests) | ||
|
||
before((done) => { | ||
series([ | ||
(cb) => ncp(repoExample, repoTests, cb), | ||
(cb) => repo.open(cb) | ||
], done) | ||
}) | ||
|
||
after((done) => { | ||
series([ | ||
(cb) => repo.close(cb), | ||
(cb) => rimraf(repoTests, cb) | ||
], done) | ||
}) | ||
|
||
require('./dag-link-test')(repo) | ||
require('./dag-node-test')(repo) | ||
}) |
Oops, something went wrong.