1
+ import { Hex } from 'ox'
1
2
import { expect , test } from 'vitest'
2
3
3
4
import { accounts } from '~test/src/constants.js'
4
5
import { anvilOptimism } from '../../../test/src/anvil.js'
5
- import { type TransactionRequestEIP1559 , parseGwei } from '../../index.js'
6
- import { parseEther } from '../../utils/unit/parseEther.js'
6
+ import { optimism } from '../../chains/index.js'
7
+ import {
8
+ http ,
9
+ type TransactionRequestEIP1559 ,
10
+ createClient ,
11
+ } from '../../index.js'
7
12
import { estimateL1Gas } from './estimateL1Gas.js'
8
13
9
14
const optimismClient = anvilOptimism . getClient ( )
10
15
const optimismClientWithAccount = anvilOptimism . getClient ( { account : true } )
11
16
const optimismClientWithoutChain = anvilOptimism . getClient ( { chain : false } )
12
17
13
18
const baseTransaction = {
14
- maxFeePerGas : parseGwei ( '100' ) ,
15
- maxPriorityFeePerGas : parseGwei ( '1' ) ,
19
+ data : '0xdeadbeef' ,
16
20
to : accounts [ 1 ] . address ,
17
- value : parseEther ( '0.1' ) ,
18
21
} as const satisfies Omit < TransactionRequestEIP1559 , 'from' >
19
22
20
23
test ( 'default' , async ( ) => {
21
24
const gas = await estimateL1Gas ( optimismClientWithAccount , baseTransaction )
22
- expect ( gas ) . toBe ( 2028n )
25
+ expect ( gas ) . toBe ( 2004n )
23
26
} )
24
27
25
28
test ( 'minimal' , async ( ) => {
26
29
const gas = await estimateL1Gas ( optimismClientWithAccount , { } )
27
- expect ( gas ) . toBe ( 1600n )
30
+ expect ( gas ) . toBe ( 1604n )
28
31
} )
29
32
30
33
test ( 'args: account' , async ( ) => {
31
34
const gas = await estimateL1Gas ( optimismClient , {
32
35
...baseTransaction ,
33
36
account : accounts [ 0 ] . address ,
34
37
} )
35
- expect ( gas ) . toBe ( 2028n )
38
+ expect ( gas ) . toBe ( 2004n )
36
39
} )
37
40
38
41
test ( 'args: data' , async ( ) => {
39
42
const gas = await estimateL1Gas ( optimismClientWithAccount , {
40
43
...baseTransaction ,
41
44
data : '0x00000000000000000000000000000000000000000000000004fefa17b7240000' ,
42
45
} )
43
- expect ( gas ) . toBe ( 2244n )
46
+ expect ( gas ) . toBe ( 2156n )
44
47
} )
45
48
46
49
test ( 'args: gasPriceOracleAddress' , async ( ) => {
47
50
const gas = await estimateL1Gas ( optimismClientWithAccount , {
48
51
...baseTransaction ,
49
52
gasPriceOracleAddress : '0x420000000000000000000000000000000000000F' ,
50
53
} )
51
- expect ( gas ) . toBe ( 2028n )
54
+ expect ( gas ) . toBe ( 2004n )
52
55
} )
53
56
54
57
test ( 'args: nonce' , async ( ) => {
55
58
const gas = await estimateL1Gas ( optimismClientWithAccount , {
56
59
...baseTransaction ,
57
60
nonce : 69 ,
58
61
} )
59
- expect ( gas ) . toBe ( 2028n )
62
+ expect ( gas ) . toBe ( 2004n )
60
63
} )
61
64
62
65
test ( 'args: nullish chain' , async ( ) => {
@@ -65,5 +68,17 @@ test('args: nullish chain', async () => {
65
68
account : accounts [ 0 ] . address ,
66
69
chain : null ,
67
70
} )
68
- expect ( gas ) . toBe ( 2028n )
71
+ expect ( gas ) . toBe ( 2004n )
72
+ } )
73
+
74
+ test ( 'behavior: account with no funds' , async ( ) => {
75
+ const optimismClient = createClient ( {
76
+ chain : optimism ,
77
+ transport : http ( ) ,
78
+ } )
79
+ const gas = await estimateL1Gas ( optimismClient , {
80
+ ...baseTransaction ,
81
+ account : Hex . random ( 20 ) ,
82
+ } )
83
+ expect ( gas ) . toBeDefined ( )
69
84
} )
0 commit comments