@apibara/starknet 0.3.0 → 0.4.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.
@@ -1,2 +1,2 @@
1
- import { apibara } from './generated';
1
+ import { apibara } from "./generated";
2
2
  export import v1alpha2 = apibara.starknet.v1alpha2;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proto/index.ts"],"names":[],"mappings":";;;AAAA,2CAAqC;AAErC,6DAA6D;AAC/C,QAAA,QAAQ,GAAG,mBAAO,CAAC,QAAQ,CAAC,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proto/index.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AAEtC,6DAA6D;AAC/C,QAAA,QAAQ,GAAG,mBAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC"}
@@ -20,6 +20,8 @@ message Block {
20
20
  repeated EventWithTransaction events = 5;
21
21
  // Messages to L1 sent in the block.
22
22
  repeated L2ToL1MessageWithTransaction l2_to_l1_messages = 6;
23
+ // Whether the block contains data.
24
+ bool empty = 7;
23
25
  }
24
26
 
25
27
  // Block header.
@@ -36,6 +38,10 @@ message BlockHeader {
36
38
  FieldElement new_root = 5;
37
39
  // Timestamp when block was produced.
38
40
  google.protobuf.Timestamp timestamp = 6;
41
+ // Starknet version.
42
+ string starknet_version = 7;
43
+ // Price of L1 gas in the block.
44
+ ResourcePrice l1_gas_price = 8;
39
45
  }
40
46
 
41
47
  // Status of a block.
@@ -69,7 +75,7 @@ message Transaction {
69
75
  InvokeTransactionV0 invoke_v0 = 2;
70
76
  // Transaction invoking a smart contract, V1.
71
77
  InvokeTransactionV1 invoke_v1 = 3;
72
- // Transaction deploying a new smart contract.
78
+ // Transaction deploying a new smart contract, V1.
73
79
  DeployTransaction deploy = 4;
74
80
  // Transaction declaring a smart contract.
75
81
  DeclareTransaction declare = 5;
@@ -77,6 +83,12 @@ message Transaction {
77
83
  L1HandlerTransaction l1_handler = 6;
78
84
  // Transaction deploying a new account.
79
85
  DeployAccountTransaction deploy_account = 7;
86
+ // Transaction deploying a new smart contract, V3.
87
+ DeployAccountTransactionV3 deploy_account_v3 = 8;
88
+ // Transaction invoking a smart contract, V3.
89
+ InvokeTransactionV3 invoke_v3 = 9;
90
+ // Transaction declaring a smart contract, V3.
91
+ DeclareTransactionV3 declare_v3 = 10;
80
92
  }
81
93
  }
82
94
 
@@ -92,6 +104,18 @@ message TransactionMeta {
92
104
  FieldElement nonce = 4;
93
105
  // Version.
94
106
  uint64 version = 5;
107
+ // Transaction resources.
108
+ ResourceBoundsMapping resource_bounds = 6;
109
+ // Tip to the sequencer.
110
+ uint64 tip = 7;
111
+ // Data passed to the paymaster.
112
+ repeated FieldElement paymaster_data = 8;
113
+ // The storage domain of the account's nonce.
114
+ DataAvailabilityMode nonce_data_availability_mode = 9;
115
+ // The storage domain of the account's balance from which fee will be charged.
116
+ DataAvailabilityMode fee_data_availability_mode = 10;
117
+ // Index of the transaction in the block.
118
+ uint64 transaction_index = 11;
95
119
  }
96
120
 
97
121
  // Transaction invoking a smart contract, V0.
@@ -112,7 +136,17 @@ message InvokeTransactionV1 {
112
136
  repeated FieldElement calldata = 2;
113
137
  }
114
138
 
115
- // Transaction deploying a new smart contract.
139
+ // Transaction invoking a smart contract, V3.
140
+ message InvokeTransactionV3 {
141
+ // Address sending the transaction.
142
+ FieldElement sender_address = 1;
143
+ // Raw calldata.
144
+ repeated FieldElement calldata = 2;
145
+ // Data passed to the account deployment.
146
+ repeated FieldElement account_deployment_data = 3;
147
+ }
148
+
149
+ // Transaction deploying a new smart contract, V1.
116
150
  message DeployTransaction {
117
151
  // Raw calldata passed to the constructor.
118
152
  repeated FieldElement constructor_calldata = 2;
@@ -132,6 +166,18 @@ message DeclareTransaction {
132
166
  FieldElement compiled_class_hash = 3;
133
167
  }
134
168
 
169
+ // Transaction declaring a smart contract.
170
+ message DeclareTransactionV3 {
171
+ // Class hash.
172
+ FieldElement class_hash = 1;
173
+ // Address of the account declaring the class.
174
+ FieldElement sender_address = 2;
175
+ // The hash of the cairo assembly resulting from the sierra compilation.
176
+ FieldElement compiled_class_hash = 3;
177
+ // Data passed to the account deployment.
178
+ repeated FieldElement account_deployment_data = 4;
179
+ }
180
+
135
181
  // Transaction handling a message from L1.
136
182
  message L1HandlerTransaction {
137
183
  // Target contract address.
@@ -152,6 +198,26 @@ message DeployAccountTransaction {
152
198
  FieldElement class_hash = 4;
153
199
  }
154
200
 
201
+ // Transaction deploying a new smart contract, V3.
202
+ message DeployAccountTransactionV3 {
203
+ // Raw calldata passed to the constructor.
204
+ repeated FieldElement constructor_calldata = 1;
205
+ // Salt used when computing the contract's address.
206
+ FieldElement contract_address_salt = 2;
207
+ // Hash of the class being deployed.
208
+ FieldElement class_hash = 3;
209
+ }
210
+
211
+ // Transaction execution status.
212
+ enum ExecutionStatus {
213
+ // Unknown execution status.
214
+ EXECUTION_STATUS_UNSPECIFIED = 0;
215
+ // Transaction succeeded.
216
+ EXECUTION_STATUS_SUCCEEDED = 1;
217
+ // Transaction reverted.
218
+ EXECUTION_STATUS_REVERTED = 2;
219
+ }
220
+
155
221
  // Result of the execution of a transaction.
156
222
  //
157
223
  // This message only contains the receipt data, if you also need the
@@ -162,13 +228,19 @@ message TransactionReceipt {
162
228
  // Transaction's indexe in the list of transactions in a block.
163
229
  uint64 transaction_index = 2;
164
230
  // Feed paid.
165
- FieldElement actual_fee = 3;
231
+ FieldElement actual_fee = 3 [ deprecated = true ];
166
232
  // Messages sent to L1 in the transactions.
167
233
  repeated L2ToL1Message l2_to_l1_messages = 4;
168
234
  // Events emitted in the transaction.
169
235
  repeated Event events = 5;
170
236
  // Address of the contract that was created by the transaction.
171
237
  FieldElement contract_address = 6;
238
+ // Transaction execution status.
239
+ ExecutionStatus execution_status = 7;
240
+ // The reason why the transaction reverted.
241
+ string revert_reason = 8;
242
+ // Feed paid.
243
+ FeePayment actual_fee_paid = 9;
172
244
  }
173
245
 
174
246
  // Message sent from L2 to L1 together with its transaction and receipt.
@@ -294,3 +366,60 @@ message NonceUpdate {
294
366
  // New nonce value.
295
367
  FieldElement nonce = 2;
296
368
  }
369
+
370
+ // Price of a unit of a resource.
371
+ message ResourcePrice {
372
+ // Price in fri (10^-18 strk).
373
+ FieldElement price_in_fri = 1;
374
+ // Price in wei (10^-18 eth).
375
+ FieldElement price_in_wei = 2;
376
+ }
377
+
378
+ // A Starknet fee payment.
379
+ message FeePayment {
380
+ // Amount paid.
381
+ FieldElement amount = 1;
382
+ // Unit of the amount.
383
+ PriceUnit unit = 2;
384
+ }
385
+
386
+ // Price unit.
387
+ enum PriceUnit {
388
+ // Unknown price unit.
389
+ PRICE_UNIT_UNSPECIFIED = 0;
390
+ // WEI.
391
+ PRICE_UNIT_WEI = 1;
392
+ // FRI.
393
+ PRICE_UNIT_FRI = 2;
394
+ }
395
+
396
+ message ResourceBoundsMapping {
397
+ // Maximum amount and price of L1 gas.
398
+ ResourceBounds l1_gas = 1;
399
+ // Maximum amount and price of L2 gas.
400
+ ResourceBounds l2_gas = 2;
401
+ }
402
+
403
+ message ResourceBounds {
404
+ // The maximum amount of resources that can be consumed by a transaction.
405
+ uint64 max_amount = 1;
406
+ /// The max price per unit of resource.
407
+ Uint128 max_price_per_unit = 2;
408
+ }
409
+
410
+ message Uint128 {
411
+ // The low 64 bits of the number.
412
+ uint64 low = 1;
413
+ // The high 64 bits of the number.
414
+ uint64 high = 2;
415
+ }
416
+
417
+ // DA mode.
418
+ enum DataAvailabilityMode {
419
+ // Unknown DA.
420
+ DATA_AVAILABILITY_MODE_UNSPECIFIED = 0;
421
+ // L1.
422
+ DATA_AVAILABILITY_MODE_L1 = 1;
423
+ // L2.
424
+ DATA_AVAILABILITY_MODE_L2 = 2;
425
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/starknet",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,17 +19,13 @@
19
19
  "@types/node": "^18.11.9",
20
20
  "protobufjs-cli": "^1.0.2"
21
21
  },
22
- "eslintConfig": {
23
- "ignorePatterns": [
24
- "src/proto/generated.d.ts"
25
- ]
26
- },
27
22
  "scripts": {
28
23
  "prebuild": "pnpm run protobuf && pnpm run gen-proto",
29
24
  "build": "tsc && cp src/proto/generated.d.ts dist/proto/generated.d.ts",
30
25
  "test": "jest src",
31
- "lint": "eslint src --ext .ts",
32
- "lint:fix": "eslint --fix src --ext .ts",
26
+ "lint": "biome check .",
27
+ "lint:fix": "pnpm lint --apply",
28
+ "format": "biome format . --write",
33
29
  "protobuf": "mkdir -p dist/proto && cp src/proto/*.proto dist/proto",
34
30
  "gen-module": "pbjs -t static-module -w commonjs -o src/proto/generated.js src/proto/*.proto",
35
31
  "gen-types": "pbts -o src/proto/generated.d.ts src/proto/generated.js",
package/src/cursor.ts CHANGED
@@ -1,6 +1,6 @@
1
- import Long from 'long'
2
- import { FieldElement } from './felt'
3
- import { v1alpha2 } from './proto'
1
+ import Long from "long";
2
+ import { FieldElement } from "./felt";
3
+ import { v1alpha2 } from "./proto";
4
4
 
5
5
  export const StarkNetCursor = {
6
6
  /**
@@ -10,17 +10,23 @@ export const StarkNetCursor = {
10
10
  return {
11
11
  orderKey: Long.fromValue(number),
12
12
  uniqueKey: new Uint8Array(),
13
- }
13
+ };
14
14
  },
15
15
 
16
16
  /**
17
17
  * Creates a cursor pointing at the block with the given height and hash.
18
18
  */
19
- createWithBlockNumberAndHash: (number: string | number | Long, hash: v1alpha2.IFieldElement) => {
20
- const uniqueKey = Buffer.from(FieldElement.toHex(hash).replace('0x', ''), 'hex')
19
+ createWithBlockNumberAndHash: (
20
+ number: string | number | Long,
21
+ hash: v1alpha2.IFieldElement,
22
+ ) => {
23
+ const uniqueKey = Buffer.from(
24
+ FieldElement.toHex(hash).replace("0x", ""),
25
+ "hex",
26
+ );
21
27
  return {
22
28
  orderKey: Long.fromValue(number),
23
29
  uniqueKey,
24
- }
30
+ };
25
31
  },
26
- }
32
+ };
package/src/felt.test.ts CHANGED
@@ -1,24 +1,26 @@
1
- import { FieldElement } from './felt'
1
+ import { FieldElement } from "./felt";
2
2
 
3
- describe('FieldElement', () => {
4
- describe('encoding', () => {
5
- it('can be encoded to and from the wire format', () => {
6
- const original = BigInt('0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3')
3
+ describe("FieldElement", () => {
4
+ describe("encoding", () => {
5
+ it("can be encoded to and from the wire format", () => {
6
+ const original = BigInt(
7
+ "0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3",
8
+ );
7
9
 
8
- const encoded = FieldElement.fromBigInt(original)
10
+ const encoded = FieldElement.fromBigInt(original);
9
11
 
10
- const back = FieldElement.toBigInt(encoded)
12
+ const back = FieldElement.toBigInt(encoded);
11
13
 
12
- expect(back).toBe(original)
13
- })
14
+ expect(back).toBe(original);
15
+ });
14
16
 
15
- it('encodes the value as big endian', () => {
16
- const prime = 2n ** 251n + 17n * 2n ** 192n
17
- const encoded = FieldElement.fromBigInt(prime)
18
- expect(encoded.hiHi?.toString()).toEqual('0')
19
- expect(encoded.hiLo?.toString()).toEqual('0')
20
- expect(encoded.loHi?.toString()).toEqual('0')
21
- expect(encoded.loLo?.toString()).toEqual('576460752303423505')
22
- })
23
- })
24
- })
17
+ it("encodes the value as big endian", () => {
18
+ const prime = 2n ** 251n + 17n * 2n ** 192n;
19
+ const encoded = FieldElement.fromBigInt(prime);
20
+ expect(encoded.hiHi?.toString()).toEqual("0");
21
+ expect(encoded.hiLo?.toString()).toEqual("0");
22
+ expect(encoded.loHi?.toString()).toEqual("0");
23
+ expect(encoded.loLo?.toString()).toEqual("576460752303423505");
24
+ });
25
+ });
26
+ });
package/src/felt.ts CHANGED
@@ -1,7 +1,7 @@
1
- import Long from 'long'
2
- import { v1alpha2 } from './proto'
1
+ import Long from "long";
2
+ import { v1alpha2 } from "./proto";
3
3
 
4
- const MAX_FELT = 2n ** 251n + 17n * 2n ** 192n
4
+ const MAX_FELT = 2n ** 251n + 17n * 2n ** 192n;
5
5
 
6
6
  export const FieldElement = {
7
7
  encode: v1alpha2.FieldElement.encode,
@@ -13,11 +13,11 @@ export const FieldElement = {
13
13
  * Converts from the wire representation to a bigint.
14
14
  */
15
15
  toBigInt(message: v1alpha2.IFieldElement): bigint {
16
- const hiHi = hexEncodedU64(message.hiHi)
17
- const hiLo = hexEncodedU64(message.hiLo)
18
- const loHi = hexEncodedU64(message.loHi)
19
- const loLo = hexEncodedU64(message.loLo)
20
- return BigInt(`0x${loLo}${loHi}${hiLo}${hiHi}`)
16
+ const hiHi = hexEncodedU64(message.hiHi);
17
+ const hiLo = hexEncodedU64(message.hiLo);
18
+ const loHi = hexEncodedU64(message.loHi);
19
+ const loLo = hexEncodedU64(message.loLo);
20
+ return BigInt(`0x${loLo}${loHi}${hiLo}${hiHi}`);
21
21
  },
22
22
 
23
23
  /**
@@ -25,37 +25,37 @@ export const FieldElement = {
25
25
  */
26
26
  fromBigInt(number: string | number | bigint): v1alpha2.IFieldElement {
27
27
  if (number < 0 || number > MAX_FELT) {
28
- throw new Error('FieldElement outside of range')
28
+ throw new Error("FieldElement outside of range");
29
29
  }
30
30
 
31
- const bn = BigInt(number)
31
+ const bn = BigInt(number);
32
32
  // bit-shifting of a big int doesn't make much sense.
33
33
  // convert to hex and from there breakup in pieces
34
- const hex = bn.toString(16).padStart(64, '0')
35
- const s = hex.length
36
- const hiHi = Long.fromString(hex.slice(s - 16, s), true, 16)
37
- const hiLo = Long.fromString(hex.slice(s - 32, s - 16), true, 16)
38
- const loHi = Long.fromString(hex.slice(s - 48, s - 32), true, 16)
39
- const loLo = Long.fromString(hex.slice(s - 64, s - 48), true, 16)
34
+ const hex = bn.toString(16).padStart(64, "0");
35
+ const s = hex.length;
36
+ const hiHi = Long.fromString(hex.slice(s - 16, s), true, 16);
37
+ const hiLo = Long.fromString(hex.slice(s - 32, s - 16), true, 16);
38
+ const loHi = Long.fromString(hex.slice(s - 48, s - 32), true, 16);
39
+ const loLo = Long.fromString(hex.slice(s - 64, s - 48), true, 16);
40
40
 
41
41
  return {
42
42
  hiHi,
43
43
  hiLo,
44
44
  loHi,
45
45
  loLo,
46
- }
46
+ };
47
47
  },
48
48
 
49
49
  /**
50
50
  * Returns the hex value of the field element.
51
51
  */
52
52
  toHex(message: v1alpha2.IFieldElement): string {
53
- const num = this.toBigInt(message)
54
- return `0x${num.toString(16).padStart(64, '0')}`
53
+ const num = this.toBigInt(message);
54
+ return `0x${num.toString(16).padStart(64, "0")}`;
55
55
  },
56
- }
56
+ };
57
57
 
58
58
  function hexEncodedU64(n: Long | number | null | undefined): string {
59
- const s = n?.toString(16) ?? ''
60
- return s.padStart(16, '0')
59
+ const s = n?.toString(16) ?? "";
60
+ return s.padStart(16, "0");
61
61
  }
@@ -1,117 +1,139 @@
1
- import { Filter } from './filter'
2
- import { FieldElement } from './felt'
3
-
4
- describe('Filter', () => {
5
- describe('addHeader', () => {
6
- it('sets the header field', () => {
7
- let filter = Filter.create().withHeader().toObject()
8
-
9
- expect(filter.header).toEqual({})
10
- })
11
- })
12
-
13
- describe('addTransaction', () => {
14
- it('accepts a builder or callback function', () => {
15
- let filter = Filter.create()
16
- .addTransaction(Filter.transaction().declare().withClassHash(FieldElement.fromBigInt(123)))
1
+ import { FieldElement } from "./felt";
2
+ import { Filter } from "./filter";
3
+
4
+ describe("Filter", () => {
5
+ describe("addHeader", () => {
6
+ it("sets the header field", () => {
7
+ const filter = Filter.create().withHeader().toObject();
8
+
9
+ expect(filter.header).toEqual({});
10
+ });
11
+ });
12
+
13
+ describe("addTransaction", () => {
14
+ it("accepts a builder or callback function", () => {
15
+ const filter = Filter.create()
16
+ .addTransaction(
17
+ Filter.transaction()
18
+ .declare()
19
+ .withClassHash(FieldElement.fromBigInt(123)),
20
+ )
17
21
  .addTransaction((tx) =>
18
- tx.deployAccount().withConstructorCalldata([FieldElement.fromBigInt(0)])
22
+ tx
23
+ .deployAccount()
24
+ .withConstructorCalldata([FieldElement.fromBigInt(0)]),
25
+ )
26
+ .toObject();
27
+
28
+ expect(filter.transactions).toHaveLength(2);
29
+ expect(filter.transactions?.[0].declare).toBeDefined();
30
+ expect(filter.transactions?.[1].deployAccount).toBeDefined();
31
+ });
32
+ });
33
+
34
+ describe("addEvent", () => {
35
+ it("accepts a builder or callback function", () => {
36
+ const filter = Filter.create()
37
+ .addEvent(
38
+ Filter.event().withFromAddress(FieldElement.fromBigInt("0x0")),
19
39
  )
20
- .toObject()
21
-
22
- expect(filter.transactions).toHaveLength(2)
23
- expect(filter.transactions?.[0].declare).toBeDefined()
24
- expect(filter.transactions?.[1].deployAccount).toBeDefined()
25
- })
26
- })
27
-
28
- describe('addEvent', () => {
29
- it('accepts a builder or callback function', () => {
30
- let filter = Filter.create()
31
- .addEvent(Filter.event().withFromAddress(FieldElement.fromBigInt('0x0')))
32
40
  .addEvent((ev) => ev.withData([FieldElement.fromBigInt(0)]))
33
- .toObject()
41
+ .toObject();
34
42
 
35
- expect(filter.events).toHaveLength(2)
36
- })
37
- })
43
+ expect(filter.events).toHaveLength(2);
44
+ });
45
+ });
38
46
 
39
- describe('addMessage', () => {
40
- it('accepts a builder or callback function', () => {
41
- let filter = Filter.create()
47
+ describe("addMessage", () => {
48
+ it("accepts a builder or callback function", () => {
49
+ const filter = Filter.create()
42
50
  .addMessage(Filter.message().withToAddress(FieldElement.fromBigInt(0)))
43
51
  .addMessage((msg) => msg.withPayload([FieldElement.fromBigInt(0)]))
44
- .toObject()
52
+ .toObject();
45
53
 
46
- expect(filter.messages).toHaveLength(2)
47
- })
48
- })
54
+ expect(filter.messages).toHaveLength(2);
55
+ });
56
+ });
49
57
 
50
- describe('withStateUpdate', () => {
51
- it('accepts a callback function', () => {
52
- let filter = Filter.create()
58
+ describe("withStateUpdate", () => {
59
+ it("accepts a callback function", () => {
60
+ const filter = Filter.create()
53
61
  .withStateUpdate((s) => s)
54
- .toObject()
55
- expect(filter.stateUpdate).toBeDefined()
56
- })
57
-
58
- it('accepts a builder', () => {
59
- let filter = Filter.create().withStateUpdate(Filter.stateUpdate()).toObject()
60
- expect(filter.stateUpdate).toBeDefined()
61
- })
62
-
63
- describe('addStorageDiff', () => {
64
- it('accepts a callback function', () => {
65
- let filter = Filter.create()
66
- .withStateUpdate((s) => s.addStorageDiff((d) => d).addStorageDiff((d) => d))
67
- .toObject()
68
- expect(filter.stateUpdate?.storageDiffs).toHaveLength(2)
69
- })
70
- })
71
-
72
- describe('addDeclaredContract', () => {
73
- it('accepts a callback function', () => {
74
- let filter = Filter.create()
75
- .withStateUpdate((s) => s.addDeclaredContract((d) => d).addDeclaredContract((d) => d))
76
- .toObject()
77
- expect(filter.stateUpdate?.declaredContracts).toHaveLength(2)
78
- })
79
- })
80
-
81
- describe('addDeployedContract', () => {
82
- it('accepts a callback function', () => {
83
- let filter = Filter.create()
84
- .withStateUpdate((s) => s.addDeployedContract((d) => d).addDeployedContract((d) => d))
85
- .toObject()
86
- expect(filter.stateUpdate?.deployedContracts).toHaveLength(2)
87
- })
88
- })
89
-
90
- describe('addDeclaredClass', () => {
91
- it('accepts a callback function', () => {
92
- let filter = Filter.create()
93
- .withStateUpdate((s) => s.addDeclaredClass((d) => d).addDeclaredClass((d) => d))
94
- .toObject()
95
- expect(filter.stateUpdate?.declaredClasses).toHaveLength(2)
96
- })
97
- })
98
-
99
- describe('addReplacedClass', () => {
100
- it('accepts a callback function', () => {
101
- let filter = Filter.create()
102
- .withStateUpdate((s) => s.addReplacedClass((d) => d).addReplacedClass((d) => d))
103
- .toObject()
104
- expect(filter.stateUpdate?.replacedClasses).toHaveLength(2)
105
- })
106
- })
107
-
108
- describe('addNonceUpdated', () => {
109
- it('accepts a callback function', () => {
110
- let filter = Filter.create()
111
- .withStateUpdate((s) => s.addNonceUpdate((d) => d).addNonceUpdate((d) => d))
112
- .toObject()
113
- expect(filter.stateUpdate?.nonces).toHaveLength(2)
114
- })
115
- })
116
- })
117
- })
62
+ .toObject();
63
+ expect(filter.stateUpdate).toBeDefined();
64
+ });
65
+
66
+ it("accepts a builder", () => {
67
+ const filter = Filter.create()
68
+ .withStateUpdate(Filter.stateUpdate())
69
+ .toObject();
70
+ expect(filter.stateUpdate).toBeDefined();
71
+ });
72
+
73
+ describe("addStorageDiff", () => {
74
+ it("accepts a callback function", () => {
75
+ const filter = Filter.create()
76
+ .withStateUpdate((s) =>
77
+ s.addStorageDiff((d) => d).addStorageDiff((d) => d),
78
+ )
79
+ .toObject();
80
+ expect(filter.stateUpdate?.storageDiffs).toHaveLength(2);
81
+ });
82
+ });
83
+
84
+ describe("addDeclaredContract", () => {
85
+ it("accepts a callback function", () => {
86
+ const filter = Filter.create()
87
+ .withStateUpdate((s) =>
88
+ s.addDeclaredContract((d) => d).addDeclaredContract((d) => d),
89
+ )
90
+ .toObject();
91
+ expect(filter.stateUpdate?.declaredContracts).toHaveLength(2);
92
+ });
93
+ });
94
+
95
+ describe("addDeployedContract", () => {
96
+ it("accepts a callback function", () => {
97
+ const filter = Filter.create()
98
+ .withStateUpdate((s) =>
99
+ s.addDeployedContract((d) => d).addDeployedContract((d) => d),
100
+ )
101
+ .toObject();
102
+ expect(filter.stateUpdate?.deployedContracts).toHaveLength(2);
103
+ });
104
+ });
105
+
106
+ describe("addDeclaredClass", () => {
107
+ it("accepts a callback function", () => {
108
+ const filter = Filter.create()
109
+ .withStateUpdate((s) =>
110
+ s.addDeclaredClass((d) => d).addDeclaredClass((d) => d),
111
+ )
112
+ .toObject();
113
+ expect(filter.stateUpdate?.declaredClasses).toHaveLength(2);
114
+ });
115
+ });
116
+
117
+ describe("addReplacedClass", () => {
118
+ it("accepts a callback function", () => {
119
+ const filter = Filter.create()
120
+ .withStateUpdate((s) =>
121
+ s.addReplacedClass((d) => d).addReplacedClass((d) => d),
122
+ )
123
+ .toObject();
124
+ expect(filter.stateUpdate?.replacedClasses).toHaveLength(2);
125
+ });
126
+ });
127
+
128
+ describe("addNonceUpdated", () => {
129
+ it("accepts a callback function", () => {
130
+ const filter = Filter.create()
131
+ .withStateUpdate((s) =>
132
+ s.addNonceUpdate((d) => d).addNonceUpdate((d) => d),
133
+ )
134
+ .toObject();
135
+ expect(filter.stateUpdate?.nonces).toHaveLength(2);
136
+ });
137
+ });
138
+ });
139
+ });