Skip to content

Commit 228ecc4

Browse files
authored
fix: switch testing framework to foundry (#59)
1 parent b2452c9 commit 228ecc4

17 files changed

+1167
-887
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "packages/did-eth-registry/lib/forge-std"]
2+
path = packages/did-eth-registry/lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std
4+
branch = v1.6.1

packages/did-eth-registry/.devcontainer/devcontainer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
"context": "..",
88
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
99
"dockerfile": "../Dockerfile"
10+
},
11+
"customizations": {
12+
"vscode": {
13+
"extensions": [
14+
"JuanBlanco.solidity"
15+
]
16+
}
1017
}
1118

1219
// Features to add to the dev container. More info: https://containers.dev/features.

packages/did-eth-registry/.dockerignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
.git/
21
cache/
32
artifacts/
4-
lib/
53
build/
64
typechain/
75
typechain-types/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"juanblanco.solidity"
5+
]
6+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "preinstall",
8+
"type": "shell",
9+
"command": "forge install",
10+
"options": {
11+
"cwd": "${workspaceFolder}"
12+
},
13+
"group": {
14+
"kind": "build"
15+
}
16+
},
17+
{
18+
"label": "install",
19+
"type": "shell",
20+
"command": "yarn install --frozen-lockfile",
21+
"options": {
22+
"cwd": "${workspaceFolder}"
23+
},
24+
"dependsOn": "preinstall",
25+
"group": {
26+
"kind": "build"
27+
}
28+
},
29+
{
30+
"label": "prettier",
31+
"type": "shell",
32+
"command": "yarn prettier:check",
33+
"options": {
34+
"cwd": "${workspaceFolder}"
35+
},
36+
"dependsOn": "install",
37+
"group": {
38+
"kind": "build"
39+
}
40+
},
41+
{
42+
"label": "lint",
43+
"type": "shell",
44+
"command": "yarn lint",
45+
"options": {
46+
"cwd": "${workspaceFolder}"
47+
},
48+
"dependsOn": "prettier",
49+
"group": {
50+
"kind": "build"
51+
}
52+
},
53+
{
54+
"label": "build",
55+
"type": "shell",
56+
"command": "forge build --sizes",
57+
"options": {
58+
"cwd": "${workspaceFolder}"
59+
},
60+
"dependsOn": "lint",
61+
"group": {
62+
"kind": "build",
63+
"isDefault": true
64+
}
65+
},
66+
{
67+
"label": "test",
68+
"type": "shell",
69+
"command": "forge test -vvv",
70+
"options": {
71+
"cwd": "${workspaceFolder}"
72+
},
73+
"dependsOn": "lint",
74+
"group": {
75+
"kind": "test",
76+
"isDefault": true
77+
}
78+
},
79+
{
80+
"label": "coverage",
81+
"type": "shell",
82+
"command": "forge coverage",
83+
"options": {
84+
"cwd": "${workspaceFolder}"
85+
},
86+
"dependsOn": "lint",
87+
"group": {
88+
"kind": "test",
89+
"isDefault": false
90+
}
91+
},
92+
{
93+
"label": "gas",
94+
"type": "shell",
95+
"command": "forge test --gas-report",
96+
"options": {
97+
"cwd": "${workspaceFolder}"
98+
},
99+
"dependsOn": "lint",
100+
"group": {
101+
"kind": "test",
102+
"isDefault": false
103+
}
104+
}
105+
]
106+
}

packages/did-eth-registry/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ COPY --chown=did:did . .
6161
RUN yarn install --frozen-lockfile
6262
RUN yarn prettier:check
6363
RUN yarn lint
64-
RUN yarn build
65-
RUN yarn test
64+
RUN forge test -v
65+
RUN forge geiger --check contracts/*.sol
66+
RUN forge coverage
6667

6768
USER did

packages/did-eth-registry/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,30 @@ needed. The list of delegateTypes to include is still to be determined.
304304
Iterate through `DIDAttributeChanged` events for service entries, encrypted public keys, and other public names. The
305305
attribute names are still to be determined.
306306

307+
## Quick Start
308+
309+
### Submodules
310+
311+
First, init submodules from the project root
312+
313+
```bash
314+
$ git submodule update --recursive --init -f
315+
```
316+
317+
### Registry Development
318+
319+
This contract supports containerized development. From Visual Studio Code Remote Containers extension
320+
321+
`Reopen in Container`
322+
323+
or
324+
325+
Command line build using docker
326+
327+
```bash
328+
$ docker build packages/did-eth-registry -t did-eth:1
329+
```
330+
307331
## Deploy contract
308332

309333
First run,
@@ -324,7 +348,8 @@ Once this funding transaction is confirmed, simply send the `rawTx` to the same
324348
## Testing the Contracts
325349

326350
```bash
327-
yarn install
328-
yarn build
329-
yarn test
351+
$ yarn install --frozen-lockfile
352+
$ yarn prettier:check
353+
$ yarn lint
354+
$ forge test -v
330355
```

packages/did-eth-registry/contracts/EthereumDIDRegistry.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ contract EthereumDIDRegistry {
4444
uint8 sigV,
4545
bytes32 sigR,
4646
bytes32 sigS,
47-
bytes32 hash
47+
bytes32 digest
4848
) internal returns (address) {
49-
address signer = ecrecover(hash, sigV, sigR, sigS);
49+
address signer = ecrecover(digest, sigV, sigR, sigS);
5050
require(signer == identityOwner(identity), "bad_signature");
5151
nonce[signer]++;
5252
return signer;
@@ -82,7 +82,7 @@ contract EthereumDIDRegistry {
8282
bytes32 sigS,
8383
address newOwner
8484
) public {
85-
bytes32 hash = keccak256(
85+
bytes32 digest = keccak256(
8686
abi.encodePacked(
8787
bytes1(0x19),
8888
bytes1(0),
@@ -93,7 +93,7 @@ contract EthereumDIDRegistry {
9393
newOwner
9494
)
9595
);
96-
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, hash), newOwner);
96+
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, digest), newOwner);
9797
}
9898

9999
function addDelegate(
@@ -126,7 +126,7 @@ contract EthereumDIDRegistry {
126126
address delegate,
127127
uint256 validity
128128
) public {
129-
bytes32 hash = keccak256(
129+
bytes32 digest = keccak256(
130130
abi.encodePacked(
131131
bytes1(0x19),
132132
bytes1(0),
@@ -139,7 +139,7 @@ contract EthereumDIDRegistry {
139139
validity
140140
)
141141
);
142-
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate, validity);
142+
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, digest), delegateType, delegate, validity);
143143
}
144144

145145
function revokeDelegate(
@@ -169,7 +169,7 @@ contract EthereumDIDRegistry {
169169
bytes32 delegateType,
170170
address delegate
171171
) public {
172-
bytes32 hash = keccak256(
172+
bytes32 digest = keccak256(
173173
abi.encodePacked(
174174
bytes1(0x19),
175175
bytes1(0),
@@ -181,7 +181,7 @@ contract EthereumDIDRegistry {
181181
delegate
182182
)
183183
);
184-
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate);
184+
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, digest), delegateType, delegate);
185185
}
186186

187187
function setAttribute(
@@ -213,7 +213,7 @@ contract EthereumDIDRegistry {
213213
bytes memory value,
214214
uint256 validity
215215
) public {
216-
bytes32 hash = keccak256(
216+
bytes32 digest = keccak256(
217217
abi.encodePacked(
218218
bytes1(0x19),
219219
bytes1(0),
@@ -226,7 +226,7 @@ contract EthereumDIDRegistry {
226226
validity
227227
)
228228
);
229-
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value, validity);
229+
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, digest), name, value, validity);
230230
}
231231

232232
function revokeAttribute(
@@ -255,7 +255,7 @@ contract EthereumDIDRegistry {
255255
bytes32 name,
256256
bytes memory value
257257
) public {
258-
bytes32 hash = keccak256(
258+
bytes32 digest = keccak256(
259259
abi.encodePacked(
260260
bytes1(0x19),
261261
bytes1(0),
@@ -267,6 +267,6 @@ contract EthereumDIDRegistry {
267267
value
268268
)
269269
);
270-
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value);
270+
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, digest), name, value);
271271
}
272272
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[profile.default]
22
src = "contracts"
33
out = "out"
4-
libs = ["node_modules"]
4+
libs = ["node_modules", "lib"]
55

66
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Submodule forge-std added at 1d9650e

0 commit comments

Comments
 (0)