Skip to content

Commit

Permalink
Feat/rpc module (#236)
Browse files Browse the repository at this point in the history
* feat: rpc module

* test: add test for the `rpc` module

* style: format

* docs: update docs

* docs: update other modules

* chore: add call method with url

* docs: update docs and examples

* docs: update examples

* chore: code review

* docs: update docs and examples

* chore: remove call with json params
  • Loading branch information
gnkz authored Nov 27, 2023
1 parent b3709ee commit d5d063f
Show file tree
Hide file tree
Showing 23 changed files with 415 additions and 16 deletions.
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

0 comments on commit d5d063f

Please sign in to comment.