Skip to content

Commit

Permalink
fix: update api typings
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkelawala committed Jun 15, 2022
1 parent b03500e commit 44796af
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 20 deletions.
47 changes: 35 additions & 12 deletions __tests__/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,43 @@ describe('defaultProvider', () => {
)
).resolves.not.toThrow();
});
test('getTransaction()', async () => {
return expect(
defaultProvider.getTransaction(
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
)
).resolves.not.toThrow();

test('getTransaction() - successful transaction', async () => {
const transaction = await defaultProvider.getTransaction(
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
);

expect(transaction).not.toHaveProperty('transaction_failure_reason');

expect(transaction.transaction).toHaveProperty('transaction_hash');

return expect(transaction.status).not.toEqual('REJECTED');
});

test('getTransactionReceipt', async () => {
return expect(
defaultProvider.getTransactionReceipt(
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
)
).resolves.not.toThrow();
test('getTransaction() - failed transaction', async () => {
const transaction = await defaultProvider.getTransaction(
'0x698e60db2bae3ef8d5fafda10ff83b6ba634351aa1f4fcf8455ec0cffa738d9'
);

expect(transaction).toHaveProperty('transaction_failure_reason');

return expect(transaction.status).toEqual('REJECTED');
});

test('getTransactionReceipt() - successful transaction', async () => {
const transactionReceipt = await defaultProvider.getTransactionReceipt(
'0x18c49389193b40e178dfc9f2f595a7c79a7a55639e9951d956329f2ce6cfd4f'
);

return expect(transactionReceipt).toHaveProperty('actual_fee');
});

test('getTransactionReceipt() - failed transaction', async () => {
const transactionReceipt = await defaultProvider.getTransactionReceipt(
'0x698e60db2bae3ef8d5fafda10ff83b6ba634351aa1f4fcf8455ec0cffa738d9'
);

return expect(transactionReceipt).not.toHaveProperty('actual_fee');
});

test('callContract()', () => {
Expand Down
43 changes: 35 additions & 8 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export type ExecutionResources = {
bitwise_builtin: number;
output_builtin: number;
ecdsa_builtin: number;
ec_op_builtin: number;
ec_op_builtin?: number;
};
n_memory_holes: number;
};
Expand Down Expand Up @@ -184,8 +184,9 @@ export type GetBlockResponse = {
transaction_index: number;
};
};
previous_block_hash: string;
parent_block_hash: string;
status: Status;
gas_price: string;
};

export type GetCodeResponse = {
Expand All @@ -195,9 +196,8 @@ export type GetCodeResponse = {

export type GetTransactionStatusResponse = {
tx_status: Status;
block_hash: string;
block_hash?: string;
tx_failure_reason?: {
tx_id: number;
code: string;
error_message: string;
};
Expand All @@ -211,40 +211,67 @@ export type GetTransactionTraceResponse = {
selector: string;
calldata: RawArgs;
result: Array<any>;
execution_resources: any;
execution_resources: ExecutionResources;
internal_call: Array<any>;
events: Array<any>;
messages: Array<any>;
};
signature: Signature;
};

export type GetTransactionResponse = {
export type SuccessfulTransactionResponse = {
status: Status;
transaction: Transaction;
block_hash: string;
block_number: BlockNumber;
transaction_index: number;
transaction_hash: string;
};

export type FailedTransactionResponse = {
status: 'REJECTED';
transaction_failure_reason: {
code: string;
error_message: string;
};
transaction: Transaction;
};

export type GetTransactionResponse = SuccessfulTransactionResponse | FailedTransactionResponse;

export type AddTransactionResponse = {
code: TransactionStatus;
transaction_hash: string;
address?: string;
class_hash?: string;
};

export type TransactionReceiptResponse = {
export type SuccessfulTransactionReceiptResponse = {
status: Status;
transaction_hash: string;
transaction_index: number;
block_hash: string;
block_number: BlockNumber;
l2_to_l1_messages: string[];
events: string[];
actual_fee: string;
execution_resources: ExecutionResources;
};

export type FailedTransactionReceiptResponse = {
status: 'REJECTED';
transaction_failure_reason: {
code: string;
error_message: string;
};
transaction_hash: string;
l2_to_l1_messages: string[];
events: string[];
};

export type TransactionReceiptResponse =
| SuccessfulTransactionReceiptResponse
| FailedTransactionReceiptResponse;

export type EstimateFeeResponse = {
amount: BN;
unit: string;
Expand Down

0 comments on commit 44796af

Please sign in to comment.