Got client to connect to service

This commit is contained in:
Chris Troutner
2021-07-17 19:14:11 -07:00
parent c3bfbbb6e1
commit 06cdc03287
5 changed files with 98 additions and 1 deletions
+11
View File
@@ -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`
+20
View File
@@ -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()
+63
View File
@@ -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
+3
View File
@@ -0,0 +1,3 @@
{
"uutAddr": "/ip4/127.0.0.1/tcp/5668/p2p/QmZSyLnRQWMBknVNjUroLQnrcmDnUVAUU4pMQ2LGhh6b9v"
}