How to use the interface-ipfs-core/src/utils/mocha.expect function in interface-ipfs-core

To help you get started, we’ve selected a few interface-ipfs-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / js-ipfs / test / core / init.spec.js View on Github external
ipfs.init({ bits: 512, emptyRepo: true }, (err) => {
      expect(err).to.not.exist()

      // Should not have default assets
      const multihash = Buffer.from('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex')

      ipfs.object.get(multihash, {}, (err, node) => {
        expect(err).to.exist()
        done()
      })
    })
  })
github ipfs / js-ipfs / test / gateway / index.js View on Github external
it('load a directory with index.html', async () => {
    const dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/' // note '/' at the end

    const res = await gateway.inject({
      method: 'GET',
      url: '/ipfs/' + dir
    })

    // confirm payload is index.html
    expect(res.statusCode).to.equal(200)
    expect(res.headers['content-type']).to.equal('text/html; charset=utf-8')
    expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + dir)
    expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable')
    expect(res.headers['last-modified']).to.equal('Thu, 01 Jan 1970 00:00:01 GMT')
    expect(res.headers['content-length']).to.equal(res.rawPayload.length)
    expect(res.headers.etag).to.equal('"Qma6665X5k3zti8nKy7gmXK2BndNDSkgmANpV6k3FUjUeg"')
    expect(res.headers.suborigin).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe')
    expect(res.rawPayload).to.deep.equal(directoryContent['index.html'])
  })
github ipfs / js-ipfs / test / core / name-pubsub.js View on Github external
// Create account for publish
    const testAccount = await nodeA.key.gen(testAccountName, {
      type: 'rsa',
      size: 2048
    })

    const keys = ipns.getIdKeys(fromB58String(testAccount.id))
    const topic = `${namespace}${base64url.encode(keys.routingKey.toBuffer())}`

    await nodeB.pubsub.subscribe(topic, checkMessage)
    await nodeA.name.publish(ipfsRef, { resolve: false, key: testAccountName })
    await waitFor(alreadySubscribed)
    const messageKey = await promisify(peerId.createFromPubKey)(publishedMessage.key)
    const pubKeyPeerId = await promisify(peerId.createFromPubKey)(publishedMessageData.pubKey)

    expect(pubKeyPeerId.toB58String()).not.to.equal(messageKey.toB58String())
    expect(pubKeyPeerId.toB58String()).to.equal(testAccount.id)
    expect(publishedMessage.from).to.equal(idA.id)
    expect(messageKey.toB58String()).to.equal(idA.id)
    expect(publishedMessageDataValue).to.equal(ipfsRef)

    // Verify the signature
    await ipns.validate(pubKeyPeerId._pubKey, publishedMessageData)
  })
})
github ipfs / js-ipfs / test / core / circuit-relay.spec.js View on Github external
])

      relayNode = res[0].ipfsd

      nodeAAddr = res[1].addrs[0]
      nodeA = res[1].ipfsd.api

      nodeBAddr = res[2].addrs[0]

      nodeB = res[2].ipfsd.api
      nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}`

      // ensure we have an address string
      expect(nodeAAddr).to.be.a('string')
      expect(nodeBAddr).to.be.a('string')
      expect(nodeBCircuitAddr).to.be.a('string')

      await relayNode.api.swarm.connect(nodeAAddr)
      await relayNode.api.swarm.connect(nodeBAddr)
      await new Promise(resolve => setTimeout(resolve, 1000))
      await nodeA.swarm.connect(nodeBCircuitAddr)
    })
github ipfs / js-ipfs-http-client / test / sub-modules.spec.js View on Github external
it('swarm', () => {
    const swarm = require('../src/swarm')()

    expect(swarm.peers).to.be.a('function')
    expect(swarm.connect).to.be.a('function')
    expect(swarm.disconnect).to.be.a('function')
    expect(swarm.addrs).to.be.a('function')
    expect(swarm.localAddrs).to.be.a('function')
  })
github ipfs / js-ipfs / test / core / name.spec.js View on Github external
it('should error to publish if _putRecordToRouting receives an invalid peer id', function () {
      return expect(node._ipns.publisher._putRecordToRouting(undefined, undefined))
        .to.eventually.be.rejected()
        .with.property('code', 'ERR_INVALID_PEER_ID')
    })
github ipfs / js-ipfs / test / cli / dns.js View on Github external
it('resolve subdomain _dnslink.docs.ipfs.io dns', async function () {
    this.timeout(60 * 1000)

    const res = await ipfs('dns _dnslink.docs.ipfs.io')
    expect(res.substr(0, 6)).to.eql('/ipfs/')
  })
}))
github ipfs / js-ipfs / test / core / dag.spec.js View on Github external
ipfs.dag.get('INVALID CID', (err) => {
        expect(err).to.exist()
        expect(err.code).to.equal('ERR_INVALID_CID')
        done()
      })
    })
github ipfs / js-ipfs / test / http-api / inject / object.js View on Github external
Hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V',
            Size: 8
          }],
          Size: 68
        }

        const payload = await streamToPromise(form)
        const res = await api.inject({
          method: 'POST',
          url: '/api/v0/object/put',
          headers,
          payload
        })

        expect(res.statusCode).to.equal(200)
        expect(res.result).to.eql(expectedResult)
      })
github ipfs / js-ipfs-http-client / test / constructor.spec.js View on Github external
async function clientWorks (client) {
  const id = await client.id()

  expect(id).to.have.a.property('id')
  expect(id).to.have.a.property('publicKey')
}