Skip to content

Commit

Permalink
Fixed getBlock for blockhashes with a leading 0 (#629).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Oct 16, 2019
1 parent 3c864de commit 12cfc59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,19 @@ export class BaseProvider extends Provider {
}

_getBlock(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>, includeTransactions?: boolean): Promise<Block | BlockWithTransactions> {
if (blockHashOrBlockTag instanceof Promise) {
return blockHashOrBlockTag.then((b) => this._getBlock(b, includeTransactions));
}

return this.ready.then(() => {
return this._getBlockTag(blockHashOrBlockTag).then((blockHashOrBlockTag) => {
let blockHashOrBlockTagPromise: Promise<string | BlockTag> = null;
if (isHexString(blockHashOrBlockTag, 32)) {
blockHashOrBlockTagPromise = Promise.resolve(blockHashOrBlockTag);
} else {
blockHashOrBlockTagPromise = this._getBlockTag(blockHashOrBlockTag);
}

return blockHashOrBlockTagPromise.then((blockHashOrBlockTag) => {
let params: { [key: string]: any } = {
includeTransactions: !!includeTransactions
};
Expand Down
13 changes: 13 additions & 0 deletions packages/tests/src.ts/test-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,16 @@ describe("Test Basic Authentication", function() {
}, "throws an exception for insecure connections");
})
});

describe("Test #629", function() {
it("Fetches a blockhash beginning with a 0 nibble", function() {
const provider = new ethers.providers.InfuraProvider('goerli');
return provider.getBlock('0x0f305466552efa183a0de26b6fda26d55a872dbc02aca8b5852cc2a361ce9ee4').then((block) => {
assert.equal(block.parentHash, "0x6723e880e01c15c5ac894abcae0f5b55ea809a31eaf5618998928f7d9cbc5118");
assert.equal(block.number, 1479831);
assert.equal(block.transactions.length, 5);
}, (error) => {
assert.ok(false, "Failed to get block");
});
});
});

0 comments on commit 12cfc59

Please sign in to comment.