From 06cdc0328750e789702e247a3935b4f033148993 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 17 Jul 2021 19:14:11 -0700 Subject: [PATCH] Got client to connect to service --- config/env/common.js | 2 +- test/e2e/manual/client/README.md | 11 +++++ test/e2e/manual/client/client.e2e.js | 20 ++++++++ test/e2e/manual/client/lib/test-utils.js | 63 ++++++++++++++++++++++++ test/e2e/manual/client/test-data.json | 3 ++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/e2e/manual/client/README.md create mode 100644 test/e2e/manual/client/client.e2e.js create mode 100644 test/e2e/manual/client/lib/test-utils.js create mode 100644 test/e2e/manual/client/test-data.json diff --git a/config/env/common.js b/config/env/common.js index 0bdc199..891dc94 100644 --- a/config/env/common.js +++ b/config/env/common.js @@ -43,7 +43,7 @@ module.exports = { isCircuitRelay: process.env.ENABLE_CIRCUIT_RELAY ? true : false, // Information passed to other IPFS peers about this node. - apiInfo: 'https://ipfs-service-provider.fullstack.cash/', + apiInfo: 'https://ipfs-bch-wallet-service.fullstack.cash/', ipfsCoordName: ipfsCoordName, diff --git a/test/e2e/manual/client/README.md b/test/e2e/manual/client/README.md new file mode 100644 index 0000000..e5b7980 --- /dev/null +++ b/test/e2e/manual/client/README.md @@ -0,0 +1,11 @@ +# Client Simulation E2E Test + +The file in this directory simulates a client using JSON RPC over IPFS. It starts a new IPFS node that connects to the ipfs-bch-wallet-service and exercises each JSON RPC endpoint. + +## Instructions + +Execute these steps in order to run the test: + +1. Run your local copy of ipfs-bch-wallet-service service provider. +2. Update the [test-data.json](./test-data.json) file with the IPFS ID of the ipfs-bch-wallet-service. +3. In another terminal, run the client simulation with `node client.e2e.js` diff --git a/test/e2e/manual/client/client.e2e.js b/test/e2e/manual/client/client.e2e.js new file mode 100644 index 0000000..a01e55a --- /dev/null +++ b/test/e2e/manual/client/client.e2e.js @@ -0,0 +1,20 @@ +/* + An end-to-end (e2e) test simulating a client connecting over IPFS and + that exercises each JSON RPC endpoint. +*/ + +const TestUtils = require('./lib/test-utils') +const testUtils = new TestUtils() + +const testData = require('./test-data.json') + +async function startTest () { + try { + await testUtils.startIpfs() + + await testUtils.connectToUut(testData.uutAddr) + } catch (err) { + console.error('Error in startTest(): ', err) + } +} +startTest() diff --git a/test/e2e/manual/client/lib/test-utils.js b/test/e2e/manual/client/lib/test-utils.js new file mode 100644 index 0000000..c17cf5b --- /dev/null +++ b/test/e2e/manual/client/lib/test-utils.js @@ -0,0 +1,63 @@ +/* + A class library of test utility functions. +*/ + +const BCHJS = require('@psf/bch-js') +const IpfsCoord = require('ipfs-coord') +const IPFS = require('ipfs') + +class TestUtils { + constructor (localConfig = {}) { + this.bchjs = new BCHJS() + } + + async startIpfs () { + try { + // Start the IPFS node. + this.ipfs = await IPFS.create() + await this.ipfs.config.profiles.apply('server') + + // Start ipfs-coord. + this.ipfsCoord = new IpfsCoord({ + ipfs: this.ipfs, + type: 'node.js', + // type: 'browser', + bchjs: this.bchjs, + privateLog: console.log, // Default to console.log + isCircuitRelay: false, + apiInfo: 'none', + announceJsonLd: announceJsonLd + }) + await this.ipfsCoord.ipfs.start() + await this.ipfsCoord.isReady() + } catch (err) { + console.error('Error in startIpfs().') + throw err + } + } + + async connectToUut (addr) { + try { + await this.ipfs.swarm.connect(addr) + console.log(`Connected to IPFS node ${addr}`) + } catch (err) { + console.error('Error in connectToUut()') + throw err + } + } +} + +const announceJsonLd = { + '@context': 'https://schema.org/', + '@type': 'WebAPI', + name: 'e2e-test-client', + description: 'A test client runing e2e tests on ipfs-bch-wallet-service.', + documentation: 'https://ipfs-bch-wallet-service.fullstack.cash/', + provider: { + '@type': 'Organization', + name: 'Permissionless Software Foundation', + url: 'https://PSFoundation.cash' + } +} + +module.exports = TestUtils diff --git a/test/e2e/manual/client/test-data.json b/test/e2e/manual/client/test-data.json new file mode 100644 index 0000000..a83e489 --- /dev/null +++ b/test/e2e/manual/client/test-data.json @@ -0,0 +1,3 @@ +{ + "uutAddr": "/ip4/127.0.0.1/tcp/5668/p2p/QmZSyLnRQWMBknVNjUroLQnrcmDnUVAUU4pMQ2LGhh6b9v" +}