Skip to content

Commit

Permalink
docs: forks examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gnkz committed Nov 22, 2023
1 parent 8030a97 commit b3709ee
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build image
run: docker build . -t nomoixyz/vulcan-test-suite
- name: Run tests
run: docker run --rm nomoixyz/vulcan-test-suite
run: docker run --rm nomoixyz/vulcan-test-suite --no-match-path 'test/examples/**/*'
format:
name: Check format
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion docs/src/examples/events/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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
25 changes: 25 additions & 0 deletions docs/src/examples/forks/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Examples
### How to use forks

How to use forks. This example assumes there is a JSON RPC server running at `localhost:8545`

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Test, expect, vulcan} from "vulcan/test.sol";
import {forks, Fork} from "vulcan/test/Forks.sol";
import {ctx} from "vulcan/test/Context.sol";
contract ForksExample is Test {
string constant RPC_URL = "http://localhost:8545";
function test() external {
forks.create(RPC_URL).select();
expect(block.chainid).toEqual(31337);
}
}
```

5 changes: 4 additions & 1 deletion docs/src/examples/fs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ Obtain metadata and check if file exists
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Test, expect, fs, BoolResult, FsMetadataResult} from "vulcan/test.sol";
import {Test} from "vulcan/test.sol";
import {expect} from "vulcan/test/Expect.sol";
import {fs, FsMetadataResult} from "vulcan/test/Fs.sol";
import {BoolResult} from "vulcan/test/Result.sol";
contract FsExample is Test {
// These files are available only on the context of vulcan
Expand Down
8 changes: 4 additions & 4 deletions docs/src/examples/results/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Different methods of getting the underlyng value of a `Result`
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Test, expect, StringResult, Ok} from "vulcan/test.sol";
import {Test, expect, StringResult} from "vulcan/test.sol";
// This import is just to demonstration, it's not meant to be imported on projects using Vulcan
import {Ok} from "vulcan/_internal/Result.sol";
contract ResultExample is Test {
function test() external {
Expand Down Expand Up @@ -48,9 +50,7 @@ contract ResultExample is Test {
CommandResult result = commands.run(["asdf12897u391723"]);
// Use unwrap to revert with the default error message
ctx.expectRevert(
"The command was not executed: \"Failed to execute command: No such file or directory (os error 2)\""
);
ctx.expectRevert();
result.unwrap();
// Use expect to revert with a custom error message
Expand Down
16 changes: 1 addition & 15 deletions docs/src/modules/forks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@

Forking functionality.

```solidity
import { Test, forks, Fork } from "vulcan/test.sol";
{{#include ../examples/forks/example.md}}

contract TestMyContract is Test {
function testMyContract() external {
// Alternatively an endpoint can be passed directly.
Fork fork = forks.create("mainnet");
// The fork can be created at an specific block
fork = forks.createAtBlock("mainnet", 16736036);
// Or right before a transaction
fork = forks.createBeforeTx("mainnet", 0x9cad524afce3fcd2e84b8ac30c57ba085fcae053e9bf3ee449cd36d511c10f43);
}
}
```
[**Forks API reference**](../references/Forks.md)
18 changes: 18 additions & 0 deletions test/examples/forks/ForksExample01.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

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

/// @title How to use forks
/// @dev How to use forks. This example assumes there is a JSON RPC server running at `localhost:8545`
contract ForksExample is Test {
string constant RPC_URL = "http://localhost:8545";

function test() external {
forks.create(RPC_URL).select();

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

0 comments on commit b3709ee

Please sign in to comment.