Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
feat: add util.cid options (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider authored Jun 26, 2018
1 parent e767312 commit f416b43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions eth-tx/test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const expect = require('chai').expect
const Transaction = require('ethereumjs-tx')
const dagEthBlock = require('../index')
const resolver = dagEthBlock.resolver
const util = dagEthBlock.util
const multihash = require('multihashes')

describe('IPLD format resolver (local)', () => {
let testIpfsBlob
Expand Down Expand Up @@ -56,4 +58,32 @@ describe('IPLD format resolver (local)', () => {
})
})
})

describe('util', () => {
it('create CID, no options', (done) => {
const testTx = new Transaction(testData)
util.cid(testTx, (err, cid) => {
expect(err).to.not.exist()
expect(cid.version).to.equal(1)
expect(cid.codec).to.equal('eth-tx')
expect(cid.multihash).to.exist()
const mh = multihash.decode(cid.multihash)
expect(mh.name).to.equal('keccak-256')
done()
})
})

it('create CID, empty options', (done) => {
const testTx = new Transaction(testData)
util.cid(testTx, {}, (err, cid) => {
expect(err).to.not.exist()
expect(cid.version).to.equal(1)
expect(cid.codec).to.equal('eth-tx')
expect(cid.multihash).to.exist()
const mh = multihash.decode(cid.multihash)
expect(mh.name).to.equal('keccak-256')
done()
})
})
})
})
2 changes: 1 addition & 1 deletion util/createUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ function createUtil (multicodec, EthObjClass) {
return {
deserialize: asyncify((serialized) => new EthObjClass(serialized)),
serialize: asyncify((ethObj) => ethObj.serialize()),
cid: asyncify((ethObj) => cidFromEthObj(multicodec, ethObj))
cid: asyncify((ethObj, options) => cidFromEthObj(multicodec, ethObj))
}
}

0 comments on commit f416b43

Please sign in to comment.