Skip to content

Commit

Permalink
fix(cucumber): handles listHeaders response correctly (#4551)
Browse files Browse the repository at this point in the history
Description
---
- Fixes how listHeaders GRPC response is handled (since #4515)

Motivation and Context
---
#4515 returns the header in a nested struct, this PR updates the js code to handle that correctly.

How Has This Been Tested?
---
`Pruned node should prune outputs` passes
  • Loading branch information
sdbondi authored Aug 29, 2022
1 parent 080bccf commit 3958dde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
10 changes: 5 additions & 5 deletions integration_tests/features/support/node_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,18 @@ Then(
5 * height /* 5 seconds per block */
);
const currTip = await client.getTipHeader();
let currTipHeaderHeight = parseInt(currTip.header.height);
let currTipHeaderHeight = parseInt(currTip.height);
console.log(
`${name} is at tip ${currTipHeaderHeight} (${currTip.header.hash.toString(
`${name} is at tip ${currTipHeaderHeight} (${currTip.hash.toString(
"hex"
)})`
);
expect(currTipHeaderHeight).to.equal(height);
if (!tipHash) {
tipHash = currTip.header.hash.toString("hex");
tipHash = currTip.hash.toString("hex");
console.log(`Node ${name} is at tip: ${tipHash}`);
} else {
const currTipHash = currTip.header.hash.toString("hex");
const currTipHash = currTip.hash.toString("hex");
console.log(
`Node ${name} is at tip: ${currTipHash} (should be ${tipHash})`
);
Expand Down Expand Up @@ -506,7 +506,7 @@ Then(/node (.*) is at tip (.*)/, async function (node, name) {
const existingHeader = this.headers[name];
expect(existingHeader).to.not.be.null;
expect(existingHeader.header.hash.toString("hex")).to.equal(
header.header.hash.toString("hex")
header.hash.toString("hex")
);
});

Expand Down
26 changes: 10 additions & 16 deletions integration_tests/helpers/baseNodeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ class BaseNodeClient {
}

getHeaderAt(height) {
return this.client
.listHeaders()
.sendMessage({ from_height: height, num_headers: 1 })
.then((header) => {
console.log("Header:", header);
return header;
});
return this.getHeaders(height, 1).then((header) =>
header && header.length ? header[0].header : null
);
}

getNetworkDifficulties(tip, start, end) {
Expand All @@ -69,21 +65,19 @@ class BaseNodeClient {
}

getTipHeader() {
return this.client
.listHeaders()
.sendMessage({ from_height: 0, num_headers: 1 })
.then((headers) => {
const header = headers[0];
return Object.assign(header, {
height: +header.height,
});
return this.getHeaders(0, 1).then((headers) => {
const header = headers[0].header;
return Object.assign(header, {
height: +header.height,
});
});
}

async getHeaders(from_height, num_headers, sorting = 0) {
return await this.client
.listHeaders()
.sendMessage({ from_height, num_headers, sorting });
.sendMessage({ from_height, num_headers, sorting })
.then((resp) => resp.map((r) => r.header));
}

getTipHeight() {
Expand Down

0 comments on commit 3958dde

Please sign in to comment.