diff --git a/README.md b/README.md index eb5130cb..8416f76b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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(); @@ -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! } } diff --git a/docs/src/README.md b/docs/src/README.md index 0d9b4ff2..e633fba4 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -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 @@ -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 @@ -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! } } diff --git a/docs/src/modules/json.md b/docs/src/modules/json.md index 290d995a..9794d0f4 100644 --- a/docs/src/modules/json.md +++ b/docs/src/modules/json.md @@ -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) diff --git a/docs/src/testing/README.md b/docs/src/testing/README.md index 048d31f7..f34c9c2d 100644 --- a/docs/src/testing/README.md +++ b/docs/src/testing/README.md @@ -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"); } } ``` diff --git a/docs/src/testing/expect.md b/docs/src/testing/expect.md index 651c25aa..a3f46d33 100644 --- a/docs/src/testing/expect.md +++ b/docs/src/testing/expect.md @@ -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); } ``` @@ -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"); } ``` @@ -59,6 +61,8 @@ function testSomething() external { ### `toHaveSucceeded()` ### `toHaveEmitted(topics)` + ### `toHaveEmitted(topics, data)` + ### `toHaveEmitted(signature, topics, data)`