Skip to content

Commit 79eb5ba

Browse files
committed
fix: provider tests
1 parent ffb6a12 commit 79eb5ba

File tree

6 files changed

+70
-74
lines changed

6 files changed

+70
-74
lines changed
Lines changed: 40 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { BlockNumber, stark } from '../src';
22
import { toBN } from '../src/utils/number';
3-
import {
4-
IS_DEVNET,
5-
compiledErc20,
6-
compiledOpenZeppelinAccount,
7-
getTestProvider,
8-
testIfNotDevnet,
9-
} from './fixtures';
3+
import { IS_DEVNET, compiledErc20, compiledOpenZeppelinAccount, getTestProvider } from './fixtures';
104

115
const { compileCalldata } = stark;
126

@@ -15,86 +9,73 @@ const provider = getTestProvider();
159
describe('defaultProvider', () => {
1610
let exampleTransactionHash: string;
1711
let exampleContractAddress: string;
18-
let exampleBlockHash: string;
19-
let exampleBlockNumber: BlockNumber;
12+
const exampleBlockHash: string =
13+
'0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43';
14+
const exampleBlockNumber: BlockNumber = 102634;
15+
2016
beforeAll(async () => {
21-
const { code, transaction_hash, address } = await provider.deployContract({
17+
const { transaction_hash, contract_address } = await provider.deployContract({
2218
contract: compiledErc20,
2319
});
24-
expect(code).toBe('TRANSACTION_RECEIVED');
2520
await provider.waitForTransaction(transaction_hash);
2621
exampleTransactionHash = transaction_hash;
27-
exampleContractAddress = address!;
28-
const transaction = await provider.getTransaction(transaction_hash);
29-
30-
if (transaction.status !== 'REJECTED') {
31-
exampleBlockHash = transaction.block_hash;
32-
exampleBlockNumber = transaction.block_number;
33-
}
22+
exampleContractAddress = contract_address;
3423
});
3524

36-
describe('feeder gateway endpoints', () => {
37-
testIfNotDevnet('getContractAddresses()', async () => {
38-
// not supported in starknet-devnet
39-
const { GpsStatementVerifier, Starknet } = await provider.getContractAddresses();
40-
expect(typeof GpsStatementVerifier).toBe('string');
41-
expect(typeof Starknet).toBe('string');
42-
});
25+
describe('endpoints', () => {
4326
test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, () => {
4427
return expect(provider.getBlock(exampleBlockHash)).resolves.not.toThrow();
4528
});
29+
4630
test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, () => {
4731
return expect(provider.getBlock(exampleBlockNumber)).resolves.not.toThrow();
4832
});
33+
4934
test('getBlock(blockHash=undefined, blockNumber=null)', async () => {
5035
const block = await provider.getBlock();
5136

5237
expect(block).not.toBeNull();
5338

54-
const { block_number, timestamp } = block;
39+
const { block_number, accepted_time } = block;
5540

5641
expect(typeof block_number).toEqual('number');
5742

58-
return expect(typeof timestamp).toEqual('number');
43+
return expect(typeof accepted_time).toEqual('number');
5944
});
45+
6046
test('getBlock() -> { blockNumber }', async () => {
6147
const block = await provider.getBlock();
6248
return expect(block).toHaveProperty('block_number');
6349
});
64-
test('getCode()', () => {
65-
return expect(provider.getCode(exampleContractAddress, 36663)).resolves.not.toThrow();
66-
});
67-
test('getCode(blockHash=undefined, blockNumber=null)', () => {
68-
return expect(provider.getCode(exampleContractAddress)).resolves.not.toThrow();
69-
});
70-
test('getStorageAt() with "key" type of number', () => {
71-
return expect(provider.getStorageAt(exampleContractAddress, 0, 36663)).resolves.not.toThrow();
72-
});
73-
test('getStorageAt() with "key" type of string', () => {
74-
return expect(
75-
provider.getStorageAt(exampleContractAddress, '0', 36663)
76-
).resolves.not.toThrow();
77-
});
78-
test('getStorageAt() with "key" type of BN', () => {
79-
return expect(
80-
provider.getStorageAt(exampleContractAddress, toBN('0x0'), 36663)
81-
).resolves.not.toThrow();
82-
});
83-
test('getStorageAt(blockHash=undefined, blockNumber=null)', () => {
84-
return expect(provider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
85-
});
86-
test('getTransactionStatus()', async () => {
87-
return expect(provider.getTransactionStatus(exampleTransactionHash)).resolves.not.toThrow();
50+
51+
describe('getStorageAt', () => {
52+
test('with "key" type of number', () => {
53+
return expect(
54+
provider.getStorageAt(exampleContractAddress, 0, 36663)
55+
).resolves.not.toThrow();
56+
});
57+
58+
test('"key" type of string', () => {
59+
return expect(
60+
provider.getStorageAt(exampleContractAddress, '0x0', 36663)
61+
).resolves.not.toThrow();
62+
});
63+
64+
test('with "key" type of BN', () => {
65+
return expect(
66+
provider.getStorageAt(exampleContractAddress, toBN('0x0'), 36663)
67+
).resolves.not.toThrow();
68+
});
69+
70+
test('(blockHash=undefined, blockNumber=null)', () => {
71+
return expect(provider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
72+
});
8873
});
8974

9075
test('getTransaction() - successful transaction', async () => {
9176
const transaction = await provider.getTransaction(exampleTransactionHash);
9277

93-
expect(transaction).not.toHaveProperty('transaction_failure_reason');
94-
95-
expect(transaction.transaction).toHaveProperty('transaction_hash');
96-
97-
return expect(transaction.status).not.toEqual('REJECTED');
78+
expect(transaction).toHaveProperty('transaction_hash');
9879
});
9980

10081
test('getTransactionReceipt() - successful transaction', async () => {
@@ -103,7 +84,7 @@ describe('defaultProvider', () => {
10384
return expect(transactionReceipt).toHaveProperty('actual_fee');
10485
});
10586

106-
test('callContract()', () => {
87+
test.only('callContract()', () => {
10788
return expect(
10889
provider.callContract({
10990
contractAddress: exampleContractAddress,
@@ -115,7 +96,7 @@ describe('defaultProvider', () => {
11596
).resolves.not.toThrow();
11697
});
11798

118-
test('callContract() - gateway error', async () => {
99+
test.only('callContract() - gateway error', async () => {
119100
const promise = provider.callContract({
120101
contractAddress: exampleContractAddress,
121102
entrypoint: 'non_existent_entrypoint',
@@ -136,12 +117,6 @@ describe('defaultProvider', () => {
136117
);
137118
}
138119
});
139-
140-
test('transaction trace', async () => {
141-
const transactionTrace = await provider.getTransactionTrace(exampleTransactionHash);
142-
expect(transactionTrace).toHaveProperty('function_invocation');
143-
expect(transactionTrace).toHaveProperty('signature');
144-
});
145120
});
146121

147122
describe('addTransaction()', () => {
@@ -150,7 +125,6 @@ describe('defaultProvider', () => {
150125
contract: compiledErc20,
151126
});
152127

153-
expect(response.code).toBe('TRANSACTION_RECEIVED');
154128
expect(response.transaction_hash).toBeDefined();
155129
expect(response.class_hash).toBeDefined();
156130
});
@@ -160,9 +134,8 @@ describe('defaultProvider', () => {
160134
contract: compiledOpenZeppelinAccount,
161135
});
162136

163-
expect(response.code).toBe('TRANSACTION_RECEIVED');
164137
expect(response.transaction_hash).toBeDefined();
165-
expect(response.address).toBeDefined();
138+
expect(response.contract_address).toBeDefined();
166139
});
167140
});
168141
});

__tests__/gatewayProvider.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,25 @@ describe('GatewayProvider', () => {
187187
});
188188
});
189189
});
190+
191+
describe('Gateway specifc methods', () => {
192+
const exampleTransactionHash =
193+
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348';
194+
195+
test('getContractAddresses()', async () => {
196+
const { GpsStatementVerifier, Starknet } = await provider.getContractAddresses();
197+
expect(typeof GpsStatementVerifier).toBe('string');
198+
expect(typeof Starknet).toBe('string');
199+
});
200+
201+
test('getTransactionStatus()', async () => {
202+
return expect(provider.getTransactionStatus(exampleTransactionHash)).resolves.not.toThrow();
203+
});
204+
205+
test('transaction trace', async () => {
206+
const transactionTrace = await provider.getTransactionTrace(exampleTransactionHash);
207+
expect(transactionTrace).toHaveProperty('function_invocation');
208+
expect(transactionTrace).toHaveProperty('signature');
209+
});
210+
});
190211
});

src/account/default.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ import { TypedData, getMessageHash } from '../utils/typedData';
2020
import { AccountInterface } from './interface';
2121

2222
export class Account extends Provider implements AccountInterface {
23-
public address: string;
24-
2523
public signer: SignerInterface;
2624

2725
constructor(
2826
providerOrOptions: ProviderOptions | ProviderInterface,
29-
address: string,
27+
public address: string,
3028
keyPairOrSigner: KeyPair | SignerInterface
3129
) {
3230
super(providerOrOptions);
3331
this.signer =
3432
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new Signer(keyPairOrSigner as KeyPair);
35-
this.address = address;
3633
}
3734

3835
public async getNonce(): Promise<string> {

src/provider/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Provider implements ProviderInterface {
4343
return this.provider.chainId;
4444
}
4545

46-
public async getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse> {
46+
public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
4747
return this.provider.getBlock(blockIdentifier);
4848
}
4949

src/provider/gateway.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@ export class GatewayProvider implements ProviderInterface {
227227
key: BigNumberish,
228228
blockIdentifier: BlockIdentifier = 'pending'
229229
): Promise<BigNumberish> {
230-
return this.fetchEndpoint('get_storage_at', { blockIdentifier, contractAddress, key }) as any;
230+
const parsedKey = toBN(key).toString(10);
231+
return this.fetchEndpoint('get_storage_at', {
232+
blockIdentifier,
233+
contractAddress,
234+
key: parsedKey,
235+
});
231236
}
232237

233238
public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {

src/types/api/gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export namespace Gateway {
259259
blockIdentifier: BlockIdentifier;
260260
};
261261
REQUEST: never;
262-
RESPONSE: object;
262+
RESPONSE: string;
263263
};
264264
get_code: {
265265
QUERY: {

0 commit comments

Comments
 (0)