Skip to content

Commit bf847d7

Browse files
committed
Add test suite
1 parent 63a80e4 commit bf847d7

19 files changed

+916
-0
lines changed

test/e2e/.env.test.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ENGINE_ACCESS_TOKEN=""
2+
ENGINE_URL=""
3+
ANVIL_URL=""

test/e2e/.gitignore

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Caches
14+
15+
.cache
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
19+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20+
21+
# Runtime data
22+
23+
pids
24+
_.pid
25+
_.seed
26+
*.pid.lock
27+
28+
# Directory for instrumented libs generated by jscoverage/JSCover
29+
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
34+
coverage
35+
*.lcov
36+
37+
# nyc test coverage
38+
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
47+
bower_components
48+
49+
# node-waf configuration
50+
51+
.lock-wscript
52+
53+
# Compiled binary addons (https://nodejs.org/api/addons.html)
54+
55+
build/Release
56+
57+
# Dependency directories
58+
59+
node_modules/
60+
jspm_packages/
61+
62+
# Snowpack dependency directory (https://snowpack.dev/)
63+
64+
web_modules/
65+
66+
# TypeScript cache
67+
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
72+
.npm
73+
74+
# Optional eslint cache
75+
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
80+
.stylelintcache
81+
82+
# Microbundle cache
83+
84+
.rpt2_cache/
85+
.rts2_cache_cjs/
86+
.rts2_cache_es/
87+
.rts2_cache_umd/
88+
89+
# Optional REPL history
90+
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
95+
*.tgz
96+
97+
# Yarn Integrity file
98+
99+
.yarn-integrity
100+
101+
# dotenv environment variable files
102+
103+
.env
104+
.env.development.local
105+
.env.test.local
106+
.env.production.local
107+
.env.local
108+
109+
# parcel-bundler cache (https://parceljs.org/)
110+
111+
.parcel-cache
112+
113+
# Next.js build output
114+
115+
.next
116+
out
117+
118+
# Nuxt.js build / generate output
119+
120+
.nuxt
121+
dist
122+
123+
# Gatsby files
124+
125+
# Comment in the public line in if your project uses Gatsby and not Next.js
126+
127+
# https://nextjs.org/blog/next-9-1#public-directory-support
128+
129+
# public
130+
131+
# vuepress build output
132+
133+
.vuepress/dist
134+
135+
# vuepress v2.x temp and cache directory
136+
137+
.temp
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.*
170+
171+
# IntelliJ based IDEs
172+
.idea
173+
174+
# Finder (MacOS) folder config
175+
.DS_Store
176+
177+
.env.test

test/e2e/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# engine e2e test suite
2+
## Configuration
3+
1. Create a `.env.test` file (use `.env.test.example` as a template) and fill in the necessary values.
4+
2. Check `config.ts` to configure the test suite.
5+
3. Run `bun test` within the directory to run the tests.
6+
7+
Note: make sure `engine` is running, and `anvil` is installed if running the tests on a local environment. (You can get the latest version of `anvil` by installing [`forge`](https://book.getfoundry.sh/getting-started/installation))
8+
9+
## Running tests
10+
The test suite depends on a local SDK to run tests. To run the tests, you need to generate the SDK. To do this, run the following command from the root of the repository:
11+
12+
```bash
13+
yarn generate:sdk
14+
```
15+
Run all subsequent commands from the `test/e2e` directory.
16+
17+
Some tests contains load tests which take a long time to run. To ensure they don't timeout, use the following command:
18+
19+
```bash
20+
bun test --timeout 300000
21+
```
22+
23+
To run a specific test, use the following command:
24+
25+
```bash
26+
bun test tests/<test_name>.test.ts
27+
```

test/e2e/bun.lockb

292 KB
Binary file not shown.

test/e2e/chain.test.ts

Whitespace-only changes.

test/e2e/config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import assert from "assert";
2+
import type { Chain } from "viem";
3+
import { anvil } from "viem/chains";
4+
5+
assert(process.env.ENGINE_URL, "ENGINE_URL is required");
6+
assert(process.env.ENGINE_ACCESS_TOKEN, "ENGINE_ACCESS_TOKEN is required");
7+
8+
export const CONFIG: Config = {
9+
ACCESS_TOKEN: process.env.ENGINE_ACCESS_TOKEN,
10+
URL: process.env.ENGINE_URL,
11+
12+
// CHAIN_ID: 1993,
13+
// CHAIN_NAME: "anvil",
14+
// RPC_URL: "http://localhost:8545",
15+
// RPC_URL: "http://localhost:8545",
16+
// USE_LOCAL_CHAIN: true,
17+
// CHAIN: arbitrumSepolia,
18+
19+
USE_LOCAL_CHAIN: true,
20+
CHAIN: anvil,
21+
22+
TRANSACTION_COUNT: 500,
23+
TRANSACTIONS_PER_BATCH: 100,
24+
POLLING_INTERVAL: 1000,
25+
26+
STAGGER_MAX: 500,
27+
INITIAL_BALANCE: "10000", // in Ether
28+
};
29+
30+
type Config = {
31+
ACCESS_TOKEN: string;
32+
URL: string;
33+
TRANSACTION_COUNT: number;
34+
TRANSACTIONS_PER_BATCH: number;
35+
POLLING_INTERVAL: number;
36+
STAGGER_MAX: number;
37+
INITIAL_BALANCE: string;
38+
39+
CHAIN: Chain;
40+
USE_LOCAL_CHAIN?: boolean;
41+
};

test/e2e/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "e2e",
3+
"module": "index.ts",
4+
"devDependencies": {
5+
"@types/bun": "latest",
6+
"tsup": "^8.2.3"
7+
},
8+
"peerDependencies": {
9+
"typescript": "^5.0.0"
10+
},
11+
"type": "module",
12+
"dependencies": {
13+
"@thirdweb-dev/sdk": "^4.0.99",
14+
"ethers": "5",
15+
"thirdweb": "^5.43.2",
16+
"viem": "^2.18.1"
17+
}
18+
}

test/e2e/scripts/counter.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Anvil chain outputs every RPC call to stdout
2+
// You can save the output to a file and then use this script to count the number of times a specific RPC call is made.
3+
4+
import { readFile } from "fs/promises";
5+
import { join } from "path";
6+
7+
const file = join(__dirname, "rpc_spam.txt");
8+
9+
async function countLines(file: string) {
10+
const data = await readFile(file, "utf-8");
11+
const lines = data.split("\n");
12+
const statements = new Map<string, number>();
13+
14+
for (const line of lines) {
15+
if (!line.trim()) {
16+
continue;
17+
}
18+
19+
if (statements.has(line)) {
20+
statements.set(line, statements.get(line)! + 1);
21+
} else {
22+
statements.set(line, 1);
23+
}
24+
}
25+
26+
return statements;
27+
}
28+
29+
countLines(file).then((lines) => {
30+
for (const [line, count] of lines) {
31+
console.log(`${line}: ${count}`);
32+
}
33+
});

0 commit comments

Comments
 (0)