Skip to content

Commit

Permalink
fix(fetchEndpoint): error handling and test case fix
Browse files Browse the repository at this point in the history
  • Loading branch information
1swaraj committed Jun 17, 2022
1 parent de3e004 commit 629479f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions __tests__/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('defaultProvider', () => {
if (transaction.status !== 'REJECTED') {
exampleBlockHash = transaction.block_hash;
exampleBlockNumber = transaction.block_number;
console.log(exampleBlockNumber);
}
});

Expand Down
7 changes: 2 additions & 5 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,15 @@ export class Account extends Provider implements AccountInterface {
*/
public async verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean> {
try {
const response = await this.callContract({
await this.callContract({
contractAddress: this.address,
entrypoint: 'is_valid_signature',
calldata: compileCalldata({
hash: toBN(hash).toString(),
signature: signature.map((x) => toBN(x).toString()),
}),
});
if (response.result) {
return true;
}
return false;
return true;
} catch {
return false;
}
Expand Down
10 changes: 9 additions & 1 deletion src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ export class Provider implements ProviderInterface {
body: stringify(request),
headers,
})
.then((res) => res.text())
.then((res) => {
if (res.status !== 200) {
throw Error(res.statusText);
}
return res.text();
})
.then((res) => {
if (endpoint === 'estimate_fee') {
return parse(res, (_, v) => {
Expand All @@ -170,6 +175,9 @@ export class Provider implements ProviderInterface {
});
}
return parse(res) as Endpoints[T]['RESPONSE'];
})
.catch((err) => {
throw Error(`Could not ${method} from endpoint: ${url} ${err.message}`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/provider/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdent
if (blockIdentifier === 'pending') {
return { type: 'BLOCK_NUMBER', data: 'pending' };
}
if (typeof blockIdentifier === 'number') {
if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
}
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
Expand Down

0 comments on commit 629479f

Please sign in to comment.