starknet 4.11.0 → 4.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # [4.12.0](https://github.com/0xs34n/starknet.js/compare/v4.11.0...v4.12.0) (2022-11-17)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **tests:** refactor udc tests ([01a6eef](https://github.com/0xs34n/starknet.js/commit/01a6eef11b2f32e05d2aea4ab185536e3fdb1a71))
6
+ - use method name similar to gateway endpoint ([79641b3](https://github.com/0xs34n/starknet.js/commit/79641b3076412d71fa4e5ccbdb018c4f3ecab938))
7
+
8
+ ### Features
9
+
10
+ - create getClass RPC alias ([1003534](https://github.com/0xs34n/starknet.js/commit/10035341dd26e23b59d3dd764936a7d8eaa3f3b0))
11
+
1
12
  # [4.11.0](https://github.com/0xs34n/starknet.js/compare/v4.10.0...v4.11.0) (2022-11-14)
2
13
 
3
14
  ### Bug Fixes
@@ -4,9 +4,13 @@ import typedDataExample from '../__mocks__/typedDataExample.json';
4
4
  import { Account, Contract, Provider, number, stark } from '../src';
5
5
  import { feeTransactionVersion } from '../src/utils/hash';
6
6
  import { toBN } from '../src/utils/number';
7
+ import { encodeShortString } from '../src/utils/shortString';
8
+ import { randomAddress } from '../src/utils/stark';
7
9
  import {
10
+ IS_DEVNET,
8
11
  compiledErc20,
9
12
  compiledTestDapp,
13
+ erc20ClassHash,
10
14
  getERC20DeployPayload,
11
15
  getTestAccount,
12
16
  getTestProvider,
@@ -159,4 +163,38 @@ describe('deploy and test Wallet', () => {
159
163
  expect(declareTx.class_hash).toBeDefined();
160
164
  });
161
165
  });
166
+
167
+ describe('Declare and UDC Deploy Flow', () => {
168
+ test('ERC20 Declare', async () => {
169
+ const declareTx = await account.declare({
170
+ classHash: erc20ClassHash,
171
+ contract: compiledErc20,
172
+ });
173
+
174
+ await provider.waitForTransaction(declareTx.transaction_hash);
175
+
176
+ expect(declareTx).toHaveProperty('class_hash');
177
+ expect(declareTx.class_hash).toEqual(erc20ClassHash);
178
+ });
179
+
180
+ test('UDC Deploy', async () => {
181
+ const salt = randomAddress(); // use random salt
182
+
183
+ const deployment = await account.deploy({
184
+ classHash: erc20ClassHash,
185
+ constructorCalldata: [
186
+ encodeShortString('Token'),
187
+ encodeShortString('ERC20'),
188
+ account.address,
189
+ ],
190
+ salt,
191
+ unique: true, // Using true here so as not to clash with normal erc20 deploy in account and provider test
192
+ isDevnet: IS_DEVNET,
193
+ });
194
+
195
+ await provider.waitForTransaction(deployment.transaction_hash);
196
+
197
+ expect(deployment).toHaveProperty('transaction_hash');
198
+ });
199
+ });
162
200
  });
@@ -1,6 +1,6 @@
1
1
  import { BlockNumber, GetBlockResponse, stark } from '../src';
2
2
  import { toBN } from '../src/utils/number';
3
- import { getERC20DeployPayload, getTestProvider } from './fixtures';
3
+ import { erc20ClassHash, getERC20DeployPayload, getTestProvider } from './fixtures';
4
4
 
5
5
  const { compileCalldata } = stark;
6
6
 
@@ -8,7 +8,7 @@ const testProvider = getTestProvider();
8
8
 
9
9
  describe('defaultProvider', () => {
10
10
  let exampleTransactionHash: string;
11
- let exampleContractAddress: string;
11
+ let erc20ContractAddress: string;
12
12
 
13
13
  let exampleBlock: GetBlockResponse;
14
14
  let exampleBlockNumber: BlockNumber;
@@ -23,7 +23,7 @@ describe('defaultProvider', () => {
23
23
  );
24
24
  await testProvider.waitForTransaction(transaction_hash);
25
25
  exampleTransactionHash = transaction_hash;
26
- exampleContractAddress = contract_address;
26
+ erc20ContractAddress = contract_address;
27
27
 
28
28
  exampleBlock = await testProvider.getBlock('latest');
29
29
  exampleBlockHash = exampleBlock.block_hash;
@@ -32,7 +32,7 @@ describe('defaultProvider', () => {
32
32
 
33
33
  describe('endpoints', () => {
34
34
  test('deployContract()', () => {
35
- expect(exampleContractAddress).toBeTruthy();
35
+ expect(erc20ContractAddress).toBeTruthy();
36
36
  expect(exampleTransactionHash).toBeTruthy();
37
37
  });
38
38
 
@@ -75,43 +75,41 @@ describe('defaultProvider', () => {
75
75
  });
76
76
 
77
77
  test('getNonce()', async () => {
78
- const nonce = await testProvider.getNonce(exampleContractAddress);
78
+ const nonce = await testProvider.getNonce(erc20ContractAddress);
79
79
  return expect(nonce).toEqual('0x0');
80
80
  });
81
81
 
82
82
  test('getClassAt(contractAddress, blockNumber="latest")', async () => {
83
- const classResponse = await testProvider.getClassAt(exampleContractAddress);
83
+ const classResponse = await testProvider.getClassAt(erc20ContractAddress);
84
84
 
85
85
  expect(classResponse).toHaveProperty('program');
86
86
  expect(classResponse).toHaveProperty('entry_points_by_type');
87
87
  });
88
88
 
89
89
  // TODO see if feasible to split
90
- describe('getClassHashAt & GetClass', () => {
90
+ describe('GetClassByHash', () => {
91
91
  test('responses', async () => {
92
- const classHash = await testProvider.getClassHashAt(exampleContractAddress);
93
- expect(typeof classHash).toBe('string');
94
-
95
- const classResponse = await testProvider.getClass(classHash);
92
+ const classResponse = await testProvider.getClassByHash(erc20ClassHash);
96
93
  expect(classResponse).toHaveProperty('program');
97
94
  expect(classResponse).toHaveProperty('entry_points_by_type');
95
+ expect(classResponse).toHaveProperty('abi');
98
96
  });
99
97
  });
100
98
 
101
99
  describe('getStorageAt', () => {
102
100
  test('with "key" type of number', () => {
103
- return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
101
+ return expect(testProvider.getStorageAt(erc20ContractAddress, 0)).resolves.not.toThrow();
104
102
  });
105
103
 
106
104
  test('"key" type of string', () => {
107
105
  return expect(
108
- testProvider.getStorageAt(exampleContractAddress, '0x0')
106
+ testProvider.getStorageAt(erc20ContractAddress, '0x0')
109
107
  ).resolves.not.toThrow();
110
108
  });
111
109
 
112
110
  test('with "key" type of BN', () => {
113
111
  return expect(
114
- testProvider.getStorageAt(exampleContractAddress, toBN('0x0'))
112
+ testProvider.getStorageAt(erc20ContractAddress, toBN('0x0'))
115
113
  ).resolves.not.toThrow();
116
114
  });
117
115
  });
@@ -135,7 +133,7 @@ describe('defaultProvider', () => {
135
133
  test('callContract()', () => {
136
134
  return expect(
137
135
  testProvider.callContract({
138
- contractAddress: exampleContractAddress,
136
+ contractAddress: erc20ContractAddress,
139
137
  entrypoint: 'balanceOf',
140
138
  calldata: compileCalldata({
141
139
  user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
@@ -148,7 +146,7 @@ describe('defaultProvider', () => {
148
146
  return expect(
149
147
  testProvider
150
148
  .callContract({
151
- contractAddress: exampleContractAddress,
149
+ contractAddress: erc20ContractAddress,
152
150
  entrypoint: 'balanceOf',
153
151
  calldata: compileCalldata({
154
152
  user: wallet,
@@ -163,7 +161,7 @@ describe('defaultProvider', () => {
163
161
  test('callContract() - gateway error', async () => {
164
162
  return expect(
165
163
  testProvider.callContract({
166
- contractAddress: exampleContractAddress,
164
+ contractAddress: erc20ContractAddress,
167
165
  entrypoint: 'non_existent_entrypoint',
168
166
  calldata: compileCalldata({
169
167
  user: '0xdeadbeef',
@@ -73,6 +73,8 @@ export const describeIfSequencer = describeIf(IS_DEVNET);
73
73
  export const describeIfRpc = describeIf(IS_RPC);
74
74
  export const describeIfNotDevnet = describeIf(!IS_DEVNET);
75
75
 
76
+ export const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
77
+
76
78
  export const getERC20DeployPayload = (recipient: string): DeployContractPayload => {
77
79
  return {
78
80
  contract: compiledErc20,
@@ -18,7 +18,7 @@ export declare class Provider implements ProviderInterface {
18
18
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
19
19
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
20
20
  getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
21
- getClass(classHash: string): Promise<ContractClass>;
21
+ getClassByHash(classHash: string): Promise<ContractClass>;
22
22
  getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
23
23
  getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
24
24
  getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
@@ -92,8 +92,8 @@ var Provider = /** @class */ (function () {
92
92
  });
93
93
  });
94
94
  };
95
- Provider.prototype.getClass = function (classHash) {
96
- return this.provider.getClass(classHash);
95
+ Provider.prototype.getClassByHash = function (classHash) {
96
+ return this.provider.getClassByHash(classHash);
97
97
  };
98
98
  Provider.prototype.getEstimateFee = function (invocationWithTxType, invocationDetails, blockIdentifier) {
99
99
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
@@ -52,7 +52,7 @@ export declare abstract class ProviderInterface {
52
52
  * @param classHash - class hash
53
53
  * @returns Contract class of compiled contract
54
54
  */
55
- abstract getClass(classHash: string): Promise<ContractClass>;
55
+ abstract getClassByHash(classHash: string): Promise<ContractClass>;
56
56
  /**
57
57
  * Gets the nonce of a contract with respect to a specific block
58
58
  *
@@ -35,6 +35,7 @@ export declare class RpcProvider implements ProviderInterface {
35
35
  getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse>;
36
36
  getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
37
37
  getTransactionReceipt(txHash: string): Promise<RPC.TransactionReceipt>;
38
+ getClassByHash(classHash: RPC.Felt): Promise<RPC.ContractClass>;
38
39
  getClass(classHash: RPC.Felt, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
39
40
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
40
41
  getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
@@ -249,6 +249,13 @@ var RpcProvider = /** @class */ (function () {
249
249
  });
250
250
  });
251
251
  };
252
+ RpcProvider.prototype.getClassByHash = function (classHash) {
253
+ return __awaiter(this, void 0, void 0, function () {
254
+ return __generator(this, function (_a) {
255
+ return [2 /*return*/, this.getClass(classHash)];
256
+ });
257
+ });
258
+ };
252
259
  RpcProvider.prototype.getClass = function (classHash, blockIdentifier) {
253
260
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
254
261
  return __awaiter(this, void 0, void 0, function () {
@@ -39,7 +39,7 @@ export declare class SequencerProvider implements ProviderInterface {
39
39
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
40
40
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
41
41
  getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
42
- getClass(classHash: string): Promise<ContractClass>;
42
+ getClassByHash(classHash: string): Promise<ContractClass>;
43
43
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
44
44
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
45
45
  deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
@@ -334,7 +334,7 @@ var SequencerProvider = /** @class */ (function () {
334
334
  });
335
335
  });
336
336
  };
337
- SequencerProvider.prototype.getClass = function (classHash) {
337
+ SequencerProvider.prototype.getClassByHash = function (classHash) {
338
338
  return __awaiter(this, void 0, void 0, function () {
339
339
  return __generator(this, function (_a) {
340
340
  return [2 /*return*/, this.fetchEndpoint('get_class_by_hash', { classHash: classHash }).then(provider_1.parseContract)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "4.11.0",
3
+ "version": "4.12.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@ export declare class Provider implements ProviderInterface {
18
18
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
19
19
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
20
20
  getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
21
- getClass(classHash: string): Promise<ContractClass>;
21
+ getClassByHash(classHash: string): Promise<ContractClass>;
22
22
  getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
23
23
  getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
24
24
  getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
@@ -92,8 +92,8 @@ var Provider = /** @class */ (function () {
92
92
  });
93
93
  });
94
94
  };
95
- Provider.prototype.getClass = function (classHash) {
96
- return this.provider.getClass(classHash);
95
+ Provider.prototype.getClassByHash = function (classHash) {
96
+ return this.provider.getClassByHash(classHash);
97
97
  };
98
98
  Provider.prototype.getEstimateFee = function (invocationWithTxType, invocationDetails, blockIdentifier) {
99
99
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
@@ -52,7 +52,7 @@ export declare abstract class ProviderInterface {
52
52
  * @param classHash - class hash
53
53
  * @returns Contract class of compiled contract
54
54
  */
55
- abstract getClass(classHash: string): Promise<ContractClass>;
55
+ abstract getClassByHash(classHash: string): Promise<ContractClass>;
56
56
  /**
57
57
  * Gets the nonce of a contract with respect to a specific block
58
58
  *
package/provider/rpc.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare class RpcProvider implements ProviderInterface {
35
35
  getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse>;
36
36
  getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
37
37
  getTransactionReceipt(txHash: string): Promise<RPC.TransactionReceipt>;
38
+ getClassByHash(classHash: RPC.Felt): Promise<RPC.ContractClass>;
38
39
  getClass(classHash: RPC.Felt, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
39
40
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
40
41
  getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
package/provider/rpc.js CHANGED
@@ -249,6 +249,13 @@ var RpcProvider = /** @class */ (function () {
249
249
  });
250
250
  });
251
251
  };
252
+ RpcProvider.prototype.getClassByHash = function (classHash) {
253
+ return __awaiter(this, void 0, void 0, function () {
254
+ return __generator(this, function (_a) {
255
+ return [2 /*return*/, this.getClass(classHash)];
256
+ });
257
+ });
258
+ };
252
259
  RpcProvider.prototype.getClass = function (classHash, blockIdentifier) {
253
260
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
254
261
  return __awaiter(this, void 0, void 0, function () {
@@ -39,7 +39,7 @@ export declare class SequencerProvider implements ProviderInterface {
39
39
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
40
40
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
41
41
  getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
42
- getClass(classHash: string): Promise<ContractClass>;
42
+ getClassByHash(classHash: string): Promise<ContractClass>;
43
43
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
44
44
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
45
45
  deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
@@ -334,7 +334,7 @@ var SequencerProvider = /** @class */ (function () {
334
334
  });
335
335
  });
336
336
  };
337
- SequencerProvider.prototype.getClass = function (classHash) {
337
+ SequencerProvider.prototype.getClassByHash = function (classHash) {
338
338
  return __awaiter(this, void 0, void 0, function () {
339
339
  return __generator(this, function (_a) {
340
340
  return [2 /*return*/, this.fetchEndpoint('get_class_by_hash', { classHash: classHash }).then(provider_1.parseContract)];
@@ -72,8 +72,8 @@ export class Provider implements ProviderInterface {
72
72
  return this.provider.getClassHashAt(contractAddress, blockIdentifier);
73
73
  }
74
74
 
75
- public getClass(classHash: string): Promise<ContractClass> {
76
- return this.provider.getClass(classHash);
75
+ public getClassByHash(classHash: string): Promise<ContractClass> {
76
+ return this.provider.getClassByHash(classHash);
77
77
  }
78
78
 
79
79
  public async getEstimateFee(
@@ -92,7 +92,7 @@ export abstract class ProviderInterface {
92
92
  * @param classHash - class hash
93
93
  * @returns Contract class of compiled contract
94
94
  */
95
- public abstract getClass(classHash: string): Promise<ContractClass>;
95
+ public abstract getClassByHash(classHash: string): Promise<ContractClass>;
96
96
 
97
97
  /**
98
98
  * Gets the nonce of a contract with respect to a specific block
@@ -195,6 +195,10 @@ export class RpcProvider implements ProviderInterface {
195
195
  return this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash });
196
196
  }
197
197
 
198
+ public async getClassByHash(classHash: RPC.Felt): Promise<RPC.ContractClass> {
199
+ return this.getClass(classHash);
200
+ }
201
+
198
202
  public async getClass(
199
203
  classHash: RPC.Felt,
200
204
  blockIdentifier: BlockIdentifier = 'pending'
@@ -307,7 +307,7 @@ export class SequencerProvider implements ProviderInterface {
307
307
  return this.fetchEndpoint('get_class_hash_at', { blockIdentifier, contractAddress });
308
308
  }
309
309
 
310
- public async getClass(classHash: string): Promise<ContractClass> {
310
+ public async getClassByHash(classHash: string): Promise<ContractClass> {
311
311
  return this.fetchEndpoint('get_class_by_hash', { classHash }).then(parseContract);
312
312
  }
313
313
 
@@ -1,41 +0,0 @@
1
- import { encodeShortString } from '../src/utils/shortString';
2
- import { randomAddress } from '../src/utils/stark';
3
- import { IS_DEVNET, compiledErc20, getTestAccount, getTestProvider } from './fixtures';
4
-
5
- describe('Declare and UDC Deploy Flow', () => {
6
- const provider = getTestProvider();
7
- const account = getTestAccount(provider);
8
- const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
9
-
10
- test('ERC20 Declare', async () => {
11
- const declareTx = await account.declare({
12
- classHash: erc20ClassHash,
13
- contract: compiledErc20,
14
- });
15
-
16
- await provider.waitForTransaction(declareTx.transaction_hash);
17
-
18
- expect(declareTx).toHaveProperty('class_hash');
19
- expect(declareTx.class_hash).toEqual(erc20ClassHash);
20
- });
21
-
22
- test('UDC Deploy', async () => {
23
- const salt = randomAddress(); // use random salt
24
-
25
- const deployment = await account.deploy({
26
- classHash: erc20ClassHash,
27
- constructorCalldata: [
28
- encodeShortString('Token'),
29
- encodeShortString('ERC20'),
30
- account.address,
31
- ],
32
- salt,
33
- unique: true, // Using true here so as not to clash with normal erc20 deploy in account and provider test
34
- isDevnet: IS_DEVNET,
35
- });
36
-
37
- await provider.waitForTransaction(deployment.transaction_hash);
38
-
39
- expect(deployment).toHaveProperty('transaction_hash');
40
- });
41
- });