Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'wip-4844' into wip-v6.11
  • Loading branch information
ricmoo committed Jan 31, 2024
2 parents c6e6c43 + 9c1e82e commit 561f7a0
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 40 deletions.
1 change: 1 addition & 0 deletions docs.wrm/links/specs.txt
Expand Up @@ -31,6 +31,7 @@ link-eip-2098 [EIP-2098](https://eips.ethereum.org/EIPS/eip-2098)
link-eip-2304 [EIP-2304](https://eips.ethereum.org/EIPS/eip-2304)
link-eip-2718 [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718)
link-eip-2930 [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)
link-eip-4844 [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844)

# Open Standards
link-base58 [Base58](https://en.bitcoinwiki.org/wiki/Base58)
Expand Down
66 changes: 66 additions & 0 deletions src.ts/_tests/test-transaction.ts
Expand Up @@ -64,6 +64,15 @@ describe("Tests Unsigned Transaction Serializing", function() {
assert.equal(tx.unsignedSerialized, test.unsignedLondon, "unsignedLondon");
});
}

for (const test of tests) {
if (!test.unsignedCancun) { continue; }
it(`serialized unsigned cancun transaction: ${ test.name }`, function() {
const txData = Object.assign({ }, test.transaction, { type: 3 });
const tx = Transaction.from(txData);
assert.equal(tx.unsignedSerialized, test.unsignedCancun, "unsignedCancun");
});
}
});

describe("Tests Signed Transaction Serializing", function() {
Expand Down Expand Up @@ -127,6 +136,20 @@ describe("Tests Signed Transaction Serializing", function() {
assert.equal(tx.serialized, test.signedLondon, "signedLondon");
});
}

for (const test of tests) {
if (!test.signedCancun) { continue; }

it(`serialized signed Cancun transaction: ${ test.name }`, function() {
const txData = Object.assign({ }, test.transaction, {
type: 3,
signature: test.signatureCancun
});

const tx = Transaction.from(txData);
assert.equal(tx.serialized, test.signedCancun, "signedCancun");
});
}
});

function assertTxUint(actual: null | bigint, _expected: undefined | string, name: string): void {
Expand Down Expand Up @@ -227,6 +250,18 @@ describe("Tests Unsigned Transaction Parsing", function() {
assertTxEqual(tx, expected);
});
}

for (const test of tests) {
if (!test.unsignedCancun) { continue; }
it(`parses unsigned Cancun transaction: ${ test.name }`, function() {
const tx = Transaction.from(test.unsignedCancun);

const expected = addDefaults(test.transaction);
expected.gasPrice = null;

assertTxEqual(tx, expected);
});
}
});

describe("Tests Signed Transaction Parsing", function() {
Expand Down Expand Up @@ -277,6 +312,7 @@ describe("Tests Signed Transaction Parsing", function() {
assert.equal(tx.isLegacy(), true, "isLegacy");
assert.equal(tx.isBerlin(), false, "isBerlin");
assert.equal(tx.isLondon(), false, "isLondon");
assert.equal(tx.isCancun(), false, "isCancun");

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

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

assert.ok(!!tx.signature, "signature:!null")
assert.equal(tx.signature.r, test.signatureLondon.r, "signature.r");
Expand All @@ -339,6 +377,34 @@ describe("Tests Signed Transaction Parsing", function() {
}
});
}

for (const test of tests) {
if (!test.signedCancun) { continue; }
it(`parses signed Cancun transaction: ${ test.name }`, function() {
let tx = Transaction.from(test.signedCancun);

const expected = addDefaults(test.transaction);
expected.gasPrice = null;

for (let i = 0; i < 2; i++) {
assertTxEqual(tx, expected);

assert.equal(tx.typeName, "eip-4844", "typeName");
assert.equal(tx.isLegacy(), false, "isLegacy");
assert.equal(tx.isBerlin(), false, "isBerlin");
assert.equal(tx.isLondon(), false, "isLondon");
assert.equal(tx.isCancun(), true, "isCancun");

assert.ok(!!tx.signature, "signature:!null")
assert.equal(tx.signature.r, test.signatureCancun.r, "signature.r");
assert.equal(tx.signature.s, test.signatureCancun.s, "signature.s");
assert.equal(tx.signature.yParity, parseInt(test.signatureCancun.v), "signature.v");

// Test cloning
tx = tx.clone();
}
});
}
});

describe("Tests Transaction Parameters", function() {
Expand Down
3 changes: 3 additions & 0 deletions src.ts/_tests/types.ts
Expand Up @@ -217,11 +217,14 @@ export interface TestCaseTransaction {
signedBerlin: string;
unsignedLondon: string;
signedLondon: string;
unsignedCancun: string;
signedCancun: string;

signatureLegacy: TestCaseTransactionSig;
signatureEip155: TestCaseTransactionSig;
signatureBerlin: TestCaseTransactionSig;
signatureLondon: TestCaseTransactionSig;
signatureCancun: TestCaseTransactionSig;
}


Expand Down

0 comments on commit 561f7a0

Please sign in to comment.