From b8a8389d64c3f845be8302054cbc579b4b3d3fb9 Mon Sep 17 00:00:00 2001 From: Antun Badurina Date: Fri, 3 Jun 2022 13:04:47 +0200 Subject: [PATCH 1/2] fix: change getStorageAt key param type to BigNumberish --- src/provider/default.ts | 2 +- src/provider/interface.ts | 2 +- src/types/api.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/provider/default.ts b/src/provider/default.ts index eeee214ef..774e5b003 100644 --- a/src/provider/default.ts +++ b/src/provider/default.ts @@ -247,7 +247,7 @@ export class Provider implements ProviderInterface { */ public async getStorageAt( contractAddress: string, - key: number, + key: BigNumberish, blockIdentifier: BlockIdentifier = 'pending' ): Promise { return this.fetchEndpoint('get_storage_at', { blockIdentifier, contractAddress, key }); diff --git a/src/provider/interface.ts b/src/provider/interface.ts index aca5ccf38..cbbee6af1 100644 --- a/src/provider/interface.ts +++ b/src/provider/interface.ts @@ -85,7 +85,7 @@ export abstract class ProviderInterface { */ public abstract getStorageAt( contractAddress: string, - key: number, + key: BigNumberish, blockIdentifier?: BlockIdentifier ): Promise; diff --git a/src/types/api.ts b/src/types/api.ts index 49a348656..52c1a3206 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -46,7 +46,7 @@ export type Endpoints = { get_storage_at: { QUERY: { contractAddress: string; - key: number; + key: BigNumberish; blockIdentifier: BlockIdentifier; }; REQUEST: never; From b8c60a9ab297b27cd86c82863220815626b3eb68 Mon Sep 17 00:00:00 2001 From: Antun Badurina Date: Fri, 3 Jun 2022 13:09:40 +0200 Subject: [PATCH 2/2] test: getStorage key param different types --- __tests__/provider.test.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/__tests__/provider.test.ts b/__tests__/provider.test.ts index f35dca229..35b650f36 100644 --- a/__tests__/provider.test.ts +++ b/__tests__/provider.test.ts @@ -1,4 +1,5 @@ import { defaultProvider, stark } from '../src'; +import { toBN } from '../src/utils/number'; import { compiledArgentAccount } from './fixtures'; const { compileCalldata } = stark; @@ -42,7 +43,7 @@ describe('defaultProvider', () => { ) ).resolves.not.toThrow(); }); - test('getStorageAt()', () => { + test('getStorageAt() with "key" type of number', () => { return expect( defaultProvider.getStorageAt( '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', @@ -51,6 +52,24 @@ describe('defaultProvider', () => { ) ).resolves.not.toThrow(); }); + test('getStorageAt() with "key" type of string', () => { + return expect( + defaultProvider.getStorageAt( + '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', + '0', + 36663 + ) + ).resolves.not.toThrow(); + }); + test('getStorageAt() with "key" type of BN', () => { + return expect( + defaultProvider.getStorageAt( + '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', + toBN('0x0'), + 36663 + ) + ).resolves.not.toThrow(); + }); test('getStorageAt(blockHash=undefined, blockNumber=null)', () => { return expect( defaultProvider.getStorageAt(