Skip to content

Commit bba22d2

Browse files
zebateirajacobheun
authored andcommitted
feat: add new memory protocol for testing and other simulation scenarios
1 parent 46bb352 commit bba22d2

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/convert.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Convert.toString = function convertToString (proto, buf) {
3636
case 55: // dns6
3737
case 56: // dnsaddr
3838
case 400: // unix
39+
case 777: // memory
3940
return buf2str(buf)
4041

4142
case 421: // ipfs
@@ -68,6 +69,7 @@ Convert.toBuffer = function convertToBuffer (proto, str) {
6869
case 55: // dns6
6970
case 56: // dnsaddr
7071
case 400: // unix
72+
case 777: // memory
7173
return str2buf(str)
7274

7375
case 421: // ipfs

src/protocols-table.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Protocols.table = [
5555
[477, 0, 'ws'],
5656
[478, 0, 'wss'],
5757
[479, 0, 'p2p-websocket-star'],
58-
[480, 0, 'http']
58+
[480, 0, 'http'],
59+
[777, V, 'memory']
5960
]
6061

6162
Protocols.names = {}

test/index.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,13 @@ describe('variants', () => {
469469
expect(addr).to.have.property('buffer')
470470
expect(addr.toString()).to.equal(str)
471471
})
472+
473+
it('memory + p2p', () => {
474+
const str = '/memory/test/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
475+
const addr = multiaddr(str)
476+
expect(addr).to.have.property('buffer')
477+
expect(addr.toString()).to.equal(str)
478+
})
472479
})
473480

474481
describe('helpers', () => {
@@ -580,6 +587,24 @@ describe('helpers', () => {
580587
resolvable: false
581588
}])
582589
})
590+
591+
it('works with memory', () => {
592+
expect(
593+
multiaddr('/memory/test/p2p/QmZR5a9AAXGqQF2ADqoDdGS8zvqv8n3Pag6TDDnTNMcFW6').protos()
594+
).to.be.eql([{
595+
code: 777,
596+
name: 'memory',
597+
path: false,
598+
size: -1,
599+
resolvable: false
600+
}, {
601+
code: 421,
602+
name: 'p2p',
603+
path: false,
604+
size: -1,
605+
resolvable: false
606+
}])
607+
})
583608
})
584609

585610
describe('.tuples', () => {

0 commit comments

Comments
 (0)