diff --git a/.gitignore b/.gitignore index 1c5bf6c..f25038b 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ database/ system-user-*.json orbitdb ipfsdata +.ipfsdata ipfs-service-provider.sh start-bch-wallet-service.sh diff --git a/package.json b/package.json index 64edc71..bef53ee 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "bcryptjs": "^2.4.3", "glob": "^7.1.6", "ipfs": "^0.54.4", - "ipfs-coord": "^4.0.1", + "ipfs-coord": "^5.0.0", "jsonrpc-lite": "^2.2.0", "jsonwebtoken": "^8.5.1", "jwt-bch-lib": "^1.3.0", diff --git a/src/adapters/ipfs/ipfs-coord.js b/src/adapters/ipfs/ipfs-coord.js index 0c46e24..11e7b6c 100644 --- a/src/adapters/ipfs/ipfs-coord.js +++ b/src/adapters/ipfs/ipfs-coord.js @@ -58,7 +58,11 @@ class IpfsCoordAdapter { if (!process.env.E2ETEST) { // Wait for the ipfs-coord library to signal that it is ready. await this.ipfsCoord.ipfs.start() - await this.ipfsCoord.isReady() + + // some ipfs-coord versions do not have this function + if (this.ipfsCoord.isReady) { + await this.ipfsCoord.isReady() + } } // Signal that this adapter is ready. diff --git a/test/e2e/manual/consumer/consumer.e2e.js b/test/e2e/manual/consumer/consumer.e2e.js index b29997f..f4945d2 100644 --- a/test/e2e/manual/consumer/consumer.e2e.js +++ b/test/e2e/manual/consumer/consumer.e2e.js @@ -20,9 +20,9 @@ async function startTest () { await testUtils.testTransaction(testData.uutId) - // ToDo: - // testTransactions() - // testUtxos() + await testUtils.testTransactions(testData.uutId) + + await testUtils.testUtxos(testData.uutId) console.log('E2E TEST: Tests completed successfully!') process.exit() diff --git a/test/e2e/manual/consumer/lib/test-utils.js b/test/e2e/manual/consumer/lib/test-utils.js index c208851..e10782d 100644 --- a/test/e2e/manual/consumer/lib/test-utils.js +++ b/test/e2e/manual/consumer/lib/test-utils.js @@ -99,7 +99,10 @@ class TestUtils { announceJsonLd: announceJsonLd }) await this.ipfsCoord.ipfs.start() - await this.ipfsCoord.isReady() + // some ipfs-coord versions do not have this function + if (this.ipfsCoord.isReady) { + await this.ipfsCoord.isReady() + } // Wait to let ipfs-coord connect to subnet peers. await this.bchjs.Util.sleep(30000) @@ -195,6 +198,69 @@ class TestUtils { } } + // Get the info a on transaction over JSON RPC. + async testTransactions (ipfsId) { + try { + // Generate the JSON RPC command + const id = uid() + const cmd = jsonrpc.request(id, 'bch', { + endpoint: 'transactions', + addresses: ['bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'] + }) + const cmdStr = JSON.stringify(cmd) + + // console.log(`Publishing message to ${ipfsId}`) + + console.log('E2E TEST: Sending Transactions command...') + const result = await this.sendRPC(ipfsId, cmdStr) + // console.log('result: ', result) + + if (result.result.value.status && Array.isArray(result.result.value.transactions)) { + console.log('E2E TEST: transactions test passed.') + return true + } else { + console.log('E2E TEST: transactions test failed.') + this.failTest() + } + } catch (err) { + console.error('Error in testTransactions()') + throw err + } + } + + // Get the utxos for a BCH address over JSON RPC. + async testUtxos (ipfsId) { + try { + // Generate the JSON RPC command + const id = uid() + const cmd = jsonrpc.request(id, 'bch', { + endpoint: 'utxos', + address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj' + }) + const cmdStr = JSON.stringify(cmd) + + // console.log(`Publishing message to ${ipfsId}`) + + console.log('E2E TEST: Sending Utxos command...') + const result = await this.sendRPC(ipfsId, cmdStr) + // console.log('result', result.result.value) + + const bchUtxos = result.result.value[0].bchUtxos + const slpUtxos = result.result.value[0].slpUtxos + + if (result.result.value && bchUtxos && slpUtxos) { + console.log('E2E TEST: utxos test passed.') + return true + } else { + console.log('E2E TEST: utxos test failed.') + this.failTest() + } + } catch (err) { + console.error('Error in testUtxos()') + throw err + } + } + failTest () { console.log('Exiting test program.') process.exit() diff --git a/test/e2e/manual/consumer/test-data.json b/test/e2e/manual/consumer/test-data.json index cd88e01..9c237f0 100644 --- a/test/e2e/manual/consumer/test-data.json +++ b/test/e2e/manual/consumer/test-data.json @@ -1,4 +1,4 @@ { - "uutAddr": "/ip4/127.0.0.1/tcp/5668/p2p/QmZSyLnRQWMBknVNjUroLQnrcmDnUVAUU4pMQ2LGhh6b9v", - "uutId": "QmZSyLnRQWMBknVNjUroLQnrcmDnUVAUU4pMQ2LGhh6b9v" + "uutAddr": "/ip4/192.168.43.115/tcp/5668/p2p/QmVBWvFxao7smhRjUUh1q8rNAEwMqbg4X3dqsQDMSjUpmx", + "uutId": "QmfUjMqUeXSCzNkFGrzvf79yvV62dtjsnwtBSYKx3wegXw" }