Skip to content

Commit

Permalink
Ensure Schema compliance with execution-apis schema (#372)
Browse files Browse the repository at this point in the history
* Add openrpc integration tests

Signed-off-by: Anton Rusev <[email protected]>
  • Loading branch information
ar-conmit committed Jul 26, 2022
1 parent 5fd35e3 commit 5af00f9
Show file tree
Hide file tree
Showing 10 changed files with 778 additions and 56 deletions.
25 changes: 13 additions & 12 deletions docs/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"items": {
"title": "rewardPercentile",
"description": "Floating point value between 0 and 100.",
"type": "number"
"type": "number",
"pattern": "^[0-9][0-9]?$|^100$"
}
}
}
Expand Down Expand Up @@ -159,7 +160,9 @@
"description": "An array of gas used ratio.",
"type": "array",
"items": {
"$ref": "#/components/schemas/uint"
"title": "hex encoded unsigned integer",
"type": "string",
"pattern": "^0x([1-9a-f]+[0-9a-f]*|0|0.8)$"
}
},
"baseFeePerGas": {
Expand Down Expand Up @@ -358,11 +361,7 @@
"result": {
"name": "Log objects",
"schema": {
"title": "Filter results",
"type": "array",
"items": {
"$ref": "#/components/schemas/FilterResults"
}
"$ref": "#/components/schemas/FilterResults"
}
}
},
Expand Down Expand Up @@ -460,10 +459,7 @@
"name": "Transaction count",
"schema": {
"title": "Transaction count",
"type": "array",
"items": {
"$ref": "#/components/schemas/uint"
}
"$ref": "#/components/schemas/uint"
}
}
},
Expand Down Expand Up @@ -683,7 +679,7 @@
"name": "The current client version.",
"schema": {
"type": "string",
"pattern": "relay/<semanticVersion>"
"pattern": "relay\/[0-9]\\.[0-9]\\.[0-9]"
}
}
}
Expand Down Expand Up @@ -1378,6 +1374,11 @@
"title": "Error message",
"type": "string",
"pattern": "Unsupported JSON-RPC method"
},
"name": {
"title": "Error name",
"type": "string",
"pattern": "Method not found"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"start": "npx lerna exec --scope @hashgraph/json-rpc-server -- npm run start",
"start:docker": "docker run --name hedera-relay -d -p 7546:7546 ${npm_package_name}:latest",
"test": "npx lerna run test",
"openrpctest": "ts-mocha packages/server/tests/integration/openrpc.spec.ts",
"openrpctest": "ts-mocha packages/relay/tests/lib/openrpc.spec.ts --exit",
"integration:prerequisite": "ts-node packages/server/tests/helpers/prerequisite.ts"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export interface Eth {

getBlockByNumber(blockNum: string, showDetails: boolean): Promise<Block | null>;

getBlockTransactionCountByHash(hash: string): Promise<number | null>;
getBlockTransactionCountByHash(hash: string): Promise<string | null>;

getBlockTransactionCountByNumber(blockNum: string): Promise<number | null>
getBlockTransactionCountByNumber(blockNum: string): Promise<string | null>

getCode(address: string, blockNumber: string | null): Promise<string>;

Expand Down
22 changes: 13 additions & 9 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export class EthImpl implements Eth {
*
* @param hash
*/
async getBlockTransactionCountByHash(hash: string): Promise<number | null> {
async getBlockTransactionCountByHash(hash: string): Promise<string | null> {
this.logger.trace('getBlockTransactionCountByHash(hash=%s, showDetails=%o)', hash);
return this.mirrorNodeClient
.getBlock(hash)
Expand All @@ -545,7 +545,7 @@ export class EthImpl implements Eth {
* Gets the number of transaction in a block by its block number.
* @param blockNumOrTag
*/
async getBlockTransactionCountByNumber(blockNumOrTag: string): Promise<number | null> {
async getBlockTransactionCountByNumber(blockNumOrTag: string): Promise<string | null> {
this.logger.trace('getBlockTransactionCountByNumber(blockNum=%s, showDetails=%o)', blockNumOrTag);
const blockNum = await this.translateBlockTag(blockNumOrTag);
return this.mirrorNodeClient
Expand Down Expand Up @@ -751,13 +751,13 @@ export class EthImpl implements Eth {
input: contractResult.function_parameters,
maxPriorityFeePerGas: maxPriorityFee,
maxFeePerGas: maxFee,
nonce: contractResult.nonce,
nonce: EthImpl.nullableNumberTo0x(contractResult.nonce),
r: rSig,
s: sSig,
to: contractResult.to?.substring(0, 42),
transactionIndex: EthImpl.numberTo0x(contractResult.transaction_index),
type: contractResult.type,
v: contractResult.v,
type: EthImpl.nullableNumberTo0x(contractResult.type),
v: EthImpl.nullableNumberTo0x(contractResult.v),
value: EthImpl.numberTo0x(contractResult.amount),
});
}
Expand Down Expand Up @@ -836,6 +836,10 @@ export class EthImpl implements Eth {
return EthImpl.emptyHex + input.toString(16);
}

static nullableNumberTo0x(input: number | BigNumber): string | null {
return input === null ? null : EthImpl.numberTo0x(input);
}

static toHash32(value: string): string {
return value.substring(0, 66);
}
Expand Down Expand Up @@ -970,7 +974,7 @@ export class EthImpl implements Eth {
return null;
}

return block.count;
return EthImpl.numberTo0x(block.count);
}

private getTransactionFromContractResults(contractResults: any) {
Expand Down Expand Up @@ -1006,13 +1010,13 @@ export class EthImpl implements Eth {
input: contractResultDetails.function_parameters,
maxPriorityFeePerGas: EthImpl.toNullIfEmptyHex(contractResultDetails.max_priority_fee_per_gas),
maxFeePerGas: EthImpl.toNullIfEmptyHex(contractResultDetails.max_fee_per_gas),
nonce: contractResultDetails.nonce,
nonce: EthImpl.nullableNumberTo0x(contractResultDetails.nonce),
r: rSig,
s: sSig,
to: contractResultDetails.to.substring(0, 42),
transactionIndex: EthImpl.numberTo0x(contractResultDetails.transaction_index),
type: contractResultDetails.type,
v: contractResultDetails.v,
type: EthImpl.nullableNumberTo0x(contractResultDetails.type),
v: EthImpl.nullableNumberTo0x(contractResultDetails.v),
value: EthImpl.numberTo0x(contractResultDetails.amount),
});
})
Expand Down
Loading

0 comments on commit 5af00f9

Please sign in to comment.