Skip to content

Commit

Permalink
feat(provider): fix and clean provider response and response parser, …
Browse files Browse the repository at this point in the history
…removed seqeuncer api
  • Loading branch information
tabaktoni committed Dec 13, 2023
1 parent 2d0c322 commit 7ecb069
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 775 deletions.
16 changes: 7 additions & 9 deletions __tests__/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
BigNumberish,
Contract,
ContractFactory,
GetTransactionReceiptResponse,
ParsedEvents,
RawArgs,
SuccessfulTransactionReceiptResponse,
json,
stark,
} from '../src';
Expand Down Expand Up @@ -720,7 +720,7 @@ describe('Complex interaction', () => {
test('invoke compiled data', async () => {
const result = await erc20Echo20Contract.iecho(CallData.compile(request));
const transaction = await provider.waitForTransaction(result.transaction_hash);
expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined();
});

// skip on live for performance
Expand All @@ -730,19 +730,19 @@ describe('Complex interaction', () => {

const result = await erc20Echo20Contract.iecho(calldata);
const transaction = await provider.waitForTransaction(result.transaction_hash);
expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined();

const result1 = await erc20Echo20Contract.iecho(...args);
const transaction1 = await provider.waitForTransaction(result1.transaction_hash);
expect((transaction1 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
expect((transaction1 as GetTransactionReceiptResponse).execution_status).toBeDefined();

const result2 = await erc20Echo20Contract.invoke('iecho', calldata);
const transaction2 = await provider.waitForTransaction(result2.transaction_hash);
expect((transaction2 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
expect((transaction2 as GetTransactionReceiptResponse).execution_status).toBeDefined();

const result3 = await erc20Echo20Contract.invoke('iecho', args);
const transaction3 = await provider.waitForTransaction(result3.transaction_hash);
expect((transaction3 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined();
expect((transaction3 as GetTransactionReceiptResponse).execution_status).toBeDefined();
});

describe('speedup live tests', () => {
Expand Down Expand Up @@ -795,9 +795,7 @@ describe('Complex interaction', () => {
{ formatResponse }
);
const transaction = await provider.waitForTransaction(result.transaction_hash);
expect(
(transaction as SuccessfulTransactionReceiptResponse).execution_status
).toBeDefined();
expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined();
});
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/defaultProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('defaultProvider', () => {
}),
})
.then((res) => {
expect(Array.isArray(res.result)).toBe(true);
expect(Array.isArray(res)).toBe(true);
})
).resolves.not.toThrow();
});
Expand Down
8 changes: 4 additions & 4 deletions src/contract/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ export class Contract implements ContractInterface {
},
blockIdentifier
)
.then((x) => {
.then((it) => {
if (!parseResponse) {
return x.result;
return it;
}
if (formatResponse) {
return this.callData.format(method, x.result, formatResponse);
return this.callData.format(method, it, formatResponse);
}
return this.callData.parse(method, x.result);
return this.callData.parse(method, it);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/provider/extensions/starknetId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class StarknetId {
address,
}),
});
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
const decimalDomain = hexDomain.map((element) => BigInt(element)).slice(1);

const stringDomain = useDecoded(decimalDomain);

Expand Down Expand Up @@ -72,7 +72,7 @@ export class StarknetId {
}),
});

return addressData.result[0];
return addressData[0];
} catch {
throw Error('Could not get address from stark name');
}
Expand Down
13 changes: 6 additions & 7 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ export class RpcProvider implements ProviderInterface {
}

public async getTransaction(txHash: BigNumberish) {
return this.channel
.getTransactionByHash(txHash)
.then(this.responseParser.parseGetTransactionResponse);
return this.channel.getTransactionByHash(txHash);
}

public async getTransactionByHash(txHash: BigNumberish) {
Expand Down Expand Up @@ -161,7 +159,9 @@ export class RpcProvider implements ProviderInterface {
options?: getSimulateTransactionOptions
) {
// can't be named simulateTransaction because of argument conflict with account
return this.channel.simulateTransaction(invocations, options);
return this.channel
.simulateTransaction(invocations, options)
.then(this.responseParser.parseSimulateTransactionResponse);
}

public async waitForTransaction(txHash: BigNumberish, options?: waitForTransactionOptions) {
Expand Down Expand Up @@ -340,9 +340,8 @@ export class RpcProvider implements ProviderInterface {
}

public async callContract(call: Call, blockIdentifier?: BlockIdentifier) {
return this.channel
.callContract(call, blockIdentifier)
.then(this.responseParser.parseCallContractResponse);
return this.channel.callContract(call, blockIdentifier);
// .then(this.responseParser.parseCallContractResponse);
}

/**
Expand Down
30 changes: 29 additions & 1 deletion src/types/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { EDataAvailabilityMode, ETransactionVersion, ResourceBounds } from './api';
import { BigNumberish, BlockIdentifier, V3TransactionDetails } from './lib';
import {
AllowArray,
BigNumberish,
BlockIdentifier,
Call,
DeclareContractPayload,
DeployAccountContractPayload,
TransactionType,
UniversalDeployerContractPayload,
V3TransactionDetails,
} from './lib';
import { DeclareTransactionReceiptResponse, EstimateFeeResponse } from './provider';

export interface EstimateFee extends EstimateFeeResponse {}
Expand Down Expand Up @@ -69,3 +79,21 @@ export enum SIMULATION_FLAG {
SKIP_VALIDATE = 'SKIP_VALIDATE',
SKIP_EXECUTE = 'SKIP_EXECUTE',
}

export type EstimateFeeAction =
| {
type: TransactionType.INVOKE;
payload: AllowArray<Call>;
}
| {
type: TransactionType.DECLARE;
payload: DeclareContractPayload;
}
| {
type: TransactionType.DEPLOY_ACCOUNT;
payload: DeployAccountContractPayload;
}
| {
type: TransactionType.DEPLOY;
payload: UniversalDeployerContractPayload;
};
5 changes: 2 additions & 3 deletions src/types/api/rpcspec_0_6/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import {
FELT,
FUNCTION_CALL,
MSG_FROM_L1,
PENDING_STATE_UPDATE,
RESULT_PAGE_REQUEST,
SIMULATION_FLAG,
SIMULATION_FLAG_FOR_ESTIMATE_FEE,
STATE_UPDATE,
STORAGE_KEY,
TXN_HASH,
} from './components';
Expand All @@ -33,6 +31,7 @@ import {
InvokedTransaction,
Nonce,
SimulateTransactionResponse,
StateUpdate,
Syncing,
TransactionReceipt,
TransactionStatus,
Expand Down Expand Up @@ -72,7 +71,7 @@ type ReadMethods = {
params: {
block_id: BLOCK_ID;
};
result: STATE_UPDATE | PENDING_STATE_UPDATE;
result: StateUpdate;
errors: Errors.BLOCK_NOT_FOUND;
};

Expand Down
7 changes: 5 additions & 2 deletions src/types/api/rpcspec_0_6/nonspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ import {
// response starknet_getClass
export type ContractClass = CONTRACT_CLASS | DEPRECATED_CONTRACT_CLASS;
// response starknet_simulateTransactions
export type SimulateTransactionResponse = {
export type SimulateTransaction = {
transaction_trace: TRANSACTION_TRACE;
fee_estimation: FEE_ESTIMATE;
}[];
};
export type SimulateTransactionResponse = SimulateTransaction[];
// response starknet_estimateFee
export type FeeEstimate = FEE_ESTIMATE;
// response starknet_getTransactionByHash, starknet_getTransactionByBlockIdAndIndex
Expand Down Expand Up @@ -79,6 +80,8 @@ export type TransactionHash = TXN_HASH;
export type TransactionTrace = TRANSACTION_TRACE;
export type BlockHash = BLOCK_HASH;
export type TransactionReceipt = TXN_RECEIPT | PENDING_TXN_RECEIPT;
export type Receipt = TXN_RECEIPT;
export type PendingReceipt = PENDING_TXN_RECEIPT;
export type EventFilter = EVENT_FILTER & RESULT_PAGE_REQUEST;
export type SimulationFlags = Array<SIMULATION_FLAG>;
export type L1Message = MSG_FROM_L1;
Expand Down
Loading

0 comments on commit 7ecb069

Please sign in to comment.