From 33af45fb745e760ea6accca9efc1e9485f213c07 Mon Sep 17 00:00:00 2001 From: jaketimothy Date: Wed, 10 Aug 2022 16:47:33 -0700 Subject: [PATCH 1/2] assume unknown tx type is legacy --- .../transaction/src/transaction-factory.ts | 10 +------ .../ethereum/transaction/tests/index.test.ts | 29 ++++++++----------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/chains/ethereum/transaction/src/transaction-factory.ts b/src/chains/ethereum/transaction/src/transaction-factory.ts index 9d815e3fa3..dcb61647ee 100644 --- a/src/chains/ethereum/transaction/src/transaction-factory.ts +++ b/src/chains/ethereum/transaction/src/transaction-factory.ts @@ -38,8 +38,6 @@ function assertValidTransactionSValue(common: Common, tx: TypedTransaction) { } } -const UNTYPED_TX_START_BYTE = 0xc0; // all txs with first byte >= 0xc0 are untyped - export enum TransactionType { Legacy = 0x0, EIP2930AccessList = 0x1, @@ -265,14 +263,8 @@ export class TransactionFactory { type === TransactionType.EIP2930AccessList ) { return type; - } else if ( - type >= UNTYPED_TX_START_BYTE || - type === TransactionType.Legacy || - type === undefined - ) { - return TransactionType.Legacy; } else { - throw new Error(`Invalid transaction type: ${type}`); + return TransactionType.Legacy; } } diff --git a/src/chains/ethereum/transaction/tests/index.test.ts b/src/chains/ethereum/transaction/tests/index.test.ts index 796856f45f..358d3badd8 100644 --- a/src/chains/ethereum/transaction/tests/index.test.ts +++ b/src/chains/ethereum/transaction/tests/index.test.ts @@ -61,6 +61,12 @@ describe("@ganache/ethereum-transaction", async () => { type: "0x0", gasPrice: "0xffff" }; + const unknownTypeTx: Transaction = { + from: from, + to: to, + type: "0x55", + gasPrice: "0xffff" + }; const rawLegacyStrTx = "0xf8618082ffff80945a17650be84f28ed583e93e6ed0c99b1d1fc1b348080820a95a0d9c2d3cb65d7079f528d28d782fe752ed698381481f7b91790e067ea335c1dc0a0731131778ae061aa29567cc6b36fe3528092b687fb68c3f529493fca200c711d"; @@ -144,6 +150,12 @@ describe("@ganache/ethereum-transaction", async () => { ); assert.strictEqual(txFromRpc.type.toString(), "0x0"); }); + it("assumes legacy transaction if type unknown", () => { + txFromRpc = ( + TransactionFactory.fromRpc(unknownTypeTx, common) + ); + assert.strictEqual(txFromRpc.type.toString(), "0x0"); + }); it("generates legacy transactions from rpc data", async () => { txFromRpc = ( TransactionFactory.fromRpc(typedLegacyTx, common) @@ -557,17 +569,6 @@ describe("@ganache/ethereum-transaction", async () => { }); describe("Error and helper cases", () => { - it("does not allow unsupported tx types from rpc data", async () => { - const rpc: Transaction = { - from: from, - to: to, - type: "0x55", - gasPrice: "0xffff" - }; - assert.throws(() => { - TransactionFactory.fromRpc(rpc, common); - }); - }); it("does not allow unsupported tx types from raw buffer data", async () => { const db = [ Buffer.from("0x55"), @@ -590,12 +591,6 @@ describe("@ganache/ethereum-transaction", async () => { ); }); }); - it("does not allow unsupported tx types from raw string data", async () => { - const str: string = "0x55"; - assert.throws(() => { - TransactionFactory.fromString(str, common); - }); - }); it("gets tx type from raw data", async () => { const db = [ BUFFER_EMPTY, From 4df960ef085d70a6dcdf347e9d3034123a12e470 Mon Sep 17 00:00:00 2001 From: jaketimothy Date: Thu, 11 Aug 2022 13:38:43 -0700 Subject: [PATCH 2/2] rpc tx tests for type 106 and >106 --- .../ethereum/transaction/tests/index.test.ts | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/chains/ethereum/transaction/tests/index.test.ts b/src/chains/ethereum/transaction/tests/index.test.ts index 358d3badd8..a6a435b27c 100644 --- a/src/chains/ethereum/transaction/tests/index.test.ts +++ b/src/chains/ethereum/transaction/tests/index.test.ts @@ -61,12 +61,8 @@ describe("@ganache/ethereum-transaction", async () => { type: "0x0", gasPrice: "0xffff" }; - const unknownTypeTx: Transaction = { - from: from, - to: to, - type: "0x55", - gasPrice: "0xffff" - }; + + const UNTYPED_TX_START_BYTE = 0xc0; // all txs with first byte >= 0xc0 are untyped const rawLegacyStrTx = "0xf8618082ffff80945a17650be84f28ed583e93e6ed0c99b1d1fc1b348080820a95a0d9c2d3cb65d7079f528d28d782fe752ed698381481f7b91790e067ea335c1dc0a0731131778ae061aa29567cc6b36fe3528092b687fb68c3f529493fca200c711d"; @@ -151,6 +147,36 @@ describe("@ganache/ethereum-transaction", async () => { assert.strictEqual(txFromRpc.type.toString(), "0x0"); }); it("assumes legacy transaction if type unknown", () => { + const unknownTypeTx: Transaction = { + from: from, + to: to, + type: "0x55", + gasPrice: "0xffff" + }; + txFromRpc = ( + TransactionFactory.fromRpc(unknownTypeTx, common) + ); + assert.strictEqual(txFromRpc.type.toString(), "0x0"); + }); + it(`assumes legacy transaction if type ${UNTYPED_TX_START_BYTE}`, () => { + const unknownTypeTx = { + from: from, + to: to, + type: "0x" + UNTYPED_TX_START_BYTE.toString(16), + gasPrice: "0xffff" + }; + txFromRpc = ( + TransactionFactory.fromRpc(unknownTypeTx, common) + ); + assert.strictEqual(txFromRpc.type.toString(), "0x0"); + }); + it(`assumes legacy transaction if type > ${UNTYPED_TX_START_BYTE}`, () => { + const unknownTypeTx = { + from: from, + to: to, + type: "0x" + (UNTYPED_TX_START_BYTE + 1).toString(16), + gasPrice: "0xffff" + }; txFromRpc = ( TransactionFactory.fromRpc(unknownTypeTx, common) );