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

fix: update code examples #133

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ See the [Vulcan Book](https://nomoixyz.github.io/vulcan/) for detailed usage inf
## Why Vulcan?

Our goal is to provide:

- Better naming for VM functionality (no more `prank`, `roll`, `warp`, ...)
- A testing framework with better readability and a familiar syntax
- Improved ergonomics
Expand All @@ -31,24 +32,34 @@ Our goal is to provide:
Vulcan test example:

```solidity
import { Test, expect, accounts, any, commands, Command, watchers } from "vulcan/test.sol";
import { Test, expect, accounts, any, commands, Command, watchers, 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();

MyContract mc = new MyContract();
// Expect style assertions!
expect(true).toBeTrue();
expect("Hello world!").toContain("Hello");

// This will watch all contract calls and record their execution
address(mc).watch().captureReverts();
// 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();

// Check that `doSomething()` reverted
expect(address(mc).lastCall()).toHaveRevertedWith("Something went wrong");

mc.doSomethingElse();
Expand All @@ -60,18 +71,6 @@ contract TestSomething is Test {
abi.encode(123) // Event data
);

// Expect style assertions!
expect(true).toBeTrue();
expect(true).toEqual(true);
expect(123).toBeGreaterThanOrEqual(123);
expect(123).not.toEqual(321);
expect("Hello world!").toContain("Hello");

// 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();

// And much more!
}
}
Expand Down
30 changes: 15 additions & 15 deletions docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Over time, Vulcan will grow to include more functionality and utilities, eventua
## Why Vulcan?

Our goal is to provide:

- Better naming for VM functionality (no more `prank`, `roll`, `warp`, ...)
- A testing framework with better readability and a familiar syntax
- Improved ergonomics
Expand All @@ -28,14 +29,25 @@ contract TestSomething is Test {
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();

MyContract mc = new MyContract();
// Expect style assertions!
expect(true).toBeTrue();
expect("Hello world!").toContain("Hello");

// This will watch all contract calls and record their execution
address(mc).watch().captureReverts();
// 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();

// Check that `doSomething()` reverted
Expand All @@ -50,18 +62,6 @@ contract TestSomething is Test {
abi.encode(123) // Event data
);

// Expect style assertions!
expect(true).toBeTrue();
expect(true).toEqual(true);
expect(123).toBeGreaterThanOrEqual(123);
expect(123).not.toEqual(321);
expect("Hello world!").toContain("Hello");

// 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();

// And much more!
}
}
Expand Down
5 changes: 3 additions & 2 deletions docs/src/modules/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ contract TestMyContract is Test {
obj.set("foo", true);

// Obtain the set Json string
expect(obj.set).toEqual('{"foo":true}');
expect(obj.serialized).toEqual('{"foo":true}');

// Nested Objects
JsonObject memory nested = json.create();

nested.set("bar", obj);

expect(nested.set).toEqual('{"bar":{"foo":true}}');
expect(nested.serialized).toEqual('{"bar":{"foo":true}}');
}
}
```

[**Json API reference**](../reference/modules/json.md)
8 changes: 5 additions & 3 deletions docs/src/testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { Test, expect } from "vulcan/test.sol";

contract ExampleTest is Test {
function testSomething() external {
expect(1).toBeLessThan(2);
expect(1).not.toEqual(2);
expect(1).toEqual(1);
uint256 value = 1;
expect(value).toEqual(1);
expect(value).not.toEqual(2);
expect(value).toBeLessThan(2);
expect("Hello World!).toContain("World");
}
}
```
8 changes: 6 additions & 2 deletions docs/src/testing/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ The `expect` function allows you to assert that a value meets a certain conditio
import { Test, expect } from "vulcan/test.sol";

function testSomething() external {
expect(1).toEqual(1);
uint256 a = 1;
uint256 b = 1;
expect(a).toEqual(b);
}
```

Expand All @@ -20,7 +22,7 @@ The `.not` property inverts the result of the assertion.

```solidity
function testSomething() external {
expect(1).not.toEqual(2);
expect("hello").not.toEqual("world");
}
```

Expand Down Expand Up @@ -59,6 +61,8 @@ function testSomething() external {
### `toHaveSucceeded()`

### `toHaveEmitted(topics)`

### `toHaveEmitted(topics, data)`

### `toHaveEmitted(signature, topics, data)`