@@ -24,8 +24,15 @@ const client20 = createPublicClient({
24
24
const randomAccount = privateKeyToAccount ( generatePrivateKey ( ) ) ;
25
25
const upgradeExecutorAddress = '0x24198F8A339cd3C47AEa3A764A20d2dDaB4D1b5b' ;
26
26
27
+ const client = createPublicClient ( {
28
+ chain : nitroTestnodeL2 ,
29
+ transport : http ( ) ,
30
+ } ) ;
31
+ const actionsWithVersion = arbOwnerPublicActions ( client , { arbOsVersion : 11 } ) ;
32
+ const actionsWithDefaultVersion = arbOwnerPublicActions ( client ) ;
33
+
27
34
describe ( 'Accept function name based on arbOSVersion' , async ( ) => {
28
- it ( 'Version 10 ' , ( ) => {
35
+ it ( 'Client with actions (version 10) ' , ( ) => {
29
36
expectTypeOf < typeof client10 . arbOwnerReadContract < 'onlyOnArbOS10' > > ( ) . toBeCallableWith ( {
30
37
functionName : 'onlyOnArbOS10' ,
31
38
} ) ;
@@ -46,7 +53,7 @@ describe('Accept function name based on arbOSVersion', async () => {
46
53
} ) ,
47
54
) . rejects . toThrowError ( AbiFunctionNotFoundError ) ;
48
55
} ) ;
49
- it ( 'Version 11 ' , ( ) => {
56
+ it ( 'Client with actions (version 11) ' , ( ) => {
50
57
expectTypeOf < typeof client11 . arbOwnerReadContract < 'onlyOnArbOS11' > > ( ) . toBeCallableWith ( {
51
58
functionName : 'onlyOnArbOS11' ,
52
59
} ) ;
@@ -67,7 +74,7 @@ describe('Accept function name based on arbOSVersion', async () => {
67
74
} ) ,
68
75
) . rejects . toThrowError ( AbiFunctionNotFoundError ) ;
69
76
} ) ;
70
- it ( 'Version 20 ' , ( ) => {
77
+ it ( 'Client with actions (version 20) ' , ( ) => {
71
78
expectTypeOf < typeof client20 . arbOwnerReadContract < 'getInfraFeeAccount' > > ( ) . toBeCallableWith ( {
72
79
functionName : 'getInfraFeeAccount' ,
73
80
} ) ;
@@ -88,7 +95,7 @@ describe('Accept function name based on arbOSVersion', async () => {
88
95
} ) ,
89
96
) . rejects . toThrowError ( AbiFunctionNotFoundError ) ;
90
97
} ) ;
91
- it ( 'Default version (20 )' , ( ) => {
98
+ it ( 'Client with actions (default version )' , ( ) => {
92
99
// arbOwnerPublicActions without params is defaulted to arbOsVersion 20
93
100
expectTypeOf <
94
101
typeof clientWithoutParam . arbOwnerReadContract < 'getInfraFeeAccount' >
@@ -112,37 +119,97 @@ describe('Accept function name based on arbOSVersion', async () => {
112
119
} ) ,
113
120
) . rejects . toThrowError ( AbiFunctionNotFoundError ) ;
114
121
} ) ;
122
+ it ( 'Standalone actions (version 11) ' , ( ) => {
123
+ expectTypeOf <
124
+ typeof actionsWithVersion . arbOwnerReadContract < 'onlyOnArbOS11' >
125
+ > ( ) . toBeCallableWith ( {
126
+ functionName : 'onlyOnArbOS11' ,
127
+ } ) ;
128
+
129
+ expectTypeOf <
130
+ typeof actionsWithVersion . arbOwnerPrepareTransactionRequest < 'setL1PricingRewardRecipient' >
131
+ > ( ) . toBeCallableWith ( {
132
+ functionName : 'setL1PricingRewardRecipient' ,
133
+ account : randomAccount . address ,
134
+ upgradeExecutor : upgradeExecutorAddress ,
135
+ args : [ 100n ] ,
136
+ } ) ;
137
+
138
+ expect (
139
+ actionsWithVersion . arbOwnerReadContract ( {
140
+ // @ts -expect-error Not available for version 11
141
+ functionName : 'onlyOnArbOS20' ,
142
+ } ) ,
143
+ ) . rejects . toThrowError ( AbiFunctionNotFoundError ) ;
144
+ } ) ;
145
+ it ( 'Standalone actions (default version) ' , ( ) => {
146
+ expectTypeOf <
147
+ typeof actionsWithDefaultVersion . arbOwnerReadContract < 'getInfraFeeAccount' >
148
+ > ( ) . toBeCallableWith ( {
149
+ functionName : 'getInfraFeeAccount' ,
150
+ } ) ;
151
+
152
+ expectTypeOf <
153
+ typeof actionsWithDefaultVersion . arbOwnerPrepareTransactionRequest < 'setL1PricingRewardRecipient' >
154
+ > ( ) . toBeCallableWith ( {
155
+ functionName : 'setL1PricingRewardRecipient' ,
156
+ account : randomAccount . address ,
157
+ upgradeExecutor : upgradeExecutorAddress ,
158
+ args : [ randomAccount . address ] ,
159
+ } ) ;
160
+
161
+ expect (
162
+ actionsWithDefaultVersion . arbOwnerReadContract ( {
163
+ // @ts -expect-error Not available for version 20
164
+ functionName : 'onlyOnArbOS10' ,
165
+ } ) ,
166
+ ) . rejects . toThrowError ( AbiFunctionNotFoundError ) ;
167
+ } ) ;
115
168
} ) ;
116
169
117
170
// Those tests won't fail if the return type is wrong
118
171
// But they will display an error in the IDE
119
172
describe ( 'Type return values for function in multiple versions' , ( ) => {
120
- it ( 'Version 10' , ( ) => {
173
+ it ( 'Client with actions ( Version 10) ' , ( ) => {
121
174
expectTypeOf (
122
175
client10 . arbOwnerReadContract ( {
123
176
functionName : 'getAllChainOwners' ,
124
177
} ) ,
125
178
) . resolves . toEqualTypeOf < `0x${string } `> ( ) ;
126
179
} ) ;
127
- it ( 'Version 11' , ( ) => {
180
+ it ( 'Client with actions ( Version 11) ' , ( ) => {
128
181
expectTypeOf (
129
182
client11 . arbOwnerReadContract ( {
130
183
functionName : 'getAllChainOwners' ,
131
184
} ) ,
132
185
) . resolves . toEqualTypeOf < bigint > ( ) ;
133
186
} ) ;
134
- it ( 'Version 20' , ( ) => {
187
+ it ( 'Client with actions ( Version 20) ' , ( ) => {
135
188
expectTypeOf (
136
189
client20 . arbOwnerReadContract ( {
137
190
functionName : 'getAllChainOwners' ,
138
191
} ) ,
139
192
) . resolves . toEqualTypeOf < readonly `0x${string } `[ ] > ( ) ;
140
193
} ) ;
141
- it ( 'Default version (20 )' , ( ) => {
194
+ it ( 'Client with actions (default version )' , ( ) => {
142
195
expectTypeOf (
143
196
clientWithoutParam . arbOwnerReadContract ( {
144
197
functionName : 'getAllChainOwners' ,
145
198
} ) ,
146
199
) . resolves . toEqualTypeOf < readonly `0x${string } `[ ] > ( ) ;
147
200
} ) ;
201
+ it ( 'Standalone actions (version 11)' , ( ) => {
202
+ expectTypeOf (
203
+ actionsWithVersion . arbOwnerReadContract ( {
204
+ functionName : 'getAllChainOwners' ,
205
+ } ) ,
206
+ ) . resolves . toEqualTypeOf < bigint > ( ) ;
207
+ } ) ;
208
+ it ( 'Standalone actions (default version)' , ( ) => {
209
+ expectTypeOf (
210
+ actionsWithDefaultVersion . arbOwnerReadContract ( {
211
+ functionName : 'getAllChainOwners' ,
212
+ } ) ,
213
+ ) . resolves . toEqualTypeOf < readonly `0x${string } `[ ] > ( ) ;
214
+ } ) ;
148
215
} ) ;
0 commit comments