Skip to content

Commit

Permalink
Merge pull request #100 from Bitcoin-com/stage
Browse files Browse the repository at this point in the history
v1.10.4
  • Loading branch information
cgcardona authored Nov 7, 2018
2 parents 51a4405 + 247d86b commit de867a0
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 9 deletions.
9 changes: 5 additions & 4 deletions dist/routes/v2/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ router.get("/getBlockchainInfo", config.blockchainRateLimit4, function (req, res
return [4 /*yield*/, BitboxHTTP(requestConfig)];
case 2:
response = _a.sent();
res.json(response.data.result);
return [3 /*break*/, 4];
case 3:
error_3 = _a.sent();
res.status(500).send(error_3.response.data.error);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
return [2 /*return*/, res.status(500).send(error_3.response.data.error)];
case 4:
res.json(response.data.result);
res.end();
return [2 /*return*/];
}
});
}); });
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "rest.bitcoin.com",
"version": "1.10.3",
"version": "1.10.4",
"description": "REST API for Bitcoin.com's Cloud",
"author": "Gabriel Cardona @ Bitcoin.com",
"license": "MIT",
"scripts": {
"start": "node ./dist/app.js",
"build": "node ./node_modules/gulp/bin/gulp.js build && ./node_modules/typescript/bin/tsc",
"dev": "nodemon ./dist/app.js",
"test:panda": "NETWORK=local RPC_BASEURL=http://localhost:18332/ RPC_USERNAME=regtest RPC_PASSWORD=regtest npm test",
"test": "npm run build && nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v1/",
"test-v1": "nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v1/",
"test-v2": "nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v2/",
"test-v2:blockchain": "nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v2/blockchain",
"test-all": "TEST=integration nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v1/ test/v2/",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coverage:report": "nyc --reporter=html mocha --require babel-core/register --timeout 15000"
Expand Down Expand Up @@ -63,6 +63,7 @@
"node-mocks-http": "^1.7.0",
"nodemon": "^1.18.1",
"nyc": "^11.6.0",
"pandacash-cli": "^0.4.0",
"prettier": "^1.14.2",
"sinon": "^6.3.4",
"typescript": "^3.1.4"
Expand Down
10 changes: 7 additions & 3 deletions src/routes/v2/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ router.get(
requestConfig.data.method = "getblockchaininfo"
requestConfig.data.params = []

let response;

try {
const response = await BitboxHTTP(requestConfig)
res.json(response.data.result)
response = await BitboxHTTP(requestConfig)
} catch (error) {
res.status(500).send(error.response.data.error)
return res.status(500).send(error.response.data.error)
}

res.json(response.data.result);
res.end();
}
)

Expand Down
75 changes: 75 additions & 0 deletions test/v2/blockchain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict"

//const chai = require("chai");
const assert = require("assert")
const httpMocks = require("node-mocks-http")
const panda = require("./helpers/panda");
process.env.RPC_BASEURL="http://localhost:48332/";
const blockchainRoute = require("../../dist/routes/v2/blockchain")

describe("#BlockchainRouter", () => {
// local node will be started in regtest mode on the port 48332
before(panda.runLocalNode);
after(() => {
// otherwise the panda will run forever
process.exit();
});

describe("#root", () => {
it("should return 'blockchain' for GET /", () => {
const mockRequest = httpMocks.createRequest({
method: "GET",
url: "/"
})

const mockResponse = httpMocks.createResponse()

blockchainRoute(mockRequest, mockResponse)

const actualResponseBody = mockResponse._getData()
const expectedResponseBody = {
status: "blockchain"
}

assert.deepEqual(JSON.parse(actualResponseBody), expectedResponseBody)
})
})

describe("#BlockchainGetBlockchainInfo", () => {
it("should GET /getBlockchainInfo ", (done) => {
const mockRequest = httpMocks.createRequest({
method: "GET",
url: "/getBlockchainInfo"
})

const mockResponse = httpMocks.createResponse({
eventEmitter: require("events").EventEmitter
})

blockchainRoute(mockRequest, mockResponse)

mockResponse.on("end", () => {
const actualResponseBody = Object.keys(
JSON.parse(mockResponse._getData())
)

assert.deepEqual(actualResponseBody, [
"chain",
"blocks",
"headers",
"bestblockhash",
"difficulty",
"mediantime",
"verificationprogress",
"chainwork",
"pruned",
"softforks",
"bip9_softforks",
"pruneheight"
]);

return done();
});
})
})
})
26 changes: 26 additions & 0 deletions test/v2/helpers/panda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict"

/**
* Read more about panda here: https://panda-suite.github.io/
*/
const panda = require("pandacash-cli")

const runLocalNode = done => {
const server = panda.server({
// always the same mnemonic
// mnemonic: "cigar magnet ocean purchase travel damp snack alone theme budget wagon wrong",
seedAccounts: true,
enableLogs: false,
debug: false
})

server.listen(48332, (err, pandaCashCore) => {
if (err) return console.error(err)

done()
})
}

module.exports = {
runLocalNode
}

0 comments on commit de867a0

Please sign in to comment.