Skip to content

Commit 9c1e82e

Browse files
committed
Added EIP-4844 BLOb transactions (#4554).
1 parent a26ff77 commit 9c1e82e

File tree

5 files changed

+275
-40
lines changed

5 files changed

+275
-40
lines changed

docs.wrm/links/specs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ link-eip-2098 [EIP-2098](https://eips.ethereum.org/EIPS/eip-2098)
3131
link-eip-2304 [EIP-2304](https://eips.ethereum.org/EIPS/eip-2304)
3232
link-eip-2718 [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718)
3333
link-eip-2930 [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)
34+
link-eip-4844 [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844)
3435

3536
# Open Standards
3637
link-base58 [Base58](https://en.bitcoinwiki.org/wiki/Base58)

src.ts/_tests/test-transaction.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ describe("Tests Unsigned Transaction Serializing", function() {
6464
assert.equal(tx.unsignedSerialized, test.unsignedLondon, "unsignedLondon");
6565
});
6666
}
67+
68+
for (const test of tests) {
69+
if (!test.unsignedCancun) { continue; }
70+
it(`serialized unsigned cancun transaction: ${ test.name }`, function() {
71+
const txData = Object.assign({ }, test.transaction, { type: 3 });
72+
const tx = Transaction.from(txData);
73+
assert.equal(tx.unsignedSerialized, test.unsignedCancun, "unsignedCancun");
74+
});
75+
}
6776
});
6877

6978
describe("Tests Signed Transaction Serializing", function() {
@@ -127,6 +136,20 @@ describe("Tests Signed Transaction Serializing", function() {
127136
assert.equal(tx.serialized, test.signedLondon, "signedLondon");
128137
});
129138
}
139+
140+
for (const test of tests) {
141+
if (!test.signedCancun) { continue; }
142+
143+
it(`serialized signed Cancun transaction: ${ test.name }`, function() {
144+
const txData = Object.assign({ }, test.transaction, {
145+
type: 3,
146+
signature: test.signatureCancun
147+
});
148+
149+
const tx = Transaction.from(txData);
150+
assert.equal(tx.serialized, test.signedCancun, "signedCancun");
151+
});
152+
}
130153
});
131154

132155
function assertTxUint(actual: null | bigint, _expected: undefined | string, name: string): void {
@@ -227,6 +250,18 @@ describe("Tests Unsigned Transaction Parsing", function() {
227250
assertTxEqual(tx, expected);
228251
});
229252
}
253+
254+
for (const test of tests) {
255+
if (!test.unsignedCancun) { continue; }
256+
it(`parses unsigned Cancun transaction: ${ test.name }`, function() {
257+
const tx = Transaction.from(test.unsignedCancun);
258+
259+
const expected = addDefaults(test.transaction);
260+
expected.gasPrice = null;
261+
262+
assertTxEqual(tx, expected);
263+
});
264+
}
230265
});
231266

232267
describe("Tests Signed Transaction Parsing", function() {
@@ -277,6 +312,7 @@ describe("Tests Signed Transaction Parsing", function() {
277312
assert.equal(tx.isLegacy(), true, "isLegacy");
278313
assert.equal(tx.isBerlin(), false, "isBerlin");
279314
assert.equal(tx.isLondon(), false, "isLondon");
315+
assert.equal(tx.isCancun(), false, "isCancun");
280316

281317
assert.ok(!!tx.signature, "signature:!null")
282318
assert.equal(tx.signature.r, test.signatureEip155.r, "signature.r");
@@ -303,6 +339,7 @@ describe("Tests Signed Transaction Parsing", function() {
303339
assert.equal(tx.isLegacy(), false, "isLegacy");
304340
assert.equal(tx.isBerlin(), true, "isBerlin");
305341
assert.equal(tx.isLondon(), false, "isLondon");
342+
assert.equal(tx.isCancun(), false, "isCancun");
306343

307344
assert.ok(!!tx.signature, "signature:!null")
308345
assert.equal(tx.signature.r, test.signatureBerlin.r, "signature.r");
@@ -328,6 +365,7 @@ describe("Tests Signed Transaction Parsing", function() {
328365
assert.equal(tx.isLegacy(), false, "isLegacy");
329366
assert.equal(tx.isBerlin(), false, "isBerlin");
330367
assert.equal(tx.isLondon(), true, "isLondon");
368+
assert.equal(tx.isCancun(), false, "isCancun");
331369

332370
assert.ok(!!tx.signature, "signature:!null")
333371
assert.equal(tx.signature.r, test.signatureLondon.r, "signature.r");
@@ -339,6 +377,34 @@ describe("Tests Signed Transaction Parsing", function() {
339377
}
340378
});
341379
}
380+
381+
for (const test of tests) {
382+
if (!test.signedCancun) { continue; }
383+
it(`parses signed Cancun transaction: ${ test.name }`, function() {
384+
let tx = Transaction.from(test.signedCancun);
385+
386+
const expected = addDefaults(test.transaction);
387+
expected.gasPrice = null;
388+
389+
for (let i = 0; i < 2; i++) {
390+
assertTxEqual(tx, expected);
391+
392+
assert.equal(tx.typeName, "eip-4844", "typeName");
393+
assert.equal(tx.isLegacy(), false, "isLegacy");
394+
assert.equal(tx.isBerlin(), false, "isBerlin");
395+
assert.equal(tx.isLondon(), false, "isLondon");
396+
assert.equal(tx.isCancun(), true, "isCancun");
397+
398+
assert.ok(!!tx.signature, "signature:!null")
399+
assert.equal(tx.signature.r, test.signatureCancun.r, "signature.r");
400+
assert.equal(tx.signature.s, test.signatureCancun.s, "signature.s");
401+
assert.equal(tx.signature.yParity, parseInt(test.signatureCancun.v), "signature.v");
402+
403+
// Test cloning
404+
tx = tx.clone();
405+
}
406+
});
407+
}
342408
});
343409

344410
describe("Tests Transaction Parameters", function() {

src.ts/_tests/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,14 @@ export interface TestCaseTransaction {
217217
signedBerlin: string;
218218
unsignedLondon: string;
219219
signedLondon: string;
220+
unsignedCancun: string;
221+
signedCancun: string;
220222

221223
signatureLegacy: TestCaseTransactionSig;
222224
signatureEip155: TestCaseTransactionSig;
223225
signatureBerlin: TestCaseTransactionSig;
224226
signatureLondon: TestCaseTransactionSig;
227+
signatureCancun: TestCaseTransactionSig;
225228
}
226229

227230

0 commit comments

Comments
 (0)