|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { setup } from "./setup"; |
| 3 | + |
| 4 | +describe("signTransaction route", () => { |
| 5 | + test("Sign a legacy transaction", async () => { |
| 6 | + const { engine, backendWallet } = await setup(); |
| 7 | + |
| 8 | + const res = await engine.backendWallet.signTransaction(backendWallet, { |
| 9 | + transaction: { |
| 10 | + type: 0, |
| 11 | + chainId: 1, |
| 12 | + to: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 13 | + nonce: "42", |
| 14 | + gasLimit: "88000", |
| 15 | + gasPrice: "2000000000", |
| 16 | + value: "100000000000000000", |
| 17 | + }, |
| 18 | + }); |
| 19 | + |
| 20 | + expect(res.result).toEqual( |
| 21 | + "0xf86c2a8477359400830157c094152e208d08cd3ea1aa5d179b2e3eba7d1a733ef488016345785d8a00008026a05da3d31d9cfbb4026b6e187c81952199d567e182d9c2ecc72acf98e4e6ce4875a03b2815b79881092ab5a4f74e6725081d652becad8495b815c14abb56cc782041", |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + test("Sign an eip-1559 transaction", async () => { |
| 26 | + const { engine, backendWallet } = await setup(); |
| 27 | + |
| 28 | + const res = await engine.backendWallet.signTransaction(backendWallet, { |
| 29 | + transaction: { |
| 30 | + type: 1, |
| 31 | + chainId: 137, |
| 32 | + to: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 33 | + nonce: "42", |
| 34 | + gasLimit: "88000", |
| 35 | + maxFeePerGas: "2000000000", |
| 36 | + maxPriorityFeePerGas: "200000000", |
| 37 | + value: "100000000000000000", |
| 38 | + accessList: [ |
| 39 | + { |
| 40 | + address: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 41 | + storageKeys: [ |
| 42 | + "0x0000000000000000000000000000000000000000000000000000000000000001", |
| 43 | + ], |
| 44 | + }, |
| 45 | + ], |
| 46 | + }, |
| 47 | + }); |
| 48 | + |
| 49 | + expect(res.result).toEqual( |
| 50 | + "0x02f8ad81892a840bebc2008477359400830157c094152e208d08cd3ea1aa5d179b2e3eba7d1a733ef488016345785d8a000080f838f794152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4e1a0000000000000000000000000000000000000000000000000000000000000000180a050fd32589ec2e2b49b3bce79d9420474115490ea0693ada75a62d003c6ada1aaa06fbc93d08a7604fbca5c31af92a662ff6be3b5a9f75214b7cd5db5feab2fc444", |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
| 54 | + test("Sign an eip-2930 transaction", async () => { |
| 55 | + const { engine, backendWallet } = await setup(); |
| 56 | + |
| 57 | + const res = await engine.backendWallet.signTransaction(backendWallet, { |
| 58 | + transaction: { |
| 59 | + type: 2, |
| 60 | + chainId: 137, |
| 61 | + to: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 62 | + nonce: "42", |
| 63 | + gasLimit: "88000", |
| 64 | + value: "100000000000000000", |
| 65 | + accessList: [ |
| 66 | + { |
| 67 | + address: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 68 | + storageKeys: [ |
| 69 | + "0x0000000000000000000000000000000000000000000000000000000000000001", |
| 70 | + ], |
| 71 | + }, |
| 72 | + ], |
| 73 | + }, |
| 74 | + }); |
| 75 | + |
| 76 | + expect(res.result).toEqual( |
| 77 | + "0x01f8a481892a80830157c094152e208d08cd3ea1aa5d179b2e3eba7d1a733ef488016345785d8a000080f838f794152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4e1a0000000000000000000000000000000000000000000000000000000000000000101a0f690bdfb3b8431125dcb77933d3ebb0e5ae05bbd04ad83fa47b2f524013d4c0aa0096ca32df9a7586a4a11ebb72ce8e1902d633976a56ca184ae5009ae53c6bd16", |
| 78 | + ); |
| 79 | + }); |
| 80 | + |
| 81 | + test("Sign an eip-4844 transaction", async () => { |
| 82 | + const { engine, backendWallet } = await setup(); |
| 83 | + |
| 84 | + const res = await engine.backendWallet.signTransaction(backendWallet, { |
| 85 | + transaction: { |
| 86 | + type: 3, |
| 87 | + chainId: 137, |
| 88 | + to: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 89 | + nonce: "42", |
| 90 | + gasLimit: "88000", |
| 91 | + maxFeePerGas: "2000000000", |
| 92 | + maxPriorityFeePerGas: "200000000", |
| 93 | + value: "100000000000000000", |
| 94 | + accessList: [ |
| 95 | + { |
| 96 | + address: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 97 | + storageKeys: [ |
| 98 | + "0x0000000000000000000000000000000000000000000000000000000000000001", |
| 99 | + ], |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | + }); |
| 104 | + |
| 105 | + expect(res.result).toEqual( |
| 106 | + "0x03f8af81892a840bebc2008477359400830157c094152e208d08cd3ea1aa5d179b2e3eba7d1a733ef488016345785d8a000080f838f794152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4e1a0000000000000000000000000000000000000000000000000000000000000000180c001a0ec4fd401847092409ffb584cc34e816a322d0bc20f3599b4fe0a0182947fe5bea048daaf620c8b765c07b16ba083c457a90fa54062039d5d1c484e81d1577cc642", |
| 107 | + ); |
| 108 | + }); |
| 109 | + |
| 110 | + test("Sign an eip-7702 transaction", async () => { |
| 111 | + const { engine, backendWallet } = await setup(); |
| 112 | + |
| 113 | + const res = await engine.backendWallet.signTransaction(backendWallet, { |
| 114 | + transaction: { |
| 115 | + type: 4, |
| 116 | + chainId: 137, |
| 117 | + to: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 118 | + nonce: "42", |
| 119 | + gasLimit: "88000", |
| 120 | + maxFeePerGas: "2000000000", |
| 121 | + maxPriorityFeePerGas: "200000000", |
| 122 | + value: "100000000000000000", |
| 123 | + accessList: [ |
| 124 | + { |
| 125 | + address: "0x152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4", |
| 126 | + storageKeys: [ |
| 127 | + "0x0000000000000000000000000000000000000000000000000000000000000001", |
| 128 | + ], |
| 129 | + }, |
| 130 | + ], |
| 131 | + customData: { |
| 132 | + someCustomField: "customValue", |
| 133 | + }, |
| 134 | + }, |
| 135 | + }); |
| 136 | + |
| 137 | + expect(res.result).toEqual( |
| 138 | + "0x04f8ae81892a840bebc2008477359400830157c094152e208d08cd3ea1aa5d179b2e3eba7d1a733ef488016345785d8a000080f838f794152e208d08cd3ea1aa5d179b2e3eba7d1a733ef4e1a00000000000000000000000000000000000000000000000000000000000000001c080a028b866bcf94201d63d71d46505a17a9341d2c7c0f25f98f8e99d5a045b6dd342a03e8807e857830b3e09b300a87c7fedacecc81c3e2222a017be2e0573be011977", |
| 139 | + ); |
| 140 | + }); |
| 141 | +}); |
0 commit comments