Skip to content

Commit

Permalink
Fix eth_getТransactionByHash does not return accesslist and yparity…
Browse files Browse the repository at this point in the history
… for 1559 and 2930 transactions (#1696)

* replaces v to yParit for 1559 and 2930

Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>

* Fixes tests

Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>

* Fixes tests

Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>

---------

Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: ebadiere <ebadiere@gmail.com>
  • Loading branch information
konstantinabl authored and ebadiere committed Sep 18, 2023
1 parent 15b401b commit 3818a4f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
24 changes: 20 additions & 4 deletions docs/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,7 @@
},
"accessList": {
"title": "accessList",
"description": "not supported",
"$ref": "#/components/schemas/null"
"type" : "array"
},
"chainId": {
"title": "chainId",
Expand Down Expand Up @@ -1235,7 +1234,15 @@
"yParity": {
"title": "yParity",
"description": "The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.",
"$ref": "#/components/schemas/uint"
"oneOf": [
{
"$ref": "#/components/schemas/byte"
},
{
"$ref": "#/components/schemas/null"
}
]

},
"r": {
"title": "r",
Expand Down Expand Up @@ -1276,7 +1283,16 @@
"properties": {
"v": {
"title": "v",
"$ref": "#/components/schemas/uint"
"oneOf": [
{
"$ref": "#/components/schemas/uint"
},
{
"$ref": "#/components/schemas/null"
}
]


},
"r": {
"title": "r",
Expand Down
3 changes: 2 additions & 1 deletion packages/relay/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const formatContractResult = (cr: any) => {
to: cr.to?.substring(0, 42),
transactionIndex: nullableNumberTo0x(cr.transaction_index),
type: nullableNumberTo0x(cr.type),
v: nanOrNumberTo0x(cr.v),
v: cr.type === null ? null : nanOrNumberTo0x(cr.v),
value: nanOrNumberTo0x(cr.amount),
};

Expand All @@ -164,6 +164,7 @@ const formatContractResult = (cr: any) => {
}); // eip 2930 fields
case 2: return new Transaction1559({
...commonFields,
accessList: [],
maxPriorityFeePerGas: toNullIfEmptyHex(cr.max_priority_fee_per_gas),
maxFeePerGas: toNullIfEmptyHex(cr.max_fee_per_gas)
}); // eip 1559 fields
Expand Down
7 changes: 5 additions & 2 deletions packages/relay/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class Transaction {
public readonly to!: string | null;
public readonly transactionIndex!: string | null;
public readonly type!: string;
public readonly v!: string;
public readonly v: string | null;
public readonly value!: string;

constructor(args: any) {
Expand All @@ -159,9 +159,12 @@ export class Transaction {

export class Transaction2930 extends Transaction {
public readonly accessList!: AccessListEntry[] | null | [];
public readonly yParity! : string | null;

constructor(args: any) {
super(args);
const {v, ...parentArgs} = args;
super(parentArgs);
this.yParity = v;
this.accessList = args.accessList;
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/relay/tests/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class RelayAssertions {
expect(tx).to.exist;
if (tx == null) return;

expect(tx.accessList).to.eq(expectedTx.accessList);
expect(tx.accessList).to.deep.eq(expectedTx.accessList);
expect(tx.blockHash).to.eq(expectedTx.blockHash);
expect(tx.blockNumber).to.eq(expectedTx.blockNumber);
expect(tx.chainId).to.eq(expectedTx.chainId);
Expand All @@ -72,7 +72,11 @@ export default class RelayAssertions {
expect(tx.to).to.eq(expectedTx.to);
expect(tx.transactionIndex).to.eq(expectedTx.transactionIndex);
expect(tx.type).to.eq(numberTo0x(expectedTx.type));
expect(tx.v).to.eq(numberTo0x(expectedTx.v));
if(tx.type === "0x1" || tx.type === "0x2") {
expect(tx.yParity).to.eq(numberTo0x(expectedTx.v));
} else {
expect(tx.v).to.eq(numberTo0x(expectedTx.v));
}
expect(tx.value).to.eq(expectedTx.value);
};

Expand Down
6 changes: 3 additions & 3 deletions packages/relay/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,12 @@ export const defaultDetailedContractResultByHash = {
"value_written": "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"
}],
"status": "0x1",
"access_list": "0x",
"access_list": [],
"block_gas_used": 50000000,
"chain_id": "0x12a",
"gas_price": "0x4a817c80",
"max_fee_per_gas": "0x",
"max_priority_fee_per_gas": "0x",
"max_fee_per_gas": "0x55",
"max_priority_fee_per_gas": "0x43",
"r": "0xd693b532a80fed6392b428604171fb32fdbf953728a3a7ecc7d4062b1652c042",
"s": "0x24e9c602ac800b983b035700a14b23f78a253ab762deab5dc27e3555a750b354",
"type": 2,
Expand Down
5 changes: 3 additions & 2 deletions packages/relay/tests/lib/eth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4618,7 +4618,7 @@ describe('Eth', async function () {
const contractEvmAddress = '0xd8db0b1dbf8ba6721ef5256ad5fe07d72d1d04b9';
const defaultTxHash = '0x4a563af33c4871b51a8b108aa2fe1dd5280a30dfb7236170ae5e5e7957eb6392';
const defaultTransaction = {
"accessList": undefined,
"accessList": [],
"blockHash": "0xd693b532a80fed6392b428604171fb32fdbf953728a3a7ecc7d4062b1652c042",
"blockNumber": "0x11",
"chainId": "0x12a",
Expand Down Expand Up @@ -5171,7 +5171,8 @@ describe('Eth', async function () {
it('handles transactions with v as null', async function () {
const detailedResultsWithNullNullableValues = {
...defaultDetailedContractResultByHash,
v: null
v: null,
type: 0
};
const uniqueTxHash = '0xb4cad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';

Expand Down
8 changes: 5 additions & 3 deletions packages/relay/tests/lib/formatters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('Formatters', () => {

it('should return a valid match', () => {
const formattedResult: any = formatContractResult(contractResult);
expect(formattedResult.accessList).to.equal(undefined);
expect(formattedResult.accessList).to.deep.eq([]);
expect(formattedResult.blockHash).to.equal('0xb0f10139fa0bf9e66402c8c0e5ed364e07cf83b3726c8045fabf86a07f488713');
expect(formattedResult.blockNumber).to.equal('0x210');
expect(formattedResult.chainId).to.equal('0x12a');
Expand All @@ -217,7 +217,8 @@ describe('Formatters', () => {
expect(formattedResult.to).to.equal('0x0000000000000000000000000000000000000409');
expect(formattedResult.transactionIndex).to.equal('0x9');
expect(formattedResult.type).to.equal('0x2');
expect(formattedResult.v).to.equal('0x1');
expect(formattedResult.yParity).to.equal('0x1');
expect(formattedResult.v).to.equal(undefined);
expect(formattedResult.value).to.equal('0x0');
});

Expand Down Expand Up @@ -251,7 +252,8 @@ describe('Formatters', () => {
expect(formattedResult.s).to.equal(null);
expect(formattedResult.to).to.equal('0x0000000000000000000000000000000000000409');
expect(formattedResult.transactionIndex).to.equal(null);
expect(formattedResult.v).to.equal('0x0');
expect(formattedResult.v).to.equal(undefined);
expect(formattedResult.yParity).to.equal('0x0');
expect(formattedResult.value).to.equal('0x0');
});
});
Expand Down

0 comments on commit 3818a4f

Please sign in to comment.