Skip to content

Commit 96e52fa

Browse files
wjmelementsclaude
andauthored
feat(dio): constructTest (#97)
* feat: add constructTest support to dio JSON format Adds a "constructTest" entry-level field that tests constructor execution — gasUsed, deployed code (output), logs, and status — with full support for the -u -w auto-update workflow. Also extracts shared helpers printEntryHeader, reportResult, and jsonScanTestEntry to eliminate duplication between tests and constructTest parsing/reporting. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs: document constructTest in README and manual Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: support empty test * set debug before executing * add failing nonce test * fix test * add tst/out/nonce.out * hush * conditional bzero --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c3612eb commit 96e52fa

File tree

10 files changed

+458
-295
lines changed

10 files changed

+458
-295
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ If `code` is also supplied for the entry, the code will be used to verify the re
133133
| `creator` | address of the account creating this contract | `0x3249936bDdF8bF739d3f06d26C40EEfC81029BD1` | `0x0000000000000000000000000000000000000000` |
134134
| `initcode` | account creation code | `0x383d3d39383df3`, `tst/in/quine.evm` | `code` mocked without constructor |
135135
| `construct` | specify `initcode` as minimum constructor of file | `tst/in/quine.evm` | `initcode` |
136+
| `constructTest` | test constructor execution; shares fields of `tests` entries | `{"gasUsed": "0xd583"}` | none |
136137
| `code` | account code ; validated if `initcode` specified | `0x383d3d39383df3`, `tst/in/quine.evm` | `0x` |
137138
| `import` | load another configuration | `tst/quine.json` | |
138139
| `tests` | transactions executed sequentially, after account configuration | <pre>[<br> {<br> "input": "0x18160ddd",<br> "output": "0x115eec47f6cf7e35000000"<br> }<br>]</pre> | `[]` |

docs/manual.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ All fields are optional; unset fields default to zero.
168168
| `code` | Runtime bytecode (hex or path to `.evm`) | `0x` |
169169
| `initcode` | Creation code (hex or path to `.evm`). If set, `code` is used as the expected deployed result. ||
170170
| `construct` | Like `initcode`, but wraps the file in a minimum constructor ||
171+
| `constructTest` | Test the constructor execution (see below) ||
171172
| `creator` | `msg.sender` for the constructor call | `0x000…000` |
172173
| `import` | Path to another config file to merge ||
173174
| `tests` | Array of test transactions (see below) | `[]` |
@@ -192,6 +193,38 @@ All fields are optional; unset fields default to zero.
192193
| `timestamp` | `block.timestamp` | `0x65712600` | |
193194
| `debug` | debug bitmask | `0x0` | See below |
194195

196+
### Constructor test
197+
198+
`constructTest` runs once after the constructor executes, before any `tests`, and reports the outcome to stderr.
199+
It accepts a subset of the test fields:
200+
201+
| Key | Description | Default |
202+
| :-: | ----------- | :-----: |
203+
| `name` | Label shown in output | `"constructor"` |
204+
| `from` | `msg.sender` for the constructor. Must equal `creator` if both are set. | `creator` (or `0x000…000`) |
205+
| `gas` | Gas limit | `0xffffffffffffffff` |
206+
| `output` | Expected deployed bytecode | ignored |
207+
| `logs` | Expected emitted logs | ignored |
208+
| `status` | Expected outcome | `0x1` (success) |
209+
| `gasUsed` | Expected gas | ignored (checked/updated if set) |
210+
| `debug` | Debug bitmask (see [Debug flags](#debug-flags)) | `0x0` |
211+
212+
Example — measure constructor gas with `-u`:
213+
```json
214+
[
215+
{
216+
"construct": "tst/in/quine.evm",
217+
"constructTest": {
218+
"name": "deploy quine",
219+
"gasUsed": "0xd583"
220+
}
221+
}
222+
]
223+
```
224+
```sh
225+
evm -uw tst/quine.json
226+
```
227+
195228
### Debug flags
196229

197230
`debug` is a bitmask.

include/address.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ typedef struct address {
1313
#define AddressCopy(dst, src) memcpy(dst.address, src.address, 20)
1414

1515
static inline int AddressEqual(const address_t *expected, const address_t *actual) {
16-
for (int i = 0; i < 20; i ++) {
16+
for (uint8_t i = 0; i < 20; i++) {
1717
if (expected->address[i] != actual->address[i]) {
1818
return 0;
1919
}
2020
}
2121
return 1;
2222
}
2323

24+
static inline int AddressZero(const address_t *address) {
25+
for (uint8_t i = 0; i < 40; i++) {
26+
if (address->address[i] != 0) {
27+
return false;
28+
}
29+
}
30+
return true;
31+
}
32+
2433
static inline address_t AddressFromHex40(const char *hex) {
2534
address_t address;
2635
for (uint8_t i = 0; i < 40; i += 2) {

make/.rme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ If `code` is also supplied for the entry, the code will be used to verify the re
133133
| `creator` | address of the account creating this contract | `0x3249936bDdF8bF739d3f06d26C40EEfC81029BD1` | `0x0000000000000000000000000000000000000000` |
134134
| `initcode` | account creation code | `0x383d3d39383df3`, `tst/in/quine.evm` | `code` mocked without constructor |
135135
| `construct` | specify `initcode` as minimum constructor of file | `tst/in/quine.evm` | `initcode` |
136+
| `constructTest` | test constructor execution; shares fields of `tests` entries | `{"gasUsed": "0xd583"}` | none |
136137
| `code` | account code ; validated if `initcode` specified | `0x383d3d39383df3`, `tst/in/quine.evm` | `0x` |
137138
| `import` | load another configuration | `tst/quine.json` | |
138139
| `tests` | transactions executed sequentially, after account configuration | <pre>[<br> {<br> "input": "0x18160ddd",<br> "output": "0x115eec47f6cf7e35000000"<br> }<br>]</pre> | `[]` |

0 commit comments

Comments
 (0)