@@ -10,16 +10,20 @@ import {
10
10
constants ,
11
11
Contract ,
12
12
ec ,
13
+ num ,
13
14
outsideExecution ,
14
15
OutsideExecutionVersion ,
15
16
Provider ,
16
17
src5 ,
17
18
stark ,
19
+ TransactionType ,
18
20
type Call ,
19
21
type Calldata ,
22
+ type Invocations ,
20
23
type OutsideExecutionOptions ,
21
24
type OutsideTransaction ,
22
25
type TypedData ,
26
+ type WeierstrassSignatureType ,
23
27
} from '../src' ;
24
28
import { getSelectorFromName } from '../src/utils/hash' ;
25
29
import { getDecimalString } from '../src/utils/num' ;
@@ -35,6 +39,25 @@ describe('Account and OutsideExecution', () => {
35
39
// For ERC20 transfer outside call
36
40
const recipientAccount = executorAccount ;
37
41
const ethContract = new Contract ( contracts . Erc20OZ . sierra . abi , ethAddress , provider ) ;
42
+ const call1 : Call = {
43
+ contractAddress : ethAddress ,
44
+ entrypoint : 'transfer' ,
45
+ calldata : {
46
+ recipient : recipientAccount . address ,
47
+ amount : cairo . uint256 ( 100 ) ,
48
+ } ,
49
+ } ;
50
+ const call2 : Call = {
51
+ contractAddress : ethAddress ,
52
+ entrypoint : 'transfer' ,
53
+ calldata : {
54
+ recipient : recipientAccount . address ,
55
+ amount : cairo . uint256 ( 200 ) ,
56
+ } ,
57
+ } ;
58
+ const now_seconds = Math . floor ( Date . now ( ) / 1000 ) ;
59
+ const hour_ago = ( now_seconds - 3600 ) . toString ( ) ;
60
+ const hour_later = ( now_seconds + 3600 ) . toString ( ) ;
38
61
39
62
beforeAll ( async ( ) => {
40
63
// Deploy the SNIP-9 signer account (ArgentX v 0.4.0, using SNIP-9 v2):
@@ -60,38 +83,22 @@ describe('Account and OutsideExecution', () => {
60
83
entrypoint : 'transfer' ,
61
84
calldata : {
62
85
recipient : signerAccount . address ,
63
- amount : cairo . uint256 ( 1000 ) ,
86
+ amount : cairo . uint256 ( 1300 ) ,
64
87
} ,
65
88
} ;
66
89
const { transaction_hash } = await executorAccount . execute ( transferCall ) ;
67
90
await provider . waitForTransaction ( transaction_hash ) ;
68
91
} ) ;
69
92
70
93
test ( 'getOutsideCall' , async ( ) => {
71
- const call1 : Call = {
72
- contractAddress : '0x0123' ,
73
- entrypoint : 'transfer' ,
74
- calldata : {
75
- recipient : '0xabcd' ,
76
- amount : cairo . uint256 ( 10 ) ,
77
- } ,
78
- } ;
79
94
expect ( outsideExecution . getOutsideCall ( call1 ) ) . toEqual ( {
80
- to : '0x0123' ,
95
+ to : ethAddress ,
81
96
selector : getSelectorFromName ( call1 . entrypoint ) ,
82
- calldata : [ '43981' , '10 ' , '0' ] ,
97
+ calldata : [ num . hexToDecimalString ( recipientAccount . address ) , '100 ' , '0' ] ,
83
98
} ) ;
84
99
} ) ;
85
100
86
101
test ( 'Build SNIP-9 v2 TypedData' , async ( ) => {
87
- const call1 : Call = {
88
- contractAddress : '0x0123' ,
89
- entrypoint : 'transfer' ,
90
- calldata : {
91
- recipient : '0xabcd' ,
92
- amount : cairo . uint256 ( 10 ) ,
93
- } ,
94
- } ;
95
102
const callOptions : OutsideExecutionOptions = {
96
103
caller : '0x1234' ,
97
104
execute_after : 100 ,
@@ -115,9 +122,9 @@ describe('Account and OutsideExecution', () => {
115
122
Caller : '0x1234' ,
116
123
Calls : [
117
124
{
118
- Calldata : [ '43981' , '10 ' , '0' ] ,
119
- Selector : '0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e' ,
120
- To : '0x0123' ,
125
+ Calldata : [ num . hexToDecimalString ( recipientAccount . address ) , '100 ' , '0' ] ,
126
+ Selector : getSelectorFromName ( call1 . entrypoint ) ,
127
+ To : ethAddress ,
121
128
} ,
122
129
] ,
123
130
'Execute After' : 100 ,
@@ -216,6 +223,48 @@ describe('Account and OutsideExecution', () => {
216
223
] ) ;
217
224
} ) ;
218
225
226
+ test ( 'buildExecuteFromOutsideCall' , async ( ) => {
227
+ const callOptions : OutsideExecutionOptions = {
228
+ caller : executorAccount . address ,
229
+ execute_after : hour_ago ,
230
+ execute_before : hour_later ,
231
+ } ;
232
+ const outsideTransaction1 : OutsideTransaction = await signerAccount . getOutsideTransaction (
233
+ callOptions ,
234
+ [ call1 , call2 ]
235
+ ) ;
236
+ const outsideExecutionCall : Call [ ] =
237
+ outsideExecution . buildExecuteFromOutsideCall ( outsideTransaction1 ) ;
238
+ expect ( outsideExecutionCall ) . toEqual ( [
239
+ {
240
+ calldata : [
241
+ num . hexToDecimalString ( recipientAccount . address ) ,
242
+ num . hexToDecimalString ( outsideTransaction1 . outsideExecution . nonce as string ) ,
243
+ outsideTransaction1 . outsideExecution . execute_after . toString ( ) ,
244
+ outsideTransaction1 . outsideExecution . execute_before . toString ( ) ,
245
+ '2' ,
246
+ '2087021424722619777119509474943472645767659996348769578120564519014510906823' ,
247
+ '232670485425082704932579856502088130646006032362877466777181098476241604910' ,
248
+ '3' ,
249
+ num . hexToDecimalString ( recipientAccount . address ) ,
250
+ '100' ,
251
+ '0' ,
252
+ '2087021424722619777119509474943472645767659996348769578120564519014510906823' ,
253
+ '232670485425082704932579856502088130646006032362877466777181098476241604910' ,
254
+ '3' ,
255
+ num . hexToDecimalString ( recipientAccount . address ) ,
256
+ '200' ,
257
+ '0' ,
258
+ '2' ,
259
+ ( outsideTransaction1 . signature as WeierstrassSignatureType ) . r . toString ( ) ,
260
+ ( outsideTransaction1 . signature as WeierstrassSignatureType ) . s . toString ( ) ,
261
+ ] ,
262
+ contractAddress : signerAccount . address ,
263
+ entrypoint : 'execute_from_outside_v2' ,
264
+ } ,
265
+ ] ) ;
266
+ } ) ;
267
+
219
268
test ( 'Signer account should support SNIP-9 v2' , async ( ) => {
220
269
expect ( await signerAccount . getSnip9Version ( ) ) . toBe ( OutsideExecutionVersion . V2 ) ;
221
270
} ) ;
@@ -227,9 +276,6 @@ describe('Account and OutsideExecution', () => {
227
276
} ) ;
228
277
229
278
test ( 'should build and execute outside transactions' , async ( ) => {
230
- const now_seconds = Math . floor ( Date . now ( ) / 1000 ) ;
231
- const hour_ago = ( now_seconds - 3600 ) . toString ( ) ;
232
- const hour_later = ( now_seconds + 3600 ) . toString ( ) ;
233
279
const callOptions : OutsideExecutionOptions = {
234
280
caller : executorAccount . address ,
235
281
execute_after : hour_ago ,
@@ -239,22 +285,6 @@ describe('Account and OutsideExecution', () => {
239
285
...callOptions ,
240
286
caller : 'ANY_CALLER' ,
241
287
} ;
242
- const call1 : Call = {
243
- contractAddress : ethAddress ,
244
- entrypoint : 'transfer' ,
245
- calldata : {
246
- recipient : recipientAccount . address ,
247
- amount : cairo . uint256 ( 100 ) ,
248
- } ,
249
- } ;
250
- const call2 : Call = {
251
- contractAddress : ethAddress ,
252
- entrypoint : 'transfer' ,
253
- calldata : {
254
- recipient : recipientAccount . address ,
255
- amount : cairo . uint256 ( 200 ) ,
256
- } ,
257
- } ;
258
288
const call3 : Call = {
259
289
contractAddress : ethAddress ,
260
290
entrypoint : 'transfer' ,
@@ -328,6 +358,49 @@ describe('Account and OutsideExecution', () => {
328
358
) ;
329
359
} ) ;
330
360
361
+ test ( 'estimate fees / simulate outsideExecution' , async ( ) => {
362
+ const callOptions : OutsideExecutionOptions = {
363
+ caller : executorAccount . address ,
364
+ execute_after : hour_ago ,
365
+ execute_before : hour_later ,
366
+ } ;
367
+ const outsideTransaction : OutsideTransaction = await signerAccount . getOutsideTransaction (
368
+ callOptions ,
369
+ [ call1 , call2 ]
370
+ ) ;
371
+ const outsideExecutionCall : Call [ ] =
372
+ outsideExecution . buildExecuteFromOutsideCall ( outsideTransaction ) ;
373
+ const estimateFee = await executorAccount . estimateFee ( outsideExecutionCall ) ;
374
+ expect ( Object . keys ( estimateFee ) ) . toEqual (
375
+ Object . keys ( {
376
+ overall_fee : 0 ,
377
+ gas_consumed : 0 ,
378
+ gas_price : 0 ,
379
+ unit : 0 ,
380
+ suggestedMaxFee : 0 ,
381
+ resourceBounds : 0 ,
382
+ data_gas_consumed : 0 ,
383
+ data_gas_price : 0 ,
384
+ } )
385
+ ) ;
386
+
387
+ const invocations : Invocations = [
388
+ {
389
+ type : TransactionType . INVOKE ,
390
+ payload : outsideExecutionCall ,
391
+ } ,
392
+ ] ;
393
+ const responseSimulate = await executorAccount . simulateTransaction ( invocations ) ;
394
+ expect ( Object . keys ( responseSimulate [ 0 ] ) ) . toEqual (
395
+ Object . keys ( {
396
+ transaction_trace : 0 ,
397
+ fee_estimation : 0 ,
398
+ suggestedMaxFee : 0 ,
399
+ resourceBounds : 0 ,
400
+ } )
401
+ ) ;
402
+ } ) ;
403
+
331
404
test ( 'ERC165 introspection' , async ( ) => {
332
405
const isSNIP9 = await src5 . supportsInterface (
333
406
provider ,
0 commit comments