2
0
mirror of synced 2025-02-23 11:38:42 +00:00

Fixed getBlock for blockhashes with a leading 0 (#629).

This commit is contained in:
Richard Moore 2019-10-17 00:53:25 +09:00
parent 3c864de612
commit 12cfc59965
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 25 additions and 1 deletions

View File

@ -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
};

View File

@ -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");
});
});
});