Skip to content

Commit 237bc24

Browse files
lipmanethgitbook-bot
authored andcommitted
GITBOOK-23: Updating based on changes to framework that simplify the GUI api
1 parent cad3f5f commit 237bc24

File tree

6 files changed

+51
-169
lines changed

6 files changed

+51
-169
lines changed

SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Platform
88

9-
* [GuardianTest](platform/guardian-test/GuardianTest.md)
9+
* [GuardianTest](platform/readme/GuardianTest.md)
1010
* [Overview](platform/guardian-test/overview/README.md)
1111
* [Key Benefits](platform/guardian-test/overview/key-benefits.md)
1212
* [Framework Roadmap](platform/guardian-test/overview/framework-roadmap.md)
@@ -34,7 +34,7 @@
3434
* [Check Results](platform/continuous-monitoring/monitoring/check-results.md)
3535
* [How We Store Data](platform/continuous-monitoring/monitoring/how-we-store-data.md)
3636
* [Browser Checks](platform/continuous-monitoring/browser-checks/README.md)
37-
* [Writing Tests](platform/guardian-test/getting-started/writing-your-first-e2e-test.md)
37+
*
3838
* [Request Custom Test Writing](platform/continuous-monitoring/browser-checks/request-custom-test-writing.md)
3939
* [Submitting Tests for Monitoring](platform/continuous-monitoring/browser-checks/submitting-tests-for-monitoring.md)
4040
* [Alerts](platform/continuous-monitoring/alerts/README.md)

platform/guardian-test/api/gui.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,6 @@ await gui.initializeChain(1, 17110784)
2424

2525

2626

27-
### killChain
28-
29-
Kills any existing forked networks. Should be used at the end of a test to make sure there are no collisions with tests spawning networks.
30-
31-
#### **Inputs**
32-
33-
* None
34-
35-
#### **Usage**
36-
37-
```javascript
38-
await gui.killChain()
39-
```
40-
41-
42-
43-
### initializeWallet
44-
45-
Updates the wallet provider in the injected wallet to use a specific chain ID.
46-
47-
#### **Inputs**
48-
49-
* `chainId` - The desired network chain ID to update the wallet provider
50-
51-
#### **Usage**
52-
53-
```javascript
54-
// Updates the wallet provider to connect to Arbitrum
55-
await gui.initializeWallet(42161);
56-
```
57-
58-
59-
6027
### setAllowance
6128

6229
Sets the allowance of an address to spend the test wallet's ERC20 tokens to a specific amount.

platform/guardian-test/getting-started/installation.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ You can install GuardianTest using either npm or yarn:
4141

4242
At your repo's top-level directory create a file called `playwright.config.ts`.
4343

44-
If you already are using Playwright and already have a `playwright.config.ts`, just add `/.*gui\.(js|ts|mjs)/` to the `testMatch` entry to make sure Playwright recognizes our tests.
44+
If you already are using Playwright and already have a `playwright.config.ts:`
45+
46+
* Add `/.*gui\.(js|ts|mjs)/` to the `testMatch` entry to make sure Playwright recognizes our tests
47+
* Set `fullyParallel` to `false`
48+
* Set `workers` to `1`
4549

4650
```typescript
4751
import { devices, PlaywrightTestConfig } from '@playwright/test';

platform/guardian-test/getting-started/writing-your-first-e2e-test.md

Lines changed: 22 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ await page.goto("https://guardianui.com");
2020

2121
#### Interaction
2222

23-
Performing interactions involves two pieces. 
23+
Performing interactions involves two pieces.
2424

2525
* The locator of the object to interact with (for more information, check out the [Playwright Locators API documentation](https://playwright.dev/docs/locators)).
26-
* The action to take. 
26+
* The action to take.
2727

2828
By default Playwright waits for an element to be actionable before attempting to perform an action.
2929

@@ -46,8 +46,6 @@ Playwright has a robust suite of actions built into the Locator API, the most co
4646
| `locator.press()` | Press a single key |
4747
| `locator.selectOption()` | Select on option from a drop down |
4848

49-
50-
5149
### Making General Assertions
5250

5351
Playwright natively includes test assertions by way of an `expect` function. For more information on the available functionality of `expect`, check out the [Playwright Assertions documentation](https://playwright.dev/docs/test-assertions).
@@ -74,8 +72,6 @@ There are also many async assertions which wait until the expected condition is
7472
| `expect(page).toHaveTitle()` | Assert that the page has a certain title |
7573
| `expect(page).toHaveURL()` | Assert that the page has a certain URL |
7674

77-
78-
7975
### Using Hooks
8076

8177
You can use test hooks to define groups of tests, or hooks like `test.beforeAll`, `test.beforeEach`, `test.afterAll`, and `test.afterEach` to perform reused sets of actions before/after each test or as setup/teardown for test suites. For more information visit the [Playwright Test Hooks documentation](https://playwright.dev/docs/api/class-test).
@@ -92,15 +88,12 @@ test.describe("hooks example", () => {
9288
});
9389

9490
test.afterEach(async ({ page, gui }) => {
95-
// Tear down Arbitrum fork after each test
96-
await gui.killChain();
91+
// Do something after each test
9792
});
9893

9994
test("example test", async ({ page, gui }) => {
10095
await page.goto("https://guardianui.com");
10196

102-
await gui.initializeWallet(1);
103-
10497
// Set ETH balance to 1 for the test wallet
10598
await gui.setEthBalance("1000000000000000000");
10699

@@ -115,26 +108,20 @@ test.describe("hooks example", () => {
115108
});ypoe
116109
```
117110

118-
119-
120111
## Writing a GuardianTest Test
121112

122113
There are eight phases to writing your first GuardianUI end-to-end test:
123114

124115
1. Forked network initialization
125116
2. Navigation to the dApp
126-
3. Wallet initialization
127-
4. Wallet state mocking
128-
5. Wallet connection
129-
6. Performing actions within the dApp
130-
7. Transaction submission and verification
131-
8. Stop the forked network
132-
133-
117+
3. Wallet state mocking
118+
4. Wallet connection
119+
5. Performing actions within the dApp
120+
6. Transaction submission and verification
134121

135122
### Phase 1: Forked Network Initialization
136123

137-
In order to set network state and perform network interactions without expending real tokens, every test that plans to interact with a live network needs to begin by initializing a forked network.
124+
In order to set network state and perform network interactions without expending real tokens, every test that plans to interact with a live network needs to begin by initializing a forked network. Within this call you can specify the network you wish to fork using its chain ID, and optionally what block number you want to fork at (if you don't specify a block it runs at the latest). We recommend pinning to a block as it increases deterministicness of the tests.
138125

139126
<pre class="language-typescript"><code class="lang-typescript">import { test } from "@guardianui/test";
140127

@@ -148,7 +135,7 @@ test.describe("Olympus Example Suite", () => {
148135
});
149136
</code></pre>
150137

151-
138+
###
152139

153140
### Phase 2: Navigation To The dApp
154141

@@ -169,33 +156,9 @@ test.describe("Olympus Example Suite", () => {
169156
});
170157
</code></pre>
171158

159+
###
172160

173-
174-
### Phase 3: Wallet Initialization
175-
176-
In order for the test to behave correctly and consistently, you will need to initialize the injected wallet with the chain ID of the network it should be connected to.
177-
178-
<pre class="language-typescript"><code class="lang-typescript">import { test } from "@guardianui/test";
179-
180-
test.describe("Olympus Example Suite", () => {
181-
test("Should stake OHM to gOHM", async ({ page, gui }) => {
182-
// Initialize a fork of Ethereum mainnet (chain ID 1)
183-
await gui.initializeChain(1);
184-
185-
// Navigate to the Olympus dApp
186-
await page.goto("https://app.olympusdao.finance/#/stake");
187-
188-
<strong> // Initialize wallet to connect to Ethereum mainnet (chain ID 1)
189-
</strong><strong> await gui.initializeWallet(1);
190-
</strong>
191-
// Complete the rest of the test
192-
});
193-
});
194-
</code></pre>
195-
196-
197-
198-
### Phase 4: Wallet State Mocking
161+
### Phase 3: Wallet State Mocking
199162

200163
The test wallet injected into the browser during these tests is empty by default. We can provide it with gas tokens, ERC20 tokens, and set allowances in a few quick lines.
201164

@@ -209,9 +172,6 @@ test.describe("Olympus Example Suite", () => {
209172
// Navigate to the Olympus dApp
210173
await page.goto("https://app.olympusdao.finance/#/stake");
211174

212-
// Initialize wallet to connect to Ethereum mainnet (chain ID 1)
213-
await gui.initializeWallet(1);
214-
215175
<strong> // Set ETH balance
216176
</strong><strong> await gui.setEthBalance("100000000000000000000000");
217177
</strong><strong>
@@ -226,13 +186,13 @@ test.describe("Olympus Example Suite", () => {
226186
});
227187
</code></pre>
228188

189+
###
229190

230-
231-
### Phase 5: Wallet Connection
191+
### Phase 4: Wallet Connection
232192

233193
The wallet connection flow will vary slightly from dApp to dApp, but usually requires locating a **"Connect Wallet"** button, and then selecting the **"Metamask"** option in an ensuing modal. While our wallet is not actually Metamask, it is surfaced to apps in a way that looks like Metamask to avoid issues where sites may not have an option to select an injected wallet.
234194

235-
To get a sense of what to write in the test, manually go to your live application and identify the visual and textual elements you need to click to go from the not-connected state to the connected state. Use the "inspect element" tool in browsers to help with this.&#x20;
195+
To get a sense of what to write in the test, manually go to your live application and identify the visual and textual elements you need to click to go from the not-connected state to the connected state. Use the "inspect element" tool in browsers to help with this.
236196

237197
See examples in our [test examples](https://app.gitbook.com/o/aEzOvP1ODgbzLwqZ2irE/s/6blK04TyOYOkA5ZEQW4b/end-to-end-testing/test-examples) section.
238198

@@ -246,9 +206,6 @@ test.describe("Olympus Example Suite", () => {
246206
// Navigate to the Olympus dApp
247207
await page.goto("https://app.olympusdao.finance/#/stake");
248208

249-
// Initialize wallet to connect to Ethereum mainnet (chain ID 1)
250-
await gui.initializeWallet(1);
251-
252209
// Set ETH balance
253210
await gui.setEthBalance("100000000000000000000000");
254211

@@ -274,9 +231,9 @@ test.describe("Olympus Example Suite", () => {
274231
});
275232
</code></pre>
276233

234+
###
277235

278-
279-
### Phase 6: Performing Actions Within the dApp
236+
### Phase 5: Performing Actions Within the dApp
280237

281238
This will vary drastically from dApp to dApp, but generally requires identifying elements on the web page based on class or ID selectors and clicking or entering information into them.
282239

@@ -292,9 +249,6 @@ test.describe("Olympus Example Suite", () => {
292249
// Navigate to the Olympus dApp
293250
await page.goto("https://app.olympusdao.finance/#/stake");
294251

295-
// Initialize wallet to connect to Ethereum mainnet (chain ID 1)
296-
await gui.initializeWallet(1);
297-
298252
// Set ETH balance
299253
await gui.setEthBalance("100000000000000000000000");
300254

@@ -319,12 +273,12 @@ test.describe("Olympus Example Suite", () => {
319273
<strong> // Performing actions within the dApp
320274
</strong><strong> // Enter OHM input amount
321275
</strong><strong> await page.locator("[data-testid='ohm-input']").type("0.1");
322-
</strong><strong>
323-
</strong><strong> // Click the stake button to open the modals
276+
</strong>
277+
<strong> // Click the stake button to open the modals
324278
</strong><strong> await page.waitForSelector("[data-testid='submit-button']");
325279
</strong><strong> await page.locator("[data-testid='submit-button']").click();
326-
</strong><strong>
327-
</strong><strong> // Click the pre-transaction checkbox
280+
</strong>
281+
<strong> // Click the pre-transaction checkbox
328282
</strong><strong> await page.waitForSelector("[class='PrivateSwitchBase-input css-1m9pwf3']");
329283
</strong><strong> await page.locator("[class='PrivateSwitchBase-input css-1m9pwf3']").click();
330284
</strong>
@@ -333,9 +287,9 @@ test.describe("Olympus Example Suite", () => {
333287
});
334288
</code></pre>
335289

290+
###
336291

337-
338-
### Phase 7: Transaction Submission and Verification
292+
### Phase 6: Transaction Submission and Verification
339293

340294
One of the primary novel behaviors of the GuardianTest framework is its ability to validate information around network transactions following a site interaction such as a button click. Doing this requires two pieces of information:
341295

@@ -354,9 +308,6 @@ test.describe("Olympus Example Suite", () => {
354308
// Navigate to the Olympus dApp
355309
await page.goto("https://app.olympusdao.finance/#/stake");
356310

357-
// Initialize wallet to connect to Ethereum mainnet (chain ID 1)
358-
await gui.initializeWallet(1);
359-
360311
// Set ETH balance
361312
await gui.setEthBalance("100000000000000000000000");
362313

@@ -391,68 +342,6 @@ test.describe("Olympus Example Suite", () => {
391342

392343
<strong> // Submit stake transaction
393344
</strong><strong> await gui.validateContractInteraction("[data-testid='submit-modal-button']", "0xb63cac384247597756545b500253ff8e607a8020");
394-
</strong>
395-
// Complete the rest of the test
396-
});
397-
});
398-
</code></pre>
399-
400-
401-
402-
### Phase 8: Stop The Forked Network
403-
404-
GuardianUI tests run in sequence to avoid port collisions when creating and using Anvil forks. However, the fork isn't torn down at the end of a test by default, so to end the test you need to specify that the fork is no longer needed.
405-
406-
<pre class="language-typescript"><code class="lang-typescript">import { test } from "@guardianui/test";
407-
408-
test.describe("Olympus Example Suite", () => {
409-
test("Should stake OHM to gOHM", async ({ page, gui }) => {
410-
// Initialize a fork of Ethereum mainnet (chain ID 1)
411-
await gui.initializeChain(1);
412-
413-
// Navigate to the Olympus dApp
414-
await page.goto("https://app.olympusdao.finance/#/stake");
415-
416-
// Initialize wallet to connect to Ethereum mainnet (chain ID 1)
417-
await gui.initializeWallet(1);
418-
419-
// Set ETH balance
420-
await gui.setEthBalance("100000000000000000000000");
421-
422-
// Set OHM balance
423-
await gui.setAllowance("0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5", "0xb63cac384247597756545b500253ff8e607a8020", "1000000000000000000000000");
424-
425-
// Set staking contract's approval to spend OHM
426-
await gui.setBalance("0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5", "1000000000000000000000000");
427-
428-
// Connect wallet
429-
await page.waitForSelector("text=Connect Wallet");
430-
await page.locator("text=Connect Wallet").first().click();
431-
await page.waitForSelector("text=Connect Wallet");
432-
await page.locator("text=Connect Wallet").first().click();
433-
await page.locator("text=Metamask").first().click();
434-
435-
// This is specific to Olympus. A side tab is opened upon wallet connection
436-
// so we click out of it
437-
await page.locator("[id='root']").click({ position: {x: 0, y: 0}, force: true });
438-
439-
// Performing actions within the dApp
440-
// Enter OHM input amount
441-
await page.locator("[data-testid='ohm-input']").type("0.1");
442-
443-
// Click the stake button to open the modals
444-
await page.waitForSelector("[data-testid='submit-button']");
445-
await page.locator("[data-testid='submit-button']").click();
446-
447-
// Click the pre-transaction checkbox
448-
await page.waitForSelector("[class='PrivateSwitchBase-input css-1m9pwf3']");
449-
await page.locator("[class='PrivateSwitchBase-input css-1m9pwf3']").click();
450-
451-
// Submit stake transaction
452-
await gui.validateContractInteraction("[data-testid='submit-modal-button']", "0xb63cac384247597756545b500253ff8e607a8020");
453-
454-
// Stop the forked network
455-
<strong> await gui.killChain();
456345
</strong> });
457346
});
458347
</code></pre>

platform/guardian-test/overview/supported-chains.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ GuardianTest currently supports four popular EVM chains:
66
* Arbitrum
77
* Optimism
88
* Polygon PoS
9+
10+
NOTE: The framework is most thoroughly tested on Ethereum, you are more likely to bump into issues on other chains

platform/readme/GuardianTest.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
description: >-
3+
Meet the new standard for web3 end-to-end testing. Reliably test in a
4+
production-like environment across any EVM-compatible chain using our open
5+
source framework.
6+
---
7+
8+
# GuardianTest
9+
10+
GuardianTest is an open source E2E testing framework developed to suit the demands of crypto organizations and developers.
11+
12+
It extends the popular [Playwright](https://playwright.dev/) testing framework so developers can easily:
13+
14+
* Engage with local deployments, staging deployments, OR live production
15+
* Perform tests on EVM compatible chains
16+
* Pin tests to any block
17+
* Interact with a site using a wallet
18+
* Mock ERC20 balances and allowances
19+
* Validate target contract addresses from app interactions
20+
* Perform any other actions or validation Playwright offers

0 commit comments

Comments
 (0)