Skip to content

Commit

Permalink
docs: update examples (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnkz authored Oct 2, 2023
1 parent 9c5f856 commit 6503f50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 51 deletions.
35 changes: 10 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,29 @@ Our goal is to provide:
Vulcan test example:

```solidity
import { Test, expect, accounts, any, commands, Command, watchers, println } from "vulcan/test.sol";
import { Test, expect, commands, Command, CommandResult, println } from "vulcan/test.sol";
contract TestSomething is Test {
using accounts for *;
using watchers for *;
function testSomething() external {
// Format strings with rust-like syntax
println("Hello {s}", abi.encode("world!")); // Hello world!
println("Balance: {u:d18}", abi.encode(1e17)); // Balance: 0.1
// Create an address from a string, set the ETH balance and impersonate calls
address alice = accounts.create("Alice").setBalance(123).impersonate();
// Expect style assertions!
expect(true).toBeTrue();
expect("Hello world!").toContain("Hello");
// Format numbers as decimals
println("Balance: {u:d18}", abi.encode(1e17)); // Balance: 0.1
// Nice external command API!
Command memory ping = commands.create("ping").args(["-c", "1"]);
res = ping.arg("etherscan.io").run();
res = ping.arg("arbiscan.io").run();
// Monitor calls and events!
MyContract mc = new MyContract();
address(mc).watch().captureReverts(); // Watch calls and record their execution
mc.doSomething();
CommandResult pingResult = ping.arg("etherscan.io").run();
expect(address(mc).lastCall()).toHaveRevertedWith("Something went wrong");
// Rust-like results
Bytes memory pingOutput = pingResult.expect("Ping command failed").stdout;
mc.doSomethingElse();
println("Ping result: {s}", abi.encode(pingOutput));
// Check event emissions
expect(address(mc).lastCall()).toHaveEmitted(
"SomeEvent(address,bytes32,uint256)",
[address(1).topic(), any()], // Event topics
abi.encode(123) // Event data
);
// Expect style assertions!
expect(pingResult.isError()).toBeFalse();
expect(pingResult.isOk()).toBeTrue();
// And much more!
}
Expand Down
38 changes: 12 additions & 26 deletions docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,36 @@ Our goal is to provide:
Vulcan test example:

```solidity
import { Test, expect, accounts, any, commands, Command, watchers } from "vulcan/test.sol";
```solidity
import { Test, expect, commands, Command, CommandResult, println } from "vulcan/test.sol";
contract TestSomething is Test {
using accounts for *;
using watchers for *;
function testSomething() external {
// Format strings with rust-like syntax
println("Hello {s}", abi.encode("world!")); // Hello world!
println("Balance: {u:d18}", abi.encode(1e17)); // Balance: 0.1
// Create an address from a string, set the ETH balance and impersonate calls
address alice = accounts.create("Alice").setBalance(123).impersonate();
// Expect style assertions!
expect(true).toBeTrue();
expect("Hello world!").toContain("Hello");
// Format numbers as decimals
println("Balance: {u:d18}", abi.encode(1e17)); // Balance: 0.1
// Nice external command API!
Command memory ping = commands.create("ping").args(["-c", "1"]);
res = ping.arg("etherscan.io").run();
res = ping.arg("arbiscan.io").run();
// Monitor calls and events!
MyContract mc = new MyContract();
address(mc).watch().captureReverts(); // Watch calls and record their execution
mc.doSomething();
CommandResult pingResult = ping.arg("etherscan.io").run();
// Check that `doSomething()` reverted
expect(address(mc).lastCall()).toHaveRevertedWith("Something went wrong");
// Rust-like results
Bytes memory pingOutput = pingResult.expect("Ping command failed").stdout;
mc.doSomethingElse();
println("Ping result: {s}", abi.encode(pingOutput));
// Check event emissions
expect(address(mc).lastCall()).toHaveEmitted(
"SomeEvent(address,bytes32,uint256)",
[address(1).topic(), any()], // Event topics
abi.encode(123) // Event data
);
// Expect style assertions!
expect(pingResult.isError()).toBeFalse();
expect(pingResult.isOk()).toBeTrue();
// And much more!
}
}
```
```
## Planned Features
Expand Down

0 comments on commit 6503f50

Please sign in to comment.