diff --git a/src/adapters/ipfs/ipfs-coord.js b/src/adapters/ipfs/ipfs-coord.js index cbb546f..142319b 100644 --- a/src/adapters/ipfs/ipfs-coord.js +++ b/src/adapters/ipfs/ipfs-coord.js @@ -29,8 +29,8 @@ class IpfsCoordAdapter { this.IpfsCoord = IpfsCoord this.ipfsCoord = {} this.bchjs = new BCHJS() - // this.rpc = new JSONRPC() this.config = config + this.publicIp = publicIp // Properties of this class instance. this.isReady = false @@ -44,7 +44,7 @@ class IpfsCoordAdapter { // If configured as a Circuit Relay, get the public IP addresses for this node. if (this.config.isCircuitRelay) { try { - const ip4 = await publicIp.v4() + const ip4 = await this.publicIp.v4() // const ip6 = await publicIp.v6() circuitRelayInfo.ip4 = ip4 diff --git a/test/unit/adapters/ipfs-coord.adapter.unit.js b/test/unit/adapters/ipfs-coord.adapter.unit.js index c9b5003..40c8516 100644 --- a/test/unit/adapters/ipfs-coord.adapter.unit.js +++ b/test/unit/adapters/ipfs-coord.adapter.unit.js @@ -47,6 +47,20 @@ describe('#IPFS', () => { assert.equal(result, true) }) + + it('should get the public IP address if this node is a Circuit Relay', async () => { + // Mock dependencies. + uut.IpfsCoord = IPFSCoordMock + sandbox.stub(uut.publicIp, 'v4').returns('123') + + // Force Circuit Relay + uut.config.isCircuitRelay = true + + const result = await uut.start() + // console.log('result: ', result) + + assert.equal(result, true) + }) }) describe('#attachRPCRouter', () => { @@ -71,16 +85,19 @@ describe('#IPFS', () => { uut.attachRPCRouter(router) }) - // it('should throw an error if ipfs-coord has not been instantiated', () => { - // try { - // const router = console.log - // - // uut.attachRPCRouter(router) - // - // assert.fail('Unexpected code path') - // } catch (err) { - // assert.include(err.message, 'Cannot read property') - // } - // }) + it('should catch and throw an error', () => { + try { + // Force an error + delete uut.ipfsCoord.adapters + + const router = console.log + + uut.attachRPCRouter(router) + + assert.fail('Unexpected code path') + } catch (err) { + assert.include(err.message, 'Cannot read property') + } + }) }) })