-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(evm-api): implement
net_version
(#792)
* Add net_version * Register handler * Return nethash * Add test
- Loading branch information
1 parent
28ce419
commit 7a9b32b
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Identifiers } from "@mainsail/contracts"; | ||
import { Validator } from "@mainsail/validation"; | ||
|
||
import { describe, Sandbox } from "../../../test-framework/source"; | ||
import { NetVersion } from "./index.js"; | ||
|
||
describe<{ | ||
sandbox: Sandbox; | ||
action: NetVersion; | ||
validator: Validator; | ||
}>("NetVersion", ({ beforeEach, it, assert }) => { | ||
const version = "0.0.1"; | ||
|
||
beforeEach(async (context) => { | ||
context.sandbox = new Sandbox(); | ||
|
||
context.sandbox.app.bind(Identifiers.Cryptography.Configuration).toConstantValue({ | ||
get: () => "nethash", | ||
}); | ||
|
||
context.action = context.sandbox.app.resolve(NetVersion); | ||
context.validator = context.sandbox.app.resolve(Validator); | ||
}); | ||
|
||
it("should have a name", ({ action }) => { | ||
assert.equal(action.name, "net_version"); | ||
}); | ||
|
||
it("schema should be array with 0 parameters", ({ action, validator }) => { | ||
assert.equal(action.schema, { | ||
$id: "jsonRpc_net_version", | ||
maxItems: 0, | ||
type: "array", | ||
}); | ||
|
||
validator.addSchema(action.schema); | ||
|
||
assert.undefined(validator.validate("jsonRpc_net_version", []).errors); | ||
assert.defined(validator.validate("jsonRpc_net_version", [1]).errors); | ||
assert.defined(validator.validate("jsonRpc_net_version", {}).errors); | ||
}); | ||
|
||
it("should return the web3 client version", async ({ action }) => { | ||
assert.equal(await action.handle([]), `nethash`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { inject, injectable } from "@mainsail/container"; | ||
import { Contracts, Identifiers } from "@mainsail/contracts"; | ||
|
||
@injectable() | ||
export class NetVersion implements Contracts.Api.RPC.Action { | ||
@inject(Identifiers.Cryptography.Configuration) | ||
private readonly configuration!: Contracts.Crypto.Configuration; | ||
|
||
public readonly name: string = "net_version"; | ||
|
||
public readonly schema = { | ||
$id: `jsonRpc_${this.name}`, | ||
maxItems: 0, | ||
type: "array", | ||
}; | ||
|
||
public async handle(parameters: []): Promise<string> { | ||
return this.configuration.get<string>("network.nethash"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters