@@ -94,9 +94,114 @@ describe('toRpc', () => {
9494 } )
9595} )
9696
97+ describe ( 'fromRpc' , ( ) => {
98+ test ( 'default' , ( ) => {
99+ const request = TransactionRequest . fromRpc ( {
100+ to : '0x0000000000000000000000000000000000000000' ,
101+ value : '0x2386f26fc10000' ,
102+ } )
103+ expect ( request ) . toMatchInlineSnapshot ( `
104+ {
105+ "to": "0x0000000000000000000000000000000000000000",
106+ "value": 10000000000000000n,
107+ }
108+ ` )
109+ } )
110+
111+ test ( 'behavior: all' , ( ) => {
112+ const request = TransactionRequest . fromRpc ( {
113+ accessList : [ ] ,
114+ authorizationList : [ ] ,
115+ blobs : [ '0xdeadbeef' ] ,
116+ blobVersionedHashes : [ '0xdeadbeef' ] ,
117+ chainId : '0x1' ,
118+ data : '0xdeadbeef' ,
119+ from : '0x0000000000000000000000000000000000000000' ,
120+ gas : '0xf4240' ,
121+ gasPrice : '0x3b9aca00' ,
122+ maxFeePerBlobGas : '0x3b9aca00' ,
123+ maxFeePerGas : '0x3b9aca00' ,
124+ maxPriorityFeePerGas : '0x3b9aca00' ,
125+ nonce : '0x1' ,
126+ to : '0x0000000000000000000000000000000000000000' ,
127+ type : '0x2' ,
128+ value : '0x3b9aca00' ,
129+ } )
130+ expect ( request ) . toMatchInlineSnapshot ( `
131+ {
132+ "accessList": [],
133+ "authorizationList": [],
134+ "blobVersionedHashes": [
135+ "0xdeadbeef",
136+ ],
137+ "blobs": [
138+ "0xdeadbeef",
139+ ],
140+ "chainId": 1,
141+ "data": "0xdeadbeef",
142+ "from": "0x0000000000000000000000000000000000000000",
143+ "gas": 1000000n,
144+ "gasPrice": 1000000000n,
145+ "maxFeePerBlobGas": 1000000000n,
146+ "maxFeePerGas": 1000000000n,
147+ "maxPriorityFeePerGas": 1000000000n,
148+ "nonce": 1n,
149+ "to": "0x0000000000000000000000000000000000000000",
150+ "type": "eip1559",
151+ "value": 1000000000n,
152+ }
153+ ` )
154+ } )
155+
156+ test ( 'behavior: input' , ( ) => {
157+ const request = TransactionRequest . fromRpc ( {
158+ input : '0xdeadbeef' ,
159+ } )
160+ expect ( request ) . toMatchInlineSnapshot ( `
161+ {
162+ "input": "0xdeadbeef",
163+ }
164+ ` )
165+ } )
166+
167+ test ( 'behavior: empty' , ( ) => {
168+ const request = TransactionRequest . fromRpc ( { } )
169+ expect ( request ) . toMatchInlineSnapshot ( '{}' )
170+ } )
171+
172+ test ( 'behavior: roundtrip' , ( ) => {
173+ const original : TransactionRequest . TransactionRequest = {
174+ accessList : [ ] ,
175+ authorizationList : [ ] ,
176+ blobs : [ '0xdeadbeef' ] ,
177+ blobVersionedHashes : [ '0xdeadbeef' ] ,
178+ chainId : 1 ,
179+ data : '0xdeadbeef' ,
180+ from : '0x0000000000000000000000000000000000000000' ,
181+ gas : 1000000n ,
182+ gasPrice : 1000000000n ,
183+ maxFeePerBlobGas : 1000000000n ,
184+ maxFeePerGas : 1000000000n ,
185+ maxPriorityFeePerGas : 1000000000n ,
186+ nonce : 1n ,
187+ to : '0x0000000000000000000000000000000000000000' ,
188+ type : 'eip1559' ,
189+ value : 1000000000n ,
190+ }
191+ const rpc = TransactionRequest . toRpc ( original )
192+ const converted = TransactionRequest . fromRpc ( rpc )
193+
194+ expect ( converted ) . toEqual ( {
195+ ...original ,
196+ input : '0xdeadbeef' ,
197+ } )
198+ } )
199+ } )
200+
97201test ( 'exports' , ( ) => {
98202 expect ( Object . keys ( TransactionRequest ) ) . toMatchInlineSnapshot ( `
99203 [
204+ "fromRpc",
100205 "toRpc",
101206 ]
102207 ` )
0 commit comments