Skip to content

Commit

Permalink
fix: getCode removed from RPC 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Aug 29, 2022
1 parent 2c92f79 commit 744a988
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 57 deletions.
5 changes: 0 additions & 5 deletions __tests__/defaultProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ describe('defaultProvider', () => {
return expect(block).toHaveProperty('block_number');
});

test('getCode() -> { bytecode }', async () => {
const code = await testProvider.getCode(exampleContractAddress);
return expect(Array.isArray(code.bytecode)).toBe(true);
});

describe('getStorageAt', () => {
test('with "key" type of number', () => {
return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
Expand Down
9 changes: 8 additions & 1 deletion __tests__/sequencerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
describeIfSequencer('SequencerProvider', () => {
let provider: SequencerProvider;
let customSequencerProvider: Provider;
let exampleContractAddress: string;

beforeAll(async () => {
provider = getTestProvider() as SequencerProvider;
Expand All @@ -27,11 +28,12 @@ describeIfSequencer('SequencerProvider', () => {
let exampleTransactionHash: string;

beforeAll(async () => {
const { transaction_hash } = await provider.deployContract({
const { transaction_hash, contract_address } = await provider.deployContract({
contract: compiledErc20,
});
await provider.waitForTransaction(transaction_hash);
exampleTransactionHash = transaction_hash;
exampleContractAddress = contract_address;
});

test('getTransactionStatus()', async () => {
Expand All @@ -44,6 +46,11 @@ describeIfSequencer('SequencerProvider', () => {
expect(transactionTrace).toHaveProperty('signature');
});

test('getCode() -> { bytecode }', async () => {
const code = await provider.getCode(exampleContractAddress);
return expect(Array.isArray(code.bytecode)).toBe(true);
});

describeIfNotDevnet('which are not available on devnet', () => {
test('getContractAddresses()', async () => {
const { GpsStatementVerifier, Starknet } = await provider.getContractAddresses();
Expand Down
8 changes: 0 additions & 8 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
DeployContractResponse,
EstimateFeeResponse,
GetBlockResponse,
GetCodeResponse,
GetTransactionReceiptResponse,
GetTransactionResponse,
Invocation,
Expand Down Expand Up @@ -104,13 +103,6 @@ export class Provider implements ProviderInterface {
return this.provider.declareContract(payload);
}

public async getCode(
contractAddress: string,
blockIdentifier?: BlockIdentifier
): Promise<GetCodeResponse> {
return this.provider.getCode(contractAddress, blockIdentifier);
}

public async waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void> {
return this.provider.waitForTransaction(txHash, retryInterval);
}
Expand Down
6 changes: 0 additions & 6 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
DeployContractResponse,
EstimateFeeResponse,
GetBlockResponse,
GetCodeResponse,
GetTransactionReceiptResponse,
GetTransactionResponse,
Invocation,
Expand Down Expand Up @@ -43,11 +42,6 @@ export abstract class ProviderInterface {
*/
public abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;

public abstract getCode(
contractAddress: string,
blockIdentifier?: BlockIdentifier
): Promise<GetCodeResponse>;

/**
* Gets the contract class of the deployed contract.
*
Expand Down
11 changes: 0 additions & 11 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,6 @@ export class RpcProvider implements ProviderInterface {
return this.responseParser.parseCallContractResponse(result);
}

public async getCode(
contractAddress: string,
_blockIdentifier?: BlockIdentifier
): Promise<RPC.GetCodeResponse> {
// deprecated method, please wait for an update of starknet.js

const result = await this.fetchEndpoint('starknet_getCode', [contractAddress]);

return this.responseParser.parseGetCodeResponse(result);
}

public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
let onchain = false;
let retries = 100;
Expand Down
4 changes: 1 addition & 3 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ export class SequencerProvider implements ProviderInterface {
contractAddress: string,
blockIdentifier: BlockIdentifier = 'pending'
): Promise<Sequencer.GetCodeResponse> {
return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier }).then(
this.responseParser.parseGetCodeResponse
);
return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier });
}

public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
Expand Down
10 changes: 0 additions & 10 deletions src/types/api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ export namespace RPC {
transactions: string[];
}; */

export type GetCodeResponse = {
bytecode: string[];
abi: string;
};

export type GetStorageAtResponse = string;

export type GetTransactionReceiptResponse = {
Expand Down Expand Up @@ -192,11 +187,6 @@ export namespace RPC {
REQUEST: any[];
RESPONSE: GetTransactionCountResponse;
};
starknet_getCode: {
QUERY: never;
REQUEST: any[];
RESPONSE: GetCodeResponse;
};
starknet_call: {
QUERY: never;
REQUEST: any[];
Expand Down
5 changes: 0 additions & 5 deletions src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ export interface GetBlockResponse {
transactions: Array<string>;
}

export interface GetCodeResponse {
bytecode: string[];
// abi: string; // is not consistent between rpc and sequencer (is it?), therefore not included in the provider interface
}

export type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;

export interface CommonTransactionResponse {
Expand Down
4 changes: 0 additions & 4 deletions src/utils/responseParser/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ export class RPCResponseParser extends ResponseParser {
};
}

public parseGetCodeResponse(res: RPC.GetCodeResponse): RPC.GetCodeResponse {
return res;
}

public parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse {
return {
overall_fee: toBN(res.overall_fee),
Expand Down
4 changes: 0 additions & 4 deletions src/utils/responseParser/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ export class SequencerAPIResponseParser extends ResponseParser {
};
}

public parseGetCodeResponse(res: Sequencer.GetCodeResponse): Sequencer.GetCodeResponse {
return res;
}

public parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse {
if ('overall_fee' in res) {
let gasInfo = {};
Expand Down

0 comments on commit 744a988

Please sign in to comment.