interface-ipfs-core
Version:
A test suite and interface you can use to implement a IPFS core interface.
49 lines (37 loc) • 1.26 kB
JavaScript
/* eslint-env mocha */
import { nanoid } from 'nanoid'
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testRename (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.key.rename', () => {
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => {
ipfs = (await factory.spawn()).api
})
after(() => factory.clean())
it('should rename a key', async function () {
this.timeout(30 * 1000)
const oldName = nanoid()
const newName = nanoid()
const key = await ipfs.key.gen(oldName, { type: 'rsa', size: 2048 })
const renameRes = await ipfs.key.rename(oldName, newName)
expect(renameRes).to.exist()
expect(renameRes).to.have.property('was', oldName)
expect(renameRes).to.have.property('now', newName)
expect(renameRes).to.have.property('id', key.id)
const res = await ipfs.key.list()
expect(res.find(k => k.name === newName)).to.exist()
expect(res.find(k => k.name === oldName)).to.not.exist()
})
})
}