Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/rpc module #236

Merged
merged 12 commits into from
Nov 27, 2023
1 change: 1 addition & 0 deletions docs/src/OTHER_MODULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
- [Env](./modules/env.md)
- [Events](./modules/events.md)
- [Forks](./modules/forks.md)
- [RPC](./modules/rpc.md)
- [Strings](./modules/strings.md)
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [Env](./modules/env.md)
- [Events](./modules/events.md)
- [Forks](./modules/forks.md)
- [RPC](./modules/rpc.md)
- [Strings](./modules/strings.md)

# References
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/config/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Read all the RPC URL from the foundry configuration as structs
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Test, expect, config, Rpc} from "vulcan/test.sol";
import {Test, expect, config, RpcConfig} from "vulcan/test.sol";

contract ConfigExample is Test {
function test() external {
Rpc[] memory rpcs = config.rpcUrlStructs();
RpcConfig[] memory rpcs = config.rpcUrlStructs();

expect(rpcs.length).toEqual(2);
expect(rpcs[0].name).toEqual("arbitrum");
Expand Down
1 change: 1 addition & 0 deletions docs/src/examples/events/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Logging events and reading events topics and data

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Test, expect, events, Log} from "vulcan/test.sol";
Expand Down
34 changes: 34 additions & 0 deletions docs/src/examples/rpc/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Examples
### Calling an RPC

Calling an rpc using the `eth_chainId` method

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Test, expect} from "vulcan/test.sol";
import {rpc} from "vulcan/test/Rpc.sol";
import {Fork, forks} from "vulcan/test/Forks.sol";

contract RpcTest is Test {
function testNetVersion() external {
forks.create("https://rpc.mevblocker.io/fast").select();

string memory method = "eth_chainId";
string memory params = "[]";

bytes memory data = rpc.call(method, params);

uint8 chainId;

assembly {
chainId := mload(add(data, 0x01))
}

expect(chainId).toEqual(block.chainid);
}
}

```

7 changes: 7 additions & 0 deletions docs/src/modules/rpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# RPC

The `rpc` module provides methods to interact with JSON-RPC APIs. The list of official Ethereum RPC methods can
be found [here](https://ethereum.org/en/developers/docs/apis/json-rpc).

{{#include ../examples/rpc/example.md}}

6 changes: 3 additions & 3 deletions docs/src/references/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## Structs

### Rpc
### RpcConfig

```solidity
struct Rpc {
struct RpcConfig {
string name
string url
}
Expand All @@ -25,7 +25,7 @@ Obtains a specific RPC from the configuration by name.

Obtains all the RPCs from the configuration.

### **rpcUrlStructs() → (Rpc[] rpcs)**
### **rpcUrlStructs() → (RpcConfig[] rpcs)**

Obtains all the RPCs from the configuration.

Loading