Skip to content

Commit

Permalink
feat: add new memory protocol for testing and other simulation scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Ze Bateira authored and jacobheun committed Jun 25, 2020
1 parent 46bb352 commit bba22d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Convert.toString = function convertToString (proto, buf) {
case 55: // dns6
case 56: // dnsaddr
case 400: // unix
case 777: // memory
return buf2str(buf)

case 421: // ipfs
Expand Down Expand Up @@ -68,6 +69,7 @@ Convert.toBuffer = function convertToBuffer (proto, str) {
case 55: // dns6
case 56: // dnsaddr
case 400: // unix
case 777: // memory
return str2buf(str)

case 421: // ipfs
Expand Down
3 changes: 2 additions & 1 deletion src/protocols-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Protocols.table = [
[477, 0, 'ws'],
[478, 0, 'wss'],
[479, 0, 'p2p-websocket-star'],
[480, 0, 'http']
[480, 0, 'http'],
[777, V, 'memory']
]

Protocols.names = {}
Expand Down
25 changes: 25 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ describe('variants', () => {
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

it('memory + p2p', () => {
const str = '/memory/test/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})
})

describe('helpers', () => {
Expand Down Expand Up @@ -580,6 +587,24 @@ describe('helpers', () => {
resolvable: false
}])
})

it('works with memory', () => {
expect(
multiaddr('/memory/test/p2p/QmZR5a9AAXGqQF2ADqoDdGS8zvqv8n3Pag6TDDnTNMcFW6').protos()
).to.be.eql([{
code: 777,
name: 'memory',
path: false,
size: -1,
resolvable: false
}, {
code: 421,
name: 'p2p',
path: false,
size: -1,
resolvable: false
}])
})
})

describe('.tuples', () => {
Expand Down

0 comments on commit bba22d2

Please sign in to comment.