Add test writing to v0 with new identity

This commit is contained in:
shamb0t 2019-03-25 13:35:33 +00:00
parent 78d23cce0c
commit aa9e7edd63
4 changed files with 786 additions and 765 deletions

1529
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -43,6 +43,7 @@
"ipfs": "^0.34.4",
"ipfs-repo": "^0.26.2",
"ipfsd-ctl": "^0.42.0",
"localstorage-level-migration": "github:orbitdb/localstorage-level-migration",
"markdown-toc": "^1.2.0",
"mocha": "^5.2.0",
"p-each-series": "^1.0.0",

View File

@ -0,0 +1 @@
{"publicKey":"04b54f6ef529cd2dd2f9c6897a382c492222d42e57826269a38101ffe752aa07260ecd092a970d7eef08c4ddae2b7006ee25f07e4ab62fa5262ae3b51fdea29f78","privateKey":"31cbd0193567605dba4cd27a0fe4de82151be65aac16b58f2337ec2b7ad41b38"}

View File

@ -11,6 +11,9 @@ const OrbitDB = require('../src/OrbitDB')
const OrbitDBAddress = require('../src/orbit-db-address')
const io = require('orbit-db-io')
const IPFS = require('ipfs')
const Identities = require('orbit-db-identity-provider')
const migrate = require('localstorage-level-migration').migrateKeys
// Include test utilities
const {
config,
@ -39,11 +42,14 @@ Object.keys(testAPIs).forEach(API => {
await fs.copy(path.join(ipfsFixturesDir, 'blocks'), path.join(ipfsd.path, 'blocks'))
await fs.copy(path.join(ipfsFixturesDir, 'datastore'), path.join(ipfsd.path, 'datastore'))
await fs.copy(dbFixturesDir, dbPath)
orbitdb = await OrbitDB.createInstance(ipfs, { directory: dbPath })
let identity = await Identities.createIdentity({ id: ipfs._peerInfo.id._idB58String, existingId: 'QmRfPsKJs9YqTot5krRibra4gPwoK4kghhU8iKWxBjGDDX', sourcePath: './test/fixtures/keys', migrate })
orbitdb = await OrbitDB.createInstance(ipfs, { directory: dbPath, identity })
})
after(async () => {
rmrf.sync(dbPath)
if(orbitdb)
await orbitdb.stop()
@ -54,6 +60,7 @@ Object.keys(testAPIs).forEach(API => {
describe('Open & Load', function() {
before(async () => {
db = await orbitdb.open('/orbitdb/QmWDUfC4zcWJGgc9UHn1X3qQ5KZqBv4KCiCtjnpMmBT8JC/v0-db')
await db.load()
})
after(async () => {
@ -82,9 +89,16 @@ Object.keys(testAPIs).forEach(API => {
})
it('load v0 orbitdb address', async () => {
await db.load()
assert.equal(db.all.length, 3)
})
it('allows migrated key to write', async () => {
const hash = await db.add({ thing: 'new addition'})
const newEntries = db.all.filter(e => e.v === 1)
assert.equal(newEntries.length, 1)
assert.strictEqual(newEntries[0].cid, hash)
})
})
})
})