Fixed getBlock for blockhashes with a leading 0 (#629).
This commit is contained in:
parent
3c864de612
commit
12cfc59965
@ -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
|
||||
};
|
||||
|
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user