tempo.ts 0.11.1 → 0.12.1

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.
Files changed (228) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +3 -34
  3. package/dist/server/Handler.d.ts +14 -14
  4. package/dist/server/Handler.d.ts.map +1 -1
  5. package/dist/server/Handler.js +16 -17
  6. package/dist/server/Handler.js.map +1 -1
  7. package/dist/wagmi/Actions/amm.d.ts +51 -51
  8. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  9. package/dist/wagmi/Actions/amm.js +37 -37
  10. package/dist/wagmi/Actions/amm.js.map +1 -1
  11. package/dist/wagmi/Actions/dex.d.ts +129 -129
  12. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  13. package/dist/wagmi/Actions/dex.js +73 -73
  14. package/dist/wagmi/Actions/dex.js.map +1 -1
  15. package/dist/wagmi/Actions/faucet.d.ts +9 -9
  16. package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
  17. package/dist/wagmi/Actions/faucet.js +7 -7
  18. package/dist/wagmi/Actions/faucet.js.map +1 -1
  19. package/dist/wagmi/Actions/fee.d.ts +17 -17
  20. package/dist/wagmi/Actions/fee.d.ts.map +1 -1
  21. package/dist/wagmi/Actions/fee.js +10 -10
  22. package/dist/wagmi/Actions/fee.js.map +1 -1
  23. package/dist/wagmi/Actions/nonce.d.ts +9 -79
  24. package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
  25. package/dist/wagmi/Actions/nonce.js +7 -89
  26. package/dist/wagmi/Actions/nonce.js.map +1 -1
  27. package/dist/wagmi/Actions/policy.d.ts +69 -70
  28. package/dist/wagmi/Actions/policy.d.ts.map +1 -1
  29. package/dist/wagmi/Actions/policy.js +43 -43
  30. package/dist/wagmi/Actions/policy.js.map +1 -1
  31. package/dist/wagmi/Actions/reward.d.ts +51 -51
  32. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  33. package/dist/wagmi/Actions/reward.js +31 -31
  34. package/dist/wagmi/Actions/reward.js.map +1 -1
  35. package/dist/wagmi/Actions/token.d.ts +238 -238
  36. package/dist/wagmi/Actions/token.d.ts.map +1 -1
  37. package/dist/wagmi/Actions/token.js +136 -136
  38. package/dist/wagmi/Actions/token.js.map +1 -1
  39. package/dist/wagmi/Connector.d.ts +2 -1
  40. package/dist/wagmi/Connector.d.ts.map +1 -1
  41. package/dist/wagmi/Connector.js +83 -22
  42. package/dist/wagmi/Connector.js.map +1 -1
  43. package/dist/wagmi/Hooks/nonce.d.ts +1 -52
  44. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
  45. package/dist/wagmi/Hooks/nonce.js +1 -70
  46. package/dist/wagmi/Hooks/nonce.js.map +1 -1
  47. package/dist/wagmi/Hooks/policy.d.ts +0 -1
  48. package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/policy.js.map +1 -1
  50. package/dist/wagmi/KeyManager.d.ts +6 -3
  51. package/dist/wagmi/KeyManager.d.ts.map +1 -1
  52. package/dist/wagmi/KeyManager.js +9 -4
  53. package/dist/wagmi/KeyManager.js.map +1 -1
  54. package/package.json +3 -13
  55. package/src/server/Handler.test.ts +2 -2
  56. package/src/server/Handler.ts +16 -17
  57. package/src/wagmi/Actions/amm.ts +63 -63
  58. package/src/wagmi/Actions/dex.test.ts +1 -1
  59. package/src/wagmi/Actions/dex.ts +153 -153
  60. package/src/wagmi/Actions/faucet.ts +11 -11
  61. package/src/wagmi/Actions/fee.ts +20 -20
  62. package/src/wagmi/Actions/nonce.test.ts +1 -64
  63. package/src/wagmi/Actions/nonce.ts +10 -142
  64. package/src/wagmi/Actions/policy.ts +83 -85
  65. package/src/wagmi/Actions/reward.ts +64 -61
  66. package/src/wagmi/Actions/token.ts +287 -283
  67. package/src/wagmi/Connector.ts +105 -31
  68. package/src/wagmi/Hooks/dex.test.ts +1 -1
  69. package/src/wagmi/Hooks/fee.test.ts +0 -6
  70. package/src/wagmi/Hooks/nonce.test.ts +1 -66
  71. package/src/wagmi/Hooks/nonce.ts +1 -114
  72. package/src/wagmi/Hooks/policy.ts +0 -2
  73. package/src/wagmi/KeyManager.ts +18 -5
  74. package/dist/chains.d.ts +0 -73
  75. package/dist/chains.d.ts.map +0 -1
  76. package/dist/chains.js +0 -51
  77. package/dist/chains.js.map +0 -1
  78. package/dist/viem/Abis.d.ts +0 -2649
  79. package/dist/viem/Abis.d.ts.map +0 -1
  80. package/dist/viem/Abis.js +0 -1677
  81. package/dist/viem/Abis.js.map +0 -1
  82. package/dist/viem/Account.d.ts +0 -244
  83. package/dist/viem/Account.d.ts.map +0 -1
  84. package/dist/viem/Account.js +0 -382
  85. package/dist/viem/Account.js.map +0 -1
  86. package/dist/viem/Actions/account.d.ts +0 -40
  87. package/dist/viem/Actions/account.d.ts.map +0 -1
  88. package/dist/viem/Actions/account.js +0 -86
  89. package/dist/viem/Actions/account.js.map +0 -1
  90. package/dist/viem/Actions/amm.d.ts +0 -1991
  91. package/dist/viem/Actions/amm.d.ts.map +0 -1
  92. package/dist/viem/Actions/amm.js +0 -814
  93. package/dist/viem/Actions/amm.js.map +0 -1
  94. package/dist/viem/Actions/dex.d.ts +0 -3900
  95. package/dist/viem/Actions/dex.d.ts.map +0 -1
  96. package/dist/viem/Actions/dex.js +0 -1414
  97. package/dist/viem/Actions/dex.js.map +0 -1
  98. package/dist/viem/Actions/faucet.d.ts +0 -69
  99. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  100. package/dist/viem/Actions/faucet.js +0 -73
  101. package/dist/viem/Actions/faucet.js.map +0 -1
  102. package/dist/viem/Actions/fee.d.ts +0 -360
  103. package/dist/viem/Actions/fee.d.ts.map +0 -1
  104. package/dist/viem/Actions/fee.js +0 -237
  105. package/dist/viem/Actions/fee.js.map +0 -1
  106. package/dist/viem/Actions/index.d.ts +0 -10
  107. package/dist/viem/Actions/index.d.ts.map +0 -1
  108. package/dist/viem/Actions/index.js +0 -10
  109. package/dist/viem/Actions/index.js.map +0 -1
  110. package/dist/viem/Actions/nonce.d.ts +0 -257
  111. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  112. package/dist/viem/Actions/nonce.js +0 -228
  113. package/dist/viem/Actions/nonce.js.map +0 -1
  114. package/dist/viem/Actions/policy.d.ts +0 -1680
  115. package/dist/viem/Actions/policy.d.ts.map +0 -1
  116. package/dist/viem/Actions/policy.js +0 -875
  117. package/dist/viem/Actions/policy.js.map +0 -1
  118. package/dist/viem/Actions/reward.d.ts +0 -2422
  119. package/dist/viem/Actions/reward.d.ts.map +0 -1
  120. package/dist/viem/Actions/reward.js +0 -651
  121. package/dist/viem/Actions/reward.js.map +0 -1
  122. package/dist/viem/Actions/token.d.ts +0 -16007
  123. package/dist/viem/Actions/token.d.ts.map +0 -1
  124. package/dist/viem/Actions/token.js +0 -2936
  125. package/dist/viem/Actions/token.js.map +0 -1
  126. package/dist/viem/Addresses.d.ts +0 -9
  127. package/dist/viem/Addresses.d.ts.map +0 -1
  128. package/dist/viem/Addresses.js +0 -9
  129. package/dist/viem/Addresses.js.map +0 -1
  130. package/dist/viem/Chain.d.ts +0 -451
  131. package/dist/viem/Chain.d.ts.map +0 -1
  132. package/dist/viem/Chain.js +0 -96
  133. package/dist/viem/Chain.js.map +0 -1
  134. package/dist/viem/Decorator.d.ts +0 -2783
  135. package/dist/viem/Decorator.d.ts.map +0 -1
  136. package/dist/viem/Decorator.js +0 -137
  137. package/dist/viem/Decorator.js.map +0 -1
  138. package/dist/viem/Formatters.d.ts +0 -10
  139. package/dist/viem/Formatters.d.ts.map +0 -1
  140. package/dist/viem/Formatters.js +0 -104
  141. package/dist/viem/Formatters.js.map +0 -1
  142. package/dist/viem/P256.d.ts +0 -2
  143. package/dist/viem/P256.d.ts.map +0 -1
  144. package/dist/viem/P256.js +0 -2
  145. package/dist/viem/P256.js.map +0 -1
  146. package/dist/viem/Secp256k1.d.ts +0 -2
  147. package/dist/viem/Secp256k1.d.ts.map +0 -1
  148. package/dist/viem/Secp256k1.js +0 -2
  149. package/dist/viem/Secp256k1.js.map +0 -1
  150. package/dist/viem/Storage.d.ts +0 -24
  151. package/dist/viem/Storage.d.ts.map +0 -1
  152. package/dist/viem/Storage.js +0 -68
  153. package/dist/viem/Storage.js.map +0 -1
  154. package/dist/viem/TokenIds.d.ts +0 -2
  155. package/dist/viem/TokenIds.d.ts.map +0 -1
  156. package/dist/viem/TokenIds.js +0 -2
  157. package/dist/viem/TokenIds.js.map +0 -1
  158. package/dist/viem/Transaction.d.ts +0 -76
  159. package/dist/viem/Transaction.d.ts.map +0 -1
  160. package/dist/viem/Transaction.js +0 -176
  161. package/dist/viem/Transaction.js.map +0 -1
  162. package/dist/viem/Transport.d.ts +0 -33
  163. package/dist/viem/Transport.d.ts.map +0 -1
  164. package/dist/viem/Transport.js +0 -138
  165. package/dist/viem/Transport.js.map +0 -1
  166. package/dist/viem/WebAuthnP256.d.ts +0 -82
  167. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  168. package/dist/viem/WebAuthnP256.js +0 -97
  169. package/dist/viem/WebAuthnP256.js.map +0 -1
  170. package/dist/viem/WebCryptoP256.d.ts +0 -2
  171. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  172. package/dist/viem/WebCryptoP256.js +0 -2
  173. package/dist/viem/WebCryptoP256.js.map +0 -1
  174. package/dist/viem/index.d.ts +0 -26
  175. package/dist/viem/index.d.ts.map +0 -1
  176. package/dist/viem/index.js +0 -17
  177. package/dist/viem/index.js.map +0 -1
  178. package/dist/viem/internal/types.d.ts +0 -20
  179. package/dist/viem/internal/types.d.ts.map +0 -1
  180. package/dist/viem/internal/types.js +0 -2
  181. package/dist/viem/internal/types.js.map +0 -1
  182. package/dist/viem/internal/utils.d.ts +0 -14
  183. package/dist/viem/internal/utils.d.ts.map +0 -1
  184. package/dist/viem/internal/utils.js +0 -33
  185. package/dist/viem/internal/utils.js.map +0 -1
  186. package/src/chains.ts +0 -54
  187. package/src/viem/Abis.ts +0 -1688
  188. package/src/viem/Account.test.ts +0 -444
  189. package/src/viem/Account.ts +0 -601
  190. package/src/viem/Actions/account.test.ts +0 -414
  191. package/src/viem/Actions/account.ts +0 -106
  192. package/src/viem/Actions/amm.test.ts +0 -381
  193. package/src/viem/Actions/amm.ts +0 -1227
  194. package/src/viem/Actions/dex.test.ts +0 -1549
  195. package/src/viem/Actions/dex.ts +0 -2150
  196. package/src/viem/Actions/faucet.ts +0 -121
  197. package/src/viem/Actions/fee.test.ts +0 -259
  198. package/src/viem/Actions/fee.ts +0 -372
  199. package/src/viem/Actions/index.ts +0 -9
  200. package/src/viem/Actions/nonce.test.ts +0 -206
  201. package/src/viem/Actions/nonce.ts +0 -347
  202. package/src/viem/Actions/policy.test.ts +0 -534
  203. package/src/viem/Actions/policy.ts +0 -1335
  204. package/src/viem/Actions/reward.test.ts +0 -434
  205. package/src/viem/Actions/reward.ts +0 -944
  206. package/src/viem/Actions/token.test.ts +0 -3029
  207. package/src/viem/Actions/token.ts +0 -4458
  208. package/src/viem/Addresses.ts +0 -9
  209. package/src/viem/Chain.bench-d.ts +0 -12
  210. package/src/viem/Chain.test.ts +0 -168
  211. package/src/viem/Chain.ts +0 -157
  212. package/src/viem/Decorator.bench-d.ts +0 -11
  213. package/src/viem/Decorator.test.ts +0 -39
  214. package/src/viem/Decorator.ts +0 -3179
  215. package/src/viem/Formatters.ts +0 -164
  216. package/src/viem/P256.ts +0 -1
  217. package/src/viem/Secp256k1.ts +0 -1
  218. package/src/viem/Storage.ts +0 -110
  219. package/src/viem/TokenIds.ts +0 -1
  220. package/src/viem/Transaction.ts +0 -382
  221. package/src/viem/Transport.ts +0 -191
  222. package/src/viem/WebAuthnP256.ts +0 -146
  223. package/src/viem/WebCryptoP256.ts +0 -1
  224. package/src/viem/e2e.test.ts +0 -1602
  225. package/src/viem/index.ts +0 -30
  226. package/src/viem/internal/types.ts +0 -69
  227. package/src/viem/internal/utils.ts +0 -58
  228. package/src/wagmi/internal/types.ts +0 -16
@@ -1,1602 +0,0 @@
1
- import * as Http from 'node:http'
2
- import { createRequestListener } from '@remix-run/node-fetch-server'
3
- import { RpcRequest, RpcResponse, WebCryptoP256 } from 'ox'
4
- import { Account, Transaction } from 'tempo.ts/viem'
5
- import { publicActions, walletActions } from 'viem'
6
- import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
7
- import { defaultPrepareTransactionRequestParameters } from 'viem/actions'
8
- import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest'
9
- import { rpcUrl } from '../../test/config.js'
10
- import {
11
- accounts,
12
- client as client_,
13
- fundAddress,
14
- getClient,
15
- http,
16
- } from '../../test/viem/config.js'
17
- import * as actions from './Actions/index.js'
18
- import { tempoActions } from './index.js'
19
- import { withFeePayer } from './Transport.js'
20
-
21
- const client = client_
22
- .extend(publicActions)
23
- .extend(walletActions)
24
- .extend(tempoActions())
25
-
26
- describe('sendTransaction', () => {
27
- describe('secp256k1', () => {
28
- test('default', async () => {
29
- const account = accounts[0]
30
-
31
- const hash = await client.sendTransaction({
32
- account,
33
- data: '0xdeadbeef',
34
- to: '0x0000000000000000000000000000000000000000',
35
- })
36
- await client.waitForTransactionReceipt({ hash })
37
-
38
- const {
39
- blockHash,
40
- blockNumber,
41
- chainId,
42
- from,
43
- gas,
44
- gasPrice,
45
- hash: hash_,
46
- keyAuthorization: __,
47
- maxFeePerGas,
48
- maxPriorityFeePerGas,
49
- nonce,
50
- nonceKey,
51
- signature,
52
- transactionIndex,
53
- ...transaction
54
- } = await client.getTransaction({ hash })
55
-
56
- expect(blockHash).toBeDefined()
57
- expect(blockNumber).toBeDefined()
58
- expect(chainId).toBeDefined()
59
- expect(from).toBe(account.address.toLowerCase())
60
- expect(gas).toBeDefined()
61
- expect(gasPrice).toBeDefined()
62
- expect(hash_).toBe(hash)
63
- expect(maxFeePerGas).toBeDefined()
64
- expect(maxPriorityFeePerGas).toBeDefined()
65
- expect(nonce).toBeDefined()
66
- expect(nonceKey).toBeDefined()
67
- expect(signature).toBeDefined()
68
- expect(transactionIndex).toBeDefined()
69
- expect(transaction).toMatchInlineSnapshot(`
70
- {
71
- "accessList": [],
72
- "authorizationList": [],
73
- "calls": [
74
- {
75
- "data": "0xdeadbeef",
76
- "to": "0x0000000000000000000000000000000000000000",
77
- "value": 0n,
78
- },
79
- ],
80
- "data": undefined,
81
- "feePayerSignature": undefined,
82
- "feeToken": "0x20c0000000000000000000000000000000000001",
83
- "maxFeePerBlobGas": undefined,
84
- "to": null,
85
- "type": "tempo",
86
- "typeHex": "0x76",
87
- "v": undefined,
88
- "validAfter": null,
89
- "validBefore": null,
90
- "value": 0n,
91
- "yParity": undefined,
92
- }
93
- `)
94
- })
95
-
96
- test('with calls', async () => {
97
- const account = accounts[0]
98
-
99
- const hash = await client.sendTransaction({
100
- account,
101
- calls: [
102
- actions.token.create.call({
103
- admin: accounts[0].address,
104
- currency: 'USD',
105
- name: 'Test Token 3',
106
- symbol: 'TEST3',
107
- }),
108
- ],
109
- })
110
- await client.waitForTransactionReceipt({ hash })
111
-
112
- const {
113
- blockHash,
114
- blockNumber,
115
- calls,
116
- chainId,
117
- from,
118
- gas,
119
- gasPrice,
120
- hash: hash_,
121
- keyAuthorization: __,
122
- maxFeePerGas,
123
- maxPriorityFeePerGas,
124
- nonce,
125
- nonceKey,
126
- signature,
127
- transactionIndex,
128
- ...transaction
129
- } = await client.getTransaction({ hash })
130
-
131
- expect(blockHash).toBeDefined()
132
- expect(blockNumber).toBeDefined()
133
- expect(calls?.length).toBe(1)
134
- expect(chainId).toBeDefined()
135
- expect(from).toBe(account.address.toLowerCase())
136
- expect(gas).toBeDefined()
137
- expect(gasPrice).toBeDefined()
138
- expect(hash_).toBe(hash)
139
- expect(maxFeePerGas).toBeDefined()
140
- expect(maxPriorityFeePerGas).toBeDefined()
141
- expect(nonce).toBeDefined()
142
- expect(nonceKey).toBeDefined()
143
- expect(signature).toBeDefined()
144
- expect(transactionIndex).toBeDefined()
145
- expect(transaction).toMatchInlineSnapshot(`
146
- {
147
- "accessList": [],
148
- "authorizationList": [],
149
- "data": undefined,
150
- "feePayerSignature": undefined,
151
- "feeToken": "0x20c0000000000000000000000000000000000001",
152
- "maxFeePerBlobGas": undefined,
153
- "to": null,
154
- "type": "tempo",
155
- "typeHex": "0x76",
156
- "v": undefined,
157
- "validAfter": null,
158
- "validBefore": null,
159
- "value": 0n,
160
- "yParity": undefined,
161
- }
162
- `)
163
- })
164
-
165
- test('with feePayer', async () => {
166
- const account = privateKeyToAccount(generatePrivateKey())
167
- const feePayer = accounts[0]
168
-
169
- const hash = await client.sendTransaction({
170
- account,
171
- feePayer,
172
- to: '0x0000000000000000000000000000000000000000',
173
- })
174
- await client.waitForTransactionReceipt({ hash })
175
-
176
- const {
177
- blockHash,
178
- blockNumber,
179
- chainId,
180
- feePayerSignature,
181
- from,
182
- gas,
183
- gasPrice,
184
- hash: hash_,
185
- keyAuthorization: __,
186
- maxFeePerGas,
187
- maxPriorityFeePerGas,
188
- nonce,
189
- nonceKey,
190
- signature,
191
- transactionIndex,
192
- ...transaction
193
- } = await client.getTransaction({ hash })
194
-
195
- expect(blockHash).toBeDefined()
196
- expect(blockNumber).toBeDefined()
197
- expect(chainId).toBeDefined()
198
- expect(feePayerSignature).toBeDefined()
199
- expect(from).toBe(account.address.toLowerCase())
200
- expect(gas).toBeDefined()
201
- expect(gasPrice).toBeDefined()
202
- expect(hash_).toBe(hash)
203
- expect(maxFeePerGas).toBeDefined()
204
- expect(maxPriorityFeePerGas).toBeDefined()
205
- expect(nonce).toBeDefined()
206
- expect(nonceKey).toBeDefined()
207
- expect(signature).toBeDefined()
208
- expect(transactionIndex).toBeDefined()
209
- expect(transaction).toMatchInlineSnapshot(`
210
- {
211
- "accessList": [],
212
- "authorizationList": [],
213
- "calls": [
214
- {
215
- "data": "0x",
216
- "to": "0x0000000000000000000000000000000000000000",
217
- "value": 0n,
218
- },
219
- ],
220
- "data": undefined,
221
- "feeToken": "0x20c0000000000000000000000000000000000001",
222
- "maxFeePerBlobGas": undefined,
223
- "to": null,
224
- "type": "tempo",
225
- "typeHex": "0x76",
226
- "v": undefined,
227
- "validAfter": null,
228
- "validBefore": null,
229
- "value": 0n,
230
- "yParity": undefined,
231
- }
232
- `)
233
- })
234
-
235
- test('with access key', async () => {
236
- const account = accounts[0]
237
- const accessKey = Account.fromP256(generatePrivateKey(), {
238
- access: account,
239
- })
240
-
241
- const keyAuthorization = await account.signKeyAuthorization(accessKey)
242
- await account.assignKeyAuthorization(keyAuthorization)
243
-
244
- {
245
- const receipt = await client.sendTransactionSync({
246
- account: accessKey,
247
- })
248
- expect(receipt).toBeDefined()
249
- }
250
-
251
- // TODO: uncomment once unlimited spend supported
252
- // {
253
- // const receipt = await client.token.transferSync({
254
- // account: accessKey,
255
- // amount: 100n,
256
- // token: '0x20c0000000000000000000000000000000000001',
257
- // to: '0x0000000000000000000000000000000000000001',
258
- // })
259
- // expect(receipt).toBeDefined()
260
- // }
261
-
262
- {
263
- const receipt = await client.token.createSync({
264
- account: accessKey,
265
- admin: accessKey.address,
266
- currency: 'USD',
267
- name: 'Test Token 4',
268
- symbol: 'TEST4',
269
- })
270
- expect(receipt).toBeDefined()
271
- }
272
- })
273
-
274
- test('behavior: deploy contract', async () => {
275
- const account = accounts[0]
276
- const receipt = await client.sendTransactionSync({
277
- account,
278
- data: '0x608060405234801561001057600080fd5b50610ee0806100206000396000f3fe6080604052600436106100f35760003560e01c80634d2301cc1161008a578063a8b0574e11610059578063a8b0574e1461025a578063bce38bd714610275578063c3077fa914610288578063ee82ac5e1461029b57600080fd5b80634d2301cc146101ec57806372425d9d1461022157806382ad56cb1461023457806386d516e81461024757600080fd5b80633408e470116100c65780633408e47014610191578063399542e9146101a45780633e64a696146101c657806342cbb15c146101d957600080fd5b80630f28c97d146100f8578063174dea711461011a578063252dba421461013a57806327e86d6e1461015b575b600080fd5b34801561010457600080fd5b50425b6040519081526020015b60405180910390f35b61012d610128366004610a85565b6102ba565b6040516101119190610bbe565b61014d610148366004610a85565b6104ef565b604051610111929190610bd8565b34801561016757600080fd5b50437fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0140610107565b34801561019d57600080fd5b5046610107565b6101b76101b2366004610c60565b610690565b60405161011193929190610cba565b3480156101d257600080fd5b5048610107565b3480156101e557600080fd5b5043610107565b3480156101f857600080fd5b50610107610207366004610ce2565b73ffffffffffffffffffffffffffffffffffffffff163190565b34801561022d57600080fd5b5044610107565b61012d610242366004610a85565b6106ab565b34801561025357600080fd5b5045610107565b34801561026657600080fd5b50604051418152602001610111565b61012d610283366004610c60565b61085a565b6101b7610296366004610a85565b610a1a565b3480156102a757600080fd5b506101076102b6366004610d18565b4090565b60606000828067ffffffffffffffff8111156102d8576102d8610d31565b60405190808252806020026020018201604052801561031e57816020015b6040805180820190915260008152606060208201528152602001906001900390816102f65790505b5092503660005b8281101561047757600085828151811061034157610341610d60565b6020026020010151905087878381811061035d5761035d610d60565b905060200281019061036f9190610d8f565b6040810135958601959093506103886020850185610ce2565b73ffffffffffffffffffffffffffffffffffffffff16816103ac6060870187610dcd565b6040516103ba929190610e32565b60006040518083038185875af1925050503d80600081146103f7576040519150601f19603f3d011682016040523d82523d6000602084013e6103fc565b606091505b50602080850191909152901515808452908501351761046d577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b5050600101610325565b508234146104e6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f4d756c746963616c6c333a2076616c7565206d69736d6174636800000000000060448201526064015b60405180910390fd5b50505092915050565b436060828067ffffffffffffffff81111561050c5761050c610d31565b60405190808252806020026020018201604052801561053f57816020015b606081526020019060019003908161052a5790505b5091503660005b8281101561068657600087878381811061056257610562610d60565b90506020028101906105749190610e42565b92506105836020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166105a66020850185610dcd565b6040516105b4929190610e32565b6000604051808303816000865af19150503d80600081146105f1576040519150601f19603f3d011682016040523d82523d6000602084013e6105f6565b606091505b5086848151811061060957610609610d60565b602090810291909101015290508061067d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b50600101610546565b5050509250929050565b43804060606106a086868661085a565b905093509350939050565b6060818067ffffffffffffffff8111156106c7576106c7610d31565b60405190808252806020026020018201604052801561070d57816020015b6040805180820190915260008152606060208201528152602001906001900390816106e55790505b5091503660005b828110156104e657600084828151811061073057610730610d60565b6020026020010151905086868381811061074c5761074c610d60565b905060200281019061075e9190610e76565b925061076d6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166107906040850185610dcd565b60405161079e929190610e32565b6000604051808303816000865af19150503d80600081146107db576040519150601f19603f3d011682016040523d82523d6000602084013e6107e0565b606091505b506020808401919091529015158083529084013517610851577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b50600101610714565b6060818067ffffffffffffffff81111561087657610876610d31565b6040519080825280602002602001820160405280156108bc57816020015b6040805180820190915260008152606060208201528152602001906001900390816108945790505b5091503660005b82811015610a105760008482815181106108df576108df610d60565b602002602001015190508686838181106108fb576108fb610d60565b905060200281019061090d9190610e42565b925061091c6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff1661093f6020850185610dcd565b60405161094d929190610e32565b6000604051808303816000865af19150503d806000811461098a576040519150601f19603f3d011682016040523d82523d6000602084013e61098f565b606091505b506020830152151581528715610a07578051610a07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b506001016108c3565b5050509392505050565b6000806060610a2b60018686610690565b919790965090945092505050565b60008083601f840112610a4b57600080fd5b50813567ffffffffffffffff811115610a6357600080fd5b6020830191508360208260051b8501011115610a7e57600080fd5b9250929050565b60008060208385031215610a9857600080fd5b823567ffffffffffffffff811115610aaf57600080fd5b610abb85828601610a39565b90969095509350505050565b6000815180845260005b81811015610aed57602081850181015186830182015201610ad1565b81811115610aff576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b84811015610bb1578583037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001895281518051151584528401516040858501819052610b9d81860183610ac7565b9a86019a9450505090830190600101610b4f565b5090979650505050505050565b602081526000610bd16020830184610b32565b9392505050565b600060408201848352602060408185015281855180845260608601915060608160051b870101935082870160005b82811015610c52577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa0888703018452610c40868351610ac7565b95509284019290840190600101610c06565b509398975050505050505050565b600080600060408486031215610c7557600080fd5b83358015158114610c8557600080fd5b9250602084013567ffffffffffffffff811115610ca157600080fd5b610cad86828701610a39565b9497909650939450505050565b838152826020820152606060408201526000610cd96060830184610b32565b95945050505050565b600060208284031215610cf457600080fd5b813573ffffffffffffffffffffffffffffffffffffffff81168114610bd157600080fd5b600060208284031215610d2a57600080fd5b5035919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81833603018112610dc357600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112610e0257600080fd5b83018035915067ffffffffffffffff821115610e1d57600080fd5b602001915036819003821315610a7e57600080fd5b8183823760009101908152919050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112610dc357600080fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa1833603018112610dc357600080fdfea2646970667358221220bb2b5c71a328032f97c676ae39a1ec2148d3e5d6f73d95e9b17910152d61f16264736f6c634300080c0033',
279
- })
280
- expect(receipt.contractAddress).toBeDefined()
281
- })
282
-
283
- test('behavior: deploy contract + `feeToken` (tempo tx)', async () => {
284
- const account = accounts[0]
285
- const receipt = await client.sendTransactionSync({
286
- account,
287
- feeToken: 1n,
288
- data: '0x608060405234801561001057600080fd5b50610ee0806100206000396000f3fe6080604052600436106100f35760003560e01c80634d2301cc1161008a578063a8b0574e11610059578063a8b0574e1461025a578063bce38bd714610275578063c3077fa914610288578063ee82ac5e1461029b57600080fd5b80634d2301cc146101ec57806372425d9d1461022157806382ad56cb1461023457806386d516e81461024757600080fd5b80633408e470116100c65780633408e47014610191578063399542e9146101a45780633e64a696146101c657806342cbb15c146101d957600080fd5b80630f28c97d146100f8578063174dea711461011a578063252dba421461013a57806327e86d6e1461015b575b600080fd5b34801561010457600080fd5b50425b6040519081526020015b60405180910390f35b61012d610128366004610a85565b6102ba565b6040516101119190610bbe565b61014d610148366004610a85565b6104ef565b604051610111929190610bd8565b34801561016757600080fd5b50437fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0140610107565b34801561019d57600080fd5b5046610107565b6101b76101b2366004610c60565b610690565b60405161011193929190610cba565b3480156101d257600080fd5b5048610107565b3480156101e557600080fd5b5043610107565b3480156101f857600080fd5b50610107610207366004610ce2565b73ffffffffffffffffffffffffffffffffffffffff163190565b34801561022d57600080fd5b5044610107565b61012d610242366004610a85565b6106ab565b34801561025357600080fd5b5045610107565b34801561026657600080fd5b50604051418152602001610111565b61012d610283366004610c60565b61085a565b6101b7610296366004610a85565b610a1a565b3480156102a757600080fd5b506101076102b6366004610d18565b4090565b60606000828067ffffffffffffffff8111156102d8576102d8610d31565b60405190808252806020026020018201604052801561031e57816020015b6040805180820190915260008152606060208201528152602001906001900390816102f65790505b5092503660005b8281101561047757600085828151811061034157610341610d60565b6020026020010151905087878381811061035d5761035d610d60565b905060200281019061036f9190610d8f565b6040810135958601959093506103886020850185610ce2565b73ffffffffffffffffffffffffffffffffffffffff16816103ac6060870187610dcd565b6040516103ba929190610e32565b60006040518083038185875af1925050503d80600081146103f7576040519150601f19603f3d011682016040523d82523d6000602084013e6103fc565b606091505b50602080850191909152901515808452908501351761046d577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b5050600101610325565b508234146104e6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f4d756c746963616c6c333a2076616c7565206d69736d6174636800000000000060448201526064015b60405180910390fd5b50505092915050565b436060828067ffffffffffffffff81111561050c5761050c610d31565b60405190808252806020026020018201604052801561053f57816020015b606081526020019060019003908161052a5790505b5091503660005b8281101561068657600087878381811061056257610562610d60565b90506020028101906105749190610e42565b92506105836020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166105a66020850185610dcd565b6040516105b4929190610e32565b6000604051808303816000865af19150503d80600081146105f1576040519150601f19603f3d011682016040523d82523d6000602084013e6105f6565b606091505b5086848151811061060957610609610d60565b602090810291909101015290508061067d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b50600101610546565b5050509250929050565b43804060606106a086868661085a565b905093509350939050565b6060818067ffffffffffffffff8111156106c7576106c7610d31565b60405190808252806020026020018201604052801561070d57816020015b6040805180820190915260008152606060208201528152602001906001900390816106e55790505b5091503660005b828110156104e657600084828151811061073057610730610d60565b6020026020010151905086868381811061074c5761074c610d60565b905060200281019061075e9190610e76565b925061076d6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166107906040850185610dcd565b60405161079e929190610e32565b6000604051808303816000865af19150503d80600081146107db576040519150601f19603f3d011682016040523d82523d6000602084013e6107e0565b606091505b506020808401919091529015158083529084013517610851577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b50600101610714565b6060818067ffffffffffffffff81111561087657610876610d31565b6040519080825280602002602001820160405280156108bc57816020015b6040805180820190915260008152606060208201528152602001906001900390816108945790505b5091503660005b82811015610a105760008482815181106108df576108df610d60565b602002602001015190508686838181106108fb576108fb610d60565b905060200281019061090d9190610e42565b925061091c6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff1661093f6020850185610dcd565b60405161094d929190610e32565b6000604051808303816000865af19150503d806000811461098a576040519150601f19603f3d011682016040523d82523d6000602084013e61098f565b606091505b506020830152151581528715610a07578051610a07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b506001016108c3565b5050509392505050565b6000806060610a2b60018686610690565b919790965090945092505050565b60008083601f840112610a4b57600080fd5b50813567ffffffffffffffff811115610a6357600080fd5b6020830191508360208260051b8501011115610a7e57600080fd5b9250929050565b60008060208385031215610a9857600080fd5b823567ffffffffffffffff811115610aaf57600080fd5b610abb85828601610a39565b90969095509350505050565b6000815180845260005b81811015610aed57602081850181015186830182015201610ad1565b81811115610aff576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b84811015610bb1578583037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001895281518051151584528401516040858501819052610b9d81860183610ac7565b9a86019a9450505090830190600101610b4f565b5090979650505050505050565b602081526000610bd16020830184610b32565b9392505050565b600060408201848352602060408185015281855180845260608601915060608160051b870101935082870160005b82811015610c52577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa0888703018452610c40868351610ac7565b95509284019290840190600101610c06565b509398975050505050505050565b600080600060408486031215610c7557600080fd5b83358015158114610c8557600080fd5b9250602084013567ffffffffffffffff811115610ca157600080fd5b610cad86828701610a39565b9497909650939450505050565b838152826020820152606060408201526000610cd96060830184610b32565b95945050505050565b600060208284031215610cf457600080fd5b813573ffffffffffffffffffffffffffffffffffffffff81168114610bd157600080fd5b600060208284031215610d2a57600080fd5b5035919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81833603018112610dc357600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112610e0257600080fd5b83018035915067ffffffffffffffff821115610e1d57600080fd5b602001915036819003821315610a7e57600080fd5b8183823760009101908152919050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112610dc357600080fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa1833603018112610dc357600080fdfea2646970667358221220bb2b5c71a328032f97c676ae39a1ec2148d3e5d6f73d95e9b17910152d61f16264736f6c634300080c0033',
289
- })
290
- expect(receipt.contractAddress).toBeDefined()
291
- })
292
- })
293
-
294
- describe('p256', () => {
295
- test('default', async () => {
296
- const account = Account.fromP256(
297
- '0x6a3086fb3f2f95a3f36ef5387d18151ff51dc98a1e0eb987b159ba196beb0c99',
298
- )
299
-
300
- // fund account
301
- await fundAddress(client, { address: account.address })
302
-
303
- const receipt = await client.sendTransactionSync({
304
- account,
305
- data: '0xdeadbeef',
306
- to: '0x0000000000000000000000000000000000000000',
307
- })
308
-
309
- const {
310
- blockHash,
311
- blockNumber,
312
- chainId,
313
- from,
314
- gas,
315
- gasPrice,
316
- hash,
317
- keyAuthorization: __,
318
- maxFeePerGas,
319
- maxPriorityFeePerGas,
320
- nonce,
321
- nonceKey,
322
- signature,
323
- transactionIndex,
324
- ...transaction
325
- } = await client.getTransaction({
326
- hash: receipt.transactionHash,
327
- })
328
-
329
- expect(blockHash).toBeDefined()
330
- expect(blockNumber).toBeDefined()
331
- expect(chainId).toBeDefined()
332
- expect(from).toBe(account.address.toLowerCase())
333
- expect(gas).toBeDefined()
334
- expect(gasPrice).toBeDefined()
335
- expect(hash).toBe(receipt.transactionHash)
336
- expect(maxFeePerGas).toBeDefined()
337
- expect(maxPriorityFeePerGas).toBeDefined()
338
- expect(nonce).toBeDefined()
339
- expect(nonceKey).toBeDefined()
340
- expect(signature).toBeDefined()
341
- expect(transactionIndex).toBeDefined()
342
- expect(transaction).toMatchInlineSnapshot(`
343
- {
344
- "accessList": [],
345
- "authorizationList": [],
346
- "calls": [
347
- {
348
- "data": "0xdeadbeef",
349
- "to": "0x0000000000000000000000000000000000000000",
350
- "value": 0n,
351
- },
352
- ],
353
- "data": undefined,
354
- "feePayerSignature": undefined,
355
- "feeToken": "0x20c0000000000000000000000000000000000001",
356
- "maxFeePerBlobGas": undefined,
357
- "to": null,
358
- "type": "tempo",
359
- "typeHex": "0x76",
360
- "v": undefined,
361
- "validAfter": null,
362
- "validBefore": null,
363
- "value": 0n,
364
- "yParity": undefined,
365
- }
366
- `)
367
- })
368
-
369
- test('with calls', async () => {
370
- const account = Account.fromP256(
371
- '0x6a3086fb3f2f95a3f36ef5387d18151ff51dc98a1e0eb987b159ba196beb0c99',
372
- )
373
-
374
- // fund account
375
- await fundAddress(client, { address: account.address })
376
-
377
- const receipt = await client.sendTransactionSync({
378
- account,
379
- calls: [
380
- actions.token.create.call({
381
- admin: account.address,
382
- currency: 'USD',
383
- name: 'Test Token 4',
384
- symbol: 'TEST4',
385
- }),
386
- ],
387
- // TODO: remove once `eth_estimateGas` supports passing key type.
388
- gas: 100_000n,
389
- })
390
-
391
- const {
392
- blockHash,
393
- blockNumber,
394
- calls,
395
- chainId,
396
- from,
397
- gas,
398
- gasPrice,
399
- hash,
400
- keyAuthorization: __,
401
- maxFeePerGas,
402
- maxPriorityFeePerGas,
403
- nonce,
404
- nonceKey,
405
- signature,
406
- transactionIndex,
407
- ...transaction
408
- } = await client.getTransaction({
409
- hash: receipt.transactionHash,
410
- })
411
-
412
- expect(blockHash).toBeDefined()
413
- expect(blockNumber).toBeDefined()
414
- expect(calls?.length).toBe(1)
415
- expect(chainId).toBeDefined()
416
- expect(from).toBe(account.address.toLowerCase())
417
- expect(gas).toBeDefined()
418
- expect(gasPrice).toBeDefined()
419
- expect(hash).toBe(receipt.transactionHash)
420
- expect(maxFeePerGas).toBeDefined()
421
- expect(maxPriorityFeePerGas).toBeDefined()
422
- expect(nonce).toBeDefined()
423
- expect(nonceKey).toBeDefined()
424
- expect(signature).toBeDefined()
425
- expect(transactionIndex).toBeDefined()
426
- expect(transaction).toMatchInlineSnapshot(`
427
- {
428
- "accessList": [],
429
- "authorizationList": [],
430
- "data": undefined,
431
- "feePayerSignature": undefined,
432
- "feeToken": "0x20c0000000000000000000000000000000000001",
433
- "maxFeePerBlobGas": undefined,
434
- "to": null,
435
- "type": "tempo",
436
- "typeHex": "0x76",
437
- "v": undefined,
438
- "validAfter": null,
439
- "validBefore": null,
440
- "value": 0n,
441
- "yParity": undefined,
442
- }
443
- `)
444
- })
445
-
446
- test('with feePayer', async () => {
447
- const account = Account.fromP256(
448
- // unfunded account with different key
449
- '0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b',
450
- )
451
- const feePayer = accounts[0]
452
-
453
- const hash = await client.sendTransaction({
454
- account,
455
- feePayer,
456
- to: '0x0000000000000000000000000000000000000000',
457
- })
458
- await client.waitForTransactionReceipt({ hash })
459
-
460
- const {
461
- blockHash,
462
- blockNumber,
463
- chainId,
464
- feePayerSignature,
465
- from,
466
- gas,
467
- gasPrice,
468
- hash: hash_,
469
- keyAuthorization: __,
470
- maxFeePerGas,
471
- maxPriorityFeePerGas,
472
- nonce,
473
- nonceKey,
474
- signature,
475
- transactionIndex,
476
- ...transaction
477
- } = await client.getTransaction({ hash })
478
-
479
- expect(blockHash).toBeDefined()
480
- expect(blockNumber).toBeDefined()
481
- expect(chainId).toBeDefined()
482
- expect(feePayerSignature).toBeDefined()
483
- expect(from).toBe(account.address.toLowerCase())
484
- expect(gas).toBeDefined()
485
- expect(gasPrice).toBeDefined()
486
- expect(hash_).toBe(hash)
487
- expect(maxFeePerGas).toBeDefined()
488
- expect(maxPriorityFeePerGas).toBeDefined()
489
- expect(nonce).toBeDefined()
490
- expect(nonceKey).toBeDefined()
491
- expect(signature).toBeDefined()
492
- expect(transactionIndex).toBeDefined()
493
- expect(transaction).toMatchInlineSnapshot(`
494
- {
495
- "accessList": [],
496
- "authorizationList": [],
497
- "calls": [
498
- {
499
- "data": "0x",
500
- "to": "0x0000000000000000000000000000000000000000",
501
- "value": 0n,
502
- },
503
- ],
504
- "data": undefined,
505
- "feeToken": "0x20c0000000000000000000000000000000000001",
506
- "maxFeePerBlobGas": undefined,
507
- "to": null,
508
- "type": "tempo",
509
- "typeHex": "0x76",
510
- "v": undefined,
511
- "validAfter": null,
512
- "validBefore": null,
513
- "value": 0n,
514
- "yParity": undefined,
515
- }
516
- `)
517
- })
518
-
519
- test('with access key', async () => {
520
- const account = accounts[0]
521
- const accessKey = Account.fromP256(generatePrivateKey(), {
522
- access: account,
523
- })
524
-
525
- const keyAuthorization = await account.signKeyAuthorization(accessKey)
526
- await account.assignKeyAuthorization(keyAuthorization)
527
-
528
- {
529
- const receipt = await client.sendTransactionSync({
530
- account: accessKey,
531
- })
532
- expect(receipt).toBeDefined()
533
- }
534
-
535
- {
536
- const receipt = await client.sendTransactionSync({
537
- account: accessKey,
538
- to: '0x0000000000000000000000000000000000000000',
539
- })
540
- expect(receipt).toBeDefined()
541
- }
542
- })
543
-
544
- test('with access key + fee payer', async () => {
545
- const account = Account.fromP256(
546
- // unfunded account with different key
547
- '0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b',
548
- )
549
- const accessKey = Account.fromP256(generatePrivateKey(), {
550
- access: account,
551
- })
552
- const feePayer = accounts[0]
553
-
554
- const keyAuthorization = await account.signKeyAuthorization(accessKey)
555
- await account.assignKeyAuthorization(keyAuthorization)
556
-
557
- {
558
- const receipt = await client.sendTransactionSync({
559
- account: accessKey,
560
- feePayer,
561
- to: '0x0000000000000000000000000000000000000000',
562
- })
563
- expect(receipt).toBeDefined()
564
- }
565
-
566
- {
567
- const receipt = await client.sendTransactionSync({
568
- account: accessKey,
569
- feePayer,
570
- to: '0x0000000000000000000000000000000000000000',
571
- })
572
- expect(receipt).toBeDefined()
573
- }
574
- })
575
- })
576
-
577
- describe('webcrypto', () => {
578
- test('default', async () => {
579
- const keyPair = await WebCryptoP256.createKeyPair()
580
- const account = Account.fromWebCryptoP256(keyPair)
581
-
582
- // fund account
583
- await fundAddress(client, { address: account.address })
584
-
585
- const receipt = await client.sendTransactionSync({
586
- account,
587
- data: '0xdeadbeef',
588
- to: '0x0000000000000000000000000000000000000000',
589
- })
590
-
591
- const {
592
- blockHash,
593
- blockNumber,
594
- chainId,
595
- from,
596
- gasPrice,
597
- hash,
598
- keyAuthorization: __,
599
- maxFeePerGas,
600
- maxPriorityFeePerGas,
601
- nonce,
602
- nonceKey,
603
- signature,
604
- transactionIndex,
605
- ...transaction
606
- } = await client.getTransaction({
607
- hash: receipt.transactionHash,
608
- })
609
-
610
- expect(blockHash).toBeDefined()
611
- expect(blockNumber).toBeDefined()
612
- expect(chainId).toBeDefined()
613
- expect(from).toBeDefined()
614
- expect(gasPrice).toBeDefined()
615
- expect(hash).toBe(receipt.transactionHash)
616
- expect(maxFeePerGas).toBeDefined()
617
- expect(maxPriorityFeePerGas).toBeDefined()
618
- expect(nonce).toBeDefined()
619
- expect(nonceKey).toBeDefined()
620
- expect(signature).toBeDefined()
621
- expect(transactionIndex).toBeDefined()
622
- expect(transaction).toMatchInlineSnapshot(`
623
- {
624
- "accessList": [],
625
- "authorizationList": [],
626
- "calls": [
627
- {
628
- "data": "0xdeadbeef",
629
- "to": "0x0000000000000000000000000000000000000000",
630
- "value": 0n,
631
- },
632
- ],
633
- "data": undefined,
634
- "feePayerSignature": undefined,
635
- "feeToken": "0x20c0000000000000000000000000000000000001",
636
- "gas": 29012n,
637
- "maxFeePerBlobGas": undefined,
638
- "to": null,
639
- "type": "tempo",
640
- "typeHex": "0x76",
641
- "v": undefined,
642
- "validAfter": null,
643
- "validBefore": null,
644
- "value": 0n,
645
- "yParity": undefined,
646
- }
647
- `)
648
- })
649
-
650
- test('with calls', async () => {
651
- const keyPair = await WebCryptoP256.createKeyPair()
652
- const account = Account.fromWebCryptoP256(keyPair)
653
-
654
- // fund account
655
- await fundAddress(client, { address: account.address })
656
-
657
- const receipt = await client.sendTransactionSync({
658
- account,
659
- calls: [
660
- actions.token.create.call({
661
- admin: account.address,
662
- currency: 'USD',
663
- name: 'Test Token 5',
664
- symbol: 'TEST5',
665
- }),
666
- ],
667
- // TODO: remove once `eth_estimateGas` supports passing key type.
668
- gas: 100_000n,
669
- })
670
-
671
- const {
672
- blockHash,
673
- blockNumber,
674
- calls,
675
- chainId,
676
- from,
677
- gas,
678
- gasPrice,
679
- hash,
680
- keyAuthorization: __,
681
- maxFeePerGas,
682
- maxPriorityFeePerGas,
683
- nonce,
684
- signature,
685
- ...transaction
686
- } = await client.getTransaction({
687
- hash: receipt.transactionHash,
688
- })
689
-
690
- expect(blockHash).toBeDefined()
691
- expect(blockNumber).toBeDefined()
692
- expect(calls?.length).toBe(1)
693
- expect(chainId).toBeDefined()
694
- expect(from).toBeDefined()
695
- expect(gas).toBeDefined()
696
- expect(gasPrice).toBeDefined()
697
- expect(hash).toBe(receipt.transactionHash)
698
- expect(maxFeePerGas).toBeDefined()
699
- expect(maxPriorityFeePerGas).toBeDefined()
700
- expect(nonce).toBeDefined()
701
- expect(signature).toBeDefined()
702
- expect(transaction).toBeDefined()
703
- })
704
-
705
- test('with feePayer', async () => {
706
- const keyPair = await WebCryptoP256.createKeyPair()
707
- const account = Account.fromWebCryptoP256(keyPair)
708
- const feePayer = accounts[0]
709
-
710
- const hash = await client.sendTransaction({
711
- account,
712
- feePayer,
713
- to: '0x0000000000000000000000000000000000000000',
714
- })
715
- await client.waitForTransactionReceipt({ hash })
716
-
717
- const {
718
- blockHash,
719
- blockNumber,
720
- chainId,
721
- from,
722
- gasPrice,
723
- hash: hash_,
724
- keyAuthorization: __,
725
- maxFeePerGas,
726
- maxPriorityFeePerGas,
727
- nonce,
728
- signature,
729
- ...transaction
730
- } = await client.getTransaction({ hash })
731
-
732
- expect(blockHash).toBeDefined()
733
- expect(blockNumber).toBeDefined()
734
- expect(chainId).toBeDefined()
735
- expect(from).toBeDefined()
736
- expect(gasPrice).toBeDefined()
737
- expect(hash_).toBe(hash)
738
- expect(maxFeePerGas).toBeDefined()
739
- expect(maxPriorityFeePerGas).toBeDefined()
740
- expect(nonce).toBeDefined()
741
- expect(signature).toBeDefined()
742
- expect(transaction).toBeDefined()
743
- })
744
-
745
- test('with access key', async () => {
746
- const keyPair = await WebCryptoP256.createKeyPair()
747
- const account = Account.fromWebCryptoP256(keyPair)
748
- const accessKey = Account.fromWebCryptoP256(keyPair, {
749
- access: account,
750
- })
751
-
752
- // fund account
753
- await fundAddress(client, { address: account.address })
754
-
755
- const keyAuthorization = await account.signKeyAuthorization(accessKey)
756
- await account.assignKeyAuthorization(keyAuthorization)
757
-
758
- {
759
- const receipt = await client.sendTransactionSync({
760
- account: accessKey,
761
- })
762
- expect(receipt).toBeDefined()
763
- }
764
-
765
- {
766
- const receipt = await client.sendTransactionSync({
767
- account: accessKey,
768
- to: '0x0000000000000000000000000000000000000000',
769
- })
770
- expect(receipt).toBeDefined()
771
- }
772
- })
773
- })
774
-
775
- describe('webAuthn', () => {
776
- test('default', async () => {
777
- const account = Account.fromHeadlessWebAuthn(
778
- '0x6a3086fb3f2f95a3f36ef5387d18151ff51dc98a1e0eb987b159ba196beb0c99',
779
- {
780
- rpId: 'localhost',
781
- origin: 'http://localhost',
782
- },
783
- )
784
-
785
- // fund account
786
- await fundAddress(client, { address: account.address })
787
-
788
- const receipt = await client.sendTransactionSync({
789
- account,
790
- data: '0xdeadbeef',
791
- to: '0x0000000000000000000000000000000000000000',
792
- })
793
-
794
- const {
795
- blockHash,
796
- blockNumber,
797
- chainId,
798
- from,
799
- gas,
800
- gasPrice,
801
- hash,
802
- keyAuthorization: __,
803
- maxFeePerGas,
804
- maxPriorityFeePerGas,
805
- nonce,
806
- nonceKey,
807
- signature,
808
- transactionIndex,
809
- ...transaction
810
- } = await client.getTransaction({
811
- hash: receipt.transactionHash,
812
- })
813
-
814
- expect(blockHash).toBeDefined()
815
- expect(blockNumber).toBeDefined()
816
- expect(chainId).toBeDefined()
817
- expect(from).toBe(account.address.toLowerCase())
818
- expect(gas).toBeDefined()
819
- expect(gasPrice).toBeDefined()
820
- expect(hash).toBe(receipt.transactionHash)
821
- expect(maxFeePerGas).toBeDefined()
822
- expect(maxPriorityFeePerGas).toBeDefined()
823
- expect(nonce).toBeDefined()
824
- expect(nonceKey).toBeDefined()
825
- expect(signature).toBeDefined()
826
- expect(transactionIndex).toBeDefined()
827
- expect(transaction).toMatchInlineSnapshot(`
828
- {
829
- "accessList": [],
830
- "authorizationList": [],
831
- "calls": [
832
- {
833
- "data": "0xdeadbeef",
834
- "to": "0x0000000000000000000000000000000000000000",
835
- "value": 0n,
836
- },
837
- ],
838
- "data": undefined,
839
- "feePayerSignature": undefined,
840
- "feeToken": "0x20c0000000000000000000000000000000000001",
841
- "maxFeePerBlobGas": undefined,
842
- "to": null,
843
- "type": "tempo",
844
- "typeHex": "0x76",
845
- "v": undefined,
846
- "validAfter": null,
847
- "validBefore": null,
848
- "value": 0n,
849
- "yParity": undefined,
850
- }
851
- `)
852
- })
853
-
854
- test('with calls', async () => {
855
- const account = Account.fromHeadlessWebAuthn(
856
- '0x6a3086fb3f2f95a3f36ef5387d18151ff51dc98a1e0eb987b159ba196beb0c99',
857
- {
858
- rpId: 'localhost',
859
- origin: 'http://localhost',
860
- },
861
- )
862
-
863
- // fund account
864
- await fundAddress(client, { address: account.address })
865
-
866
- const receipt = await client.sendTransactionSync({
867
- account,
868
- calls: [
869
- actions.token.create.call({
870
- admin: account.address,
871
- currency: 'USD',
872
- name: 'Test Token 6',
873
- symbol: 'TEST6',
874
- }),
875
- ],
876
- // TODO: remove once `eth_estimateGas` supports passing key type.
877
- gas: 100_000n,
878
- })
879
-
880
- const {
881
- blockHash,
882
- blockNumber,
883
- calls,
884
- chainId,
885
- from,
886
- gas,
887
- gasPrice,
888
- hash,
889
- keyAuthorization: __,
890
- maxFeePerGas,
891
- maxPriorityFeePerGas,
892
- nonce,
893
- nonceKey,
894
- signature,
895
- transactionIndex,
896
- ...transaction
897
- } = await client.getTransaction({
898
- hash: receipt.transactionHash,
899
- })
900
-
901
- expect(blockHash).toBeDefined()
902
- expect(blockNumber).toBeDefined()
903
- expect(calls?.length).toBe(1)
904
- expect(chainId).toBeDefined()
905
- expect(from).toBe(account.address.toLowerCase())
906
- expect(gas).toBeDefined()
907
- expect(gasPrice).toBeDefined()
908
- expect(hash).toBe(receipt.transactionHash)
909
- expect(maxFeePerGas).toBeDefined()
910
- expect(maxPriorityFeePerGas).toBeDefined()
911
- expect(nonce).toBeDefined()
912
- expect(nonceKey).toBeDefined()
913
- expect(signature).toBeDefined()
914
- expect(transactionIndex).toBeDefined()
915
- expect(transaction).toMatchInlineSnapshot(`
916
- {
917
- "accessList": [],
918
- "authorizationList": [],
919
- "data": undefined,
920
- "feePayerSignature": undefined,
921
- "feeToken": "0x20c0000000000000000000000000000000000001",
922
- "maxFeePerBlobGas": undefined,
923
- "to": null,
924
- "type": "tempo",
925
- "typeHex": "0x76",
926
- "v": undefined,
927
- "validAfter": null,
928
- "validBefore": null,
929
- "value": 0n,
930
- "yParity": undefined,
931
- }
932
- `)
933
- })
934
-
935
- test('with feePayer', async () => {
936
- const account = Account.fromHeadlessWebAuthn(
937
- // unfunded account with different key
938
- '0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b',
939
- {
940
- rpId: 'localhost',
941
- origin: 'http://localhost',
942
- },
943
- )
944
- const feePayer = accounts[0]
945
-
946
- const hash = await client.sendTransaction({
947
- account,
948
- feePayer,
949
- to: '0x0000000000000000000000000000000000000000',
950
- })
951
- await client.waitForTransactionReceipt({ hash })
952
-
953
- const {
954
- blockHash,
955
- blockNumber,
956
- chainId,
957
- feePayerSignature,
958
- from,
959
- gas,
960
- gasPrice,
961
- hash: hash_,
962
- keyAuthorization: __,
963
- maxFeePerGas,
964
- maxPriorityFeePerGas,
965
- nonce,
966
- nonceKey,
967
- signature,
968
- transactionIndex,
969
- ...transaction
970
- } = await client.getTransaction({ hash })
971
-
972
- expect(blockHash).toBeDefined()
973
- expect(blockNumber).toBeDefined()
974
- expect(chainId).toBeDefined()
975
- expect(feePayerSignature).toBeDefined()
976
- expect(from).toBe(account.address.toLowerCase())
977
- expect(gas).toBeDefined()
978
- expect(gasPrice).toBeDefined()
979
- expect(hash_).toBe(hash)
980
- expect(maxFeePerGas).toBeDefined()
981
- expect(maxPriorityFeePerGas).toBeDefined()
982
- expect(nonce).toBeDefined()
983
- expect(nonceKey).toBeDefined()
984
- expect(signature).toBeDefined()
985
- expect(transactionIndex).toBeDefined()
986
- expect(transaction).toMatchInlineSnapshot(`
987
- {
988
- "accessList": [],
989
- "authorizationList": [],
990
- "calls": [
991
- {
992
- "data": "0x",
993
- "to": "0x0000000000000000000000000000000000000000",
994
- "value": 0n,
995
- },
996
- ],
997
- "data": undefined,
998
- "feeToken": "0x20c0000000000000000000000000000000000001",
999
- "maxFeePerBlobGas": undefined,
1000
- "to": null,
1001
- "type": "tempo",
1002
- "typeHex": "0x76",
1003
- "v": undefined,
1004
- "validAfter": null,
1005
- "validBefore": null,
1006
- "value": 0n,
1007
- "yParity": undefined,
1008
- }
1009
- `)
1010
- })
1011
-
1012
- test('with access key', async () => {
1013
- const account = Account.fromHeadlessWebAuthn(
1014
- '0x6a3086fb3f2f95a3f36ef5387d18151ff51dc98a1e0eb987b159ba196beb0c99',
1015
- {
1016
- rpId: 'localhost',
1017
- origin: 'http://localhost',
1018
- },
1019
- )
1020
- const accessKey = Account.fromP256(generatePrivateKey(), {
1021
- access: account,
1022
- })
1023
-
1024
- // fund account
1025
- await fundAddress(client, { address: account.address })
1026
-
1027
- const keyAuthorization = await account.signKeyAuthorization(accessKey)
1028
- await account.assignKeyAuthorization(keyAuthorization)
1029
-
1030
- {
1031
- const receipt = await client.sendTransactionSync({
1032
- account: accessKey,
1033
- })
1034
- expect(receipt).toBeDefined()
1035
- }
1036
-
1037
- {
1038
- const receipt = await client.sendTransactionSync({
1039
- account: accessKey,
1040
- to: '0x0000000000000000000000000000000000000000',
1041
- })
1042
- expect(receipt).toBeDefined()
1043
- }
1044
- })
1045
- })
1046
-
1047
- test('behavior: 2d nonces', async () => {
1048
- const account = accounts[0]
1049
-
1050
- // fund account
1051
- await fundAddress(client, { address: account.address })
1052
-
1053
- const receipts = await Promise.all([
1054
- client.sendTransactionSync({
1055
- account,
1056
- nonceKey: 'random',
1057
- to: '0x0000000000000000000000000000000000000000',
1058
- }),
1059
- client.sendTransactionSync({
1060
- account,
1061
- nonceKey: 'random',
1062
- to: '0x0000000000000000000000000000000000000000',
1063
- }),
1064
- ])
1065
-
1066
- expect(receipts[0].status).toBe('success')
1067
- expect(receipts[1].status).toBe('success')
1068
- expect(receipts[0].transactionHash).not.toBe(receipts[1].transactionHash)
1069
- })
1070
-
1071
- test('behavior: 2d nonces (implicit)', async () => {
1072
- const account = accounts[0]
1073
-
1074
- // fund account
1075
- await fundAddress(client, { address: account.address })
1076
-
1077
- const receipts = await Promise.all([
1078
- client.sendTransactionSync({
1079
- account,
1080
- to: '0x0000000000000000000000000000000000000000',
1081
- }),
1082
- client.sendTransactionSync({
1083
- account,
1084
- to: '0x0000000000000000000000000000000000000000',
1085
- }),
1086
- client.sendTransactionSync({
1087
- account,
1088
- to: '0x0000000000000000000000000000000000000000',
1089
- }),
1090
- ])
1091
-
1092
- const transactions = await Promise.all([
1093
- client.getTransaction({ hash: receipts[0].transactionHash }),
1094
- client.getTransaction({ hash: receipts[1].transactionHash }),
1095
- client.getTransaction({ hash: receipts[2].transactionHash }),
1096
- ])
1097
-
1098
- expect(transactions[0].nonceKey).toBe(0n)
1099
- expect(transactions[1].nonceKey).toBeGreaterThan(0n)
1100
- expect(transactions[2].nonceKey).toBeGreaterThan(0n)
1101
- })
1102
- })
1103
-
1104
- describe('signTransaction', () => {
1105
- test('default', async () => {
1106
- const account = privateKeyToAccount(
1107
- // unfunded PK
1108
- '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1109
- )
1110
- const feePayer = accounts[0]
1111
-
1112
- const request = await client.prepareTransactionRequest({
1113
- account,
1114
- data: '0xdeadbeef',
1115
- feePayer: true,
1116
- parameters: defaultPrepareTransactionRequestParameters,
1117
- to: '0xcafebabecafebabecafebabecafebabecafebabe',
1118
- })
1119
- let transaction = await client.signTransaction(request as never)
1120
-
1121
- transaction = await client.signTransaction({
1122
- ...Transaction.deserialize(transaction),
1123
- account,
1124
- feePayer,
1125
- } as never)
1126
- const hash = await client.sendRawTransaction({
1127
- serializedTransaction: transaction,
1128
- })
1129
-
1130
- await client.waitForTransactionReceipt({ hash })
1131
-
1132
- const {
1133
- blockHash,
1134
- blockNumber,
1135
- chainId,
1136
- feePayerSignature,
1137
- from,
1138
- gasPrice,
1139
- hash: hash_,
1140
- keyAuthorization: __,
1141
- maxFeePerGas,
1142
- maxPriorityFeePerGas,
1143
- nonce,
1144
- nonceKey,
1145
- signature,
1146
- transactionIndex,
1147
- ...transaction2
1148
- } = await client.getTransaction({ hash })
1149
-
1150
- expect(blockHash).toBeDefined()
1151
- expect(blockNumber).toBeDefined()
1152
- expect(chainId).toBeDefined()
1153
- expect(feePayerSignature).toBeDefined()
1154
- expect(from).toBe(account.address.toLowerCase())
1155
- expect(gasPrice).toBeDefined()
1156
- expect(hash_).toBe(hash)
1157
- expect(maxFeePerGas).toBeDefined()
1158
- expect(maxPriorityFeePerGas).toBeDefined()
1159
- expect(nonce).toBeDefined()
1160
- expect(nonceKey).toBeDefined()
1161
- expect(signature).toBeDefined()
1162
- expect(transactionIndex).toBeDefined()
1163
- expect(transaction2).toMatchInlineSnapshot(`
1164
- {
1165
- "accessList": [],
1166
- "authorizationList": [],
1167
- "calls": [
1168
- {
1169
- "data": "0xdeadbeef",
1170
- "to": "0xcafebabecafebabecafebabecafebabecafebabe",
1171
- "value": 0n,
1172
- },
1173
- ],
1174
- "data": undefined,
1175
- "feeToken": "0x20c0000000000000000000000000000000000001",
1176
- "gas": 24002n,
1177
- "maxFeePerBlobGas": undefined,
1178
- "to": null,
1179
- "type": "tempo",
1180
- "typeHex": "0x76",
1181
- "v": undefined,
1182
- "validAfter": null,
1183
- "validBefore": null,
1184
- "value": 0n,
1185
- "yParity": undefined,
1186
- }
1187
- `)
1188
- })
1189
- })
1190
-
1191
- describe('relay', () => {
1192
- const client = getClient({
1193
- transport: withFeePayer(http(), http('http://localhost:3050')),
1194
- })
1195
- .extend(tempoActions())
1196
- .extend(walletActions)
1197
- .extend(publicActions)
1198
- let server: Http.Server
1199
-
1200
- afterEach(async () => {
1201
- await fetch(`${rpcUrl}/restart`)
1202
- })
1203
-
1204
- beforeAll(async () => {
1205
- server = Http.createServer(
1206
- createRequestListener(async (r) => {
1207
- const client = getClient({
1208
- account: accounts[0],
1209
- }).extend(walletActions)
1210
-
1211
- const request = RpcRequest.from(await r.json())
1212
-
1213
- // Validate method
1214
- if (
1215
- (request as any).method !== 'eth_signRawTransaction' &&
1216
- request.method !== 'eth_sendRawTransaction' &&
1217
- request.method !== 'eth_sendRawTransactionSync'
1218
- )
1219
- return Response.json(
1220
- RpcResponse.from(
1221
- {
1222
- error: new RpcResponse.InvalidParamsError({
1223
- message:
1224
- 'service only supports `eth_signTransaction`, `eth_sendRawTransaction`, and `eth_sendRawTransactionSync`',
1225
- }),
1226
- },
1227
- { request },
1228
- ),
1229
- )
1230
-
1231
- const serialized = request.params?.[0] as `0x76${string}`
1232
- if (!serialized.startsWith('0x76'))
1233
- return Response.json(
1234
- RpcResponse.from(
1235
- {
1236
- error: new RpcResponse.InvalidParamsError({
1237
- message: 'service only supports `0x76` transactions',
1238
- }),
1239
- },
1240
- { request },
1241
- ),
1242
- )
1243
-
1244
- const transaction = Transaction.deserialize(serialized)
1245
- const serializedTransaction = await client.signTransaction({
1246
- ...transaction,
1247
- feePayer: client.account,
1248
- })
1249
-
1250
- // Handle based on RPC method
1251
- if ((request as any).method === 'eth_signRawTransaction') {
1252
- // Policy: 'sign-only' - Return signed transaction without broadcasting
1253
- return Response.json(
1254
- RpcResponse.from({ result: serializedTransaction }, { request }),
1255
- )
1256
- }
1257
-
1258
- // Policy: 'sign-and-broadcast' - Sign, broadcast, and return hash
1259
- const result = await client.request({
1260
- method: request.method,
1261
- params: [serializedTransaction],
1262
- } as never)
1263
-
1264
- return Response.json(RpcResponse.from({ result }, { request }))
1265
- }),
1266
- ).listen(3050)
1267
- })
1268
-
1269
- afterAll(() => {
1270
- server.close()
1271
- process.on('SIGINT', () => {
1272
- server.close()
1273
- process.exit(0)
1274
- })
1275
- process.on('SIGTERM', () => {
1276
- server.close()
1277
- process.exit(0)
1278
- })
1279
- })
1280
-
1281
- describe('secp256k1', () => {
1282
- test('default', async () => {
1283
- const account = privateKeyToAccount(
1284
- // unfunded PK
1285
- '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1286
- )
1287
-
1288
- const { receipt } = await client.fee.setUserTokenSync({
1289
- account,
1290
- feePayer: true,
1291
- token: 1n,
1292
- })
1293
-
1294
- const userToken = await client.fee.getUserToken({ account })
1295
- expect(userToken).toMatchInlineSnapshot(`
1296
- {
1297
- "address": "0x20C0000000000000000000000000000000000001",
1298
- "id": 1n,
1299
- }
1300
- `)
1301
-
1302
- const {
1303
- blockHash,
1304
- blockNumber,
1305
- chainId,
1306
- feePayerSignature,
1307
- from,
1308
- gas,
1309
- gasPrice,
1310
- hash,
1311
- keyAuthorization: __,
1312
- maxFeePerGas,
1313
- maxPriorityFeePerGas,
1314
- nonce,
1315
- nonceKey,
1316
- signature,
1317
- transactionIndex,
1318
- ...transaction
1319
- } = await client.getTransaction({ hash: receipt.transactionHash })
1320
-
1321
- expect(blockHash).toBeDefined()
1322
- expect(blockNumber).toBeDefined()
1323
- expect(chainId).toBeDefined()
1324
- expect(feePayerSignature).toBeDefined()
1325
- expect(from).toBe(account.address.toLowerCase())
1326
- expect(gas).toBeDefined()
1327
- expect(gasPrice).toBeDefined()
1328
- expect(hash).toBe(receipt.transactionHash)
1329
- expect(maxFeePerGas).toBeDefined()
1330
- expect(maxPriorityFeePerGas).toBeDefined()
1331
- expect(nonce).toBeDefined()
1332
- expect(nonceKey).toBeDefined()
1333
- expect(signature).toBeDefined()
1334
- expect(transactionIndex).toBeDefined()
1335
- expect(transaction).toMatchInlineSnapshot(`
1336
- {
1337
- "accessList": [],
1338
- "authorizationList": [],
1339
- "calls": [
1340
- {
1341
- "data": "0xe789744400000000000000000000000020c0000000000000000000000000000000000001",
1342
- "to": "0xfeec000000000000000000000000000000000000",
1343
- "value": 0n,
1344
- },
1345
- ],
1346
- "data": undefined,
1347
- "feeToken": "0x20c0000000000000000000000000000000000001",
1348
- "maxFeePerBlobGas": undefined,
1349
- "to": null,
1350
- "type": "tempo",
1351
- "typeHex": "0x76",
1352
- "v": undefined,
1353
- "validAfter": null,
1354
- "validBefore": null,
1355
- "value": 0n,
1356
- "yParity": undefined,
1357
- }
1358
- `)
1359
- })
1360
-
1361
- test('behavior: 2d nonces', async () => {
1362
- const account = privateKeyToAccount(
1363
- // unfunded PK
1364
- '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1365
- )
1366
-
1367
- const receipts = await Promise.all([
1368
- client.sendTransactionSync({
1369
- account,
1370
- feePayer: true,
1371
- to: '0x0000000000000000000000000000000000000000',
1372
- }),
1373
- client.sendTransactionSync({
1374
- account,
1375
- feePayer: true,
1376
- to: '0x0000000000000000000000000000000000000001',
1377
- }),
1378
- client.sendTransactionSync({
1379
- account,
1380
- feePayer: true,
1381
- to: '0x0000000000000000000000000000000000000002',
1382
- }),
1383
- ])
1384
-
1385
- expect(receipts.every((receipt) => receipt.status === 'success')).toBe(
1386
- true,
1387
- )
1388
- })
1389
-
1390
- test('behavior: policy: sign-and-broadcast', async () => {
1391
- const client = getClient({
1392
- transport: withFeePayer(http(), http('http://localhost:3050'), {
1393
- policy: 'sign-and-broadcast',
1394
- }),
1395
- }).extend(tempoActions())
1396
-
1397
- // unfunded account that needs sponsorship
1398
- const account = privateKeyToAccount(
1399
- '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1400
- )
1401
-
1402
- const { receipt } = await client.fee.setUserTokenSync({
1403
- account,
1404
- feePayer: true,
1405
- token: 1n,
1406
- })
1407
-
1408
- expect(receipt.status).toBe('success')
1409
- })
1410
- })
1411
-
1412
- describe('p256', () => {
1413
- test('default', async () => {
1414
- const account = Account.fromP256(
1415
- '0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b',
1416
- )
1417
-
1418
- const { receipt } = await client.fee.setUserTokenSync({
1419
- account,
1420
- feePayer: true,
1421
- token: 1n,
1422
- })
1423
-
1424
- const userToken = await client.fee.getUserToken({ account })
1425
- expect(userToken).toMatchInlineSnapshot(`
1426
- {
1427
- "address": "0x20C0000000000000000000000000000000000001",
1428
- "id": 1n,
1429
- }
1430
- `)
1431
-
1432
- const {
1433
- blockHash,
1434
- blockNumber,
1435
- chainId,
1436
- feePayerSignature,
1437
- from,
1438
- gas,
1439
- gasPrice,
1440
- hash,
1441
- keyAuthorization: __,
1442
- maxFeePerGas,
1443
- maxPriorityFeePerGas,
1444
- nonce,
1445
- nonceKey,
1446
- signature,
1447
- transactionIndex,
1448
- ...transaction
1449
- } = await client.getTransaction({ hash: receipt.transactionHash })
1450
-
1451
- expect(blockHash).toBeDefined()
1452
- expect(blockNumber).toBeDefined()
1453
- expect(chainId).toBeDefined()
1454
- expect(feePayerSignature).toBeDefined()
1455
- expect(from).toBe(account.address.toLowerCase())
1456
- expect(gas).toBeDefined()
1457
- expect(gasPrice).toBeDefined()
1458
- expect(hash).toBe(receipt.transactionHash)
1459
- expect(maxFeePerGas).toBeDefined()
1460
- expect(maxPriorityFeePerGas).toBeDefined()
1461
- expect(nonce).toBeDefined()
1462
- expect(nonceKey).toBeDefined()
1463
- expect(signature).toBeDefined()
1464
- expect(transactionIndex).toBeDefined()
1465
- expect(transaction).toMatchInlineSnapshot(`
1466
- {
1467
- "accessList": [],
1468
- "authorizationList": [],
1469
- "calls": [
1470
- {
1471
- "data": "0xe789744400000000000000000000000020c0000000000000000000000000000000000001",
1472
- "to": "0xfeec000000000000000000000000000000000000",
1473
- "value": 0n,
1474
- },
1475
- ],
1476
- "data": undefined,
1477
- "feeToken": "0x20c0000000000000000000000000000000000001",
1478
- "maxFeePerBlobGas": undefined,
1479
- "to": null,
1480
- "type": "tempo",
1481
- "typeHex": "0x76",
1482
- "v": undefined,
1483
- "validAfter": null,
1484
- "validBefore": null,
1485
- "value": 0n,
1486
- "yParity": undefined,
1487
- }
1488
- `)
1489
- })
1490
- })
1491
-
1492
- describe('webcrypto', () => {
1493
- test('default', async () => {
1494
- const keyPair = await WebCryptoP256.createKeyPair()
1495
- const account = Account.fromWebCryptoP256(keyPair)
1496
-
1497
- const { receipt } = await client.fee.setUserTokenSync({
1498
- account,
1499
- feePayer: true,
1500
- token: 1n,
1501
- })
1502
-
1503
- const userToken = await client.fee.getUserToken({ account })
1504
- expect(userToken).toMatchInlineSnapshot(`
1505
- {
1506
- "address": "0x20C0000000000000000000000000000000000001",
1507
- "id": 1n,
1508
- }
1509
- `)
1510
-
1511
- const transaction = await client.getTransaction({
1512
- hash: receipt.transactionHash,
1513
- })
1514
-
1515
- expect(transaction).toBeDefined()
1516
- })
1517
- })
1518
-
1519
- describe('webAuthn', () => {
1520
- test('default', async () => {
1521
- const account = Account.fromHeadlessWebAuthn(
1522
- '0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b',
1523
- {
1524
- rpId: 'localhost',
1525
- origin: 'http://localhost',
1526
- },
1527
- )
1528
-
1529
- const { receipt } = await client.fee.setUserTokenSync({
1530
- account,
1531
- feePayer: true,
1532
- token: 1n,
1533
- })
1534
-
1535
- const userToken = await client.fee.getUserToken({ account })
1536
- expect(userToken).toMatchInlineSnapshot(`
1537
- {
1538
- "address": "0x20C0000000000000000000000000000000000001",
1539
- "id": 1n,
1540
- }
1541
- `)
1542
-
1543
- const {
1544
- blockHash,
1545
- blockNumber,
1546
- chainId,
1547
- feePayerSignature,
1548
- from,
1549
- gas,
1550
- gasPrice,
1551
- hash,
1552
- keyAuthorization: __,
1553
- maxFeePerGas,
1554
- maxPriorityFeePerGas,
1555
- nonce,
1556
- nonceKey,
1557
- signature,
1558
- transactionIndex,
1559
- ...transaction
1560
- } = await client.getTransaction({ hash: receipt.transactionHash })
1561
-
1562
- expect(blockHash).toBeDefined()
1563
- expect(blockNumber).toBeDefined()
1564
- expect(chainId).toBeDefined()
1565
- expect(feePayerSignature).toBeDefined()
1566
- expect(from).toBe(account.address.toLowerCase())
1567
- expect(gas).toBeDefined()
1568
- expect(gasPrice).toBeDefined()
1569
- expect(hash).toBe(receipt.transactionHash)
1570
- expect(maxFeePerGas).toBeDefined()
1571
- expect(maxPriorityFeePerGas).toBeDefined()
1572
- expect(nonce).toBeDefined()
1573
- expect(nonceKey).toBeDefined()
1574
- expect(signature).toBeDefined()
1575
- expect(transactionIndex).toBeDefined()
1576
- expect(transaction).toMatchInlineSnapshot(`
1577
- {
1578
- "accessList": [],
1579
- "authorizationList": [],
1580
- "calls": [
1581
- {
1582
- "data": "0xe789744400000000000000000000000020c0000000000000000000000000000000000001",
1583
- "to": "0xfeec000000000000000000000000000000000000",
1584
- "value": 0n,
1585
- },
1586
- ],
1587
- "data": undefined,
1588
- "feeToken": "0x20c0000000000000000000000000000000000001",
1589
- "maxFeePerBlobGas": undefined,
1590
- "to": null,
1591
- "type": "tempo",
1592
- "typeHex": "0x76",
1593
- "v": undefined,
1594
- "validAfter": null,
1595
- "validBefore": null,
1596
- "value": 0n,
1597
- "yParity": undefined,
1598
- }
1599
- `)
1600
- })
1601
- })
1602
- })