Skip to content

Commit

Permalink
fix: switch testing framework to foundry (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 authored Oct 17, 2023
1 parent b2452c9 commit 228ecc4
Show file tree
Hide file tree
Showing 17 changed files with 1,167 additions and 887 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "packages/did-eth-registry/lib/forge-std"]
path = packages/did-eth-registry/lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.6.1
7 changes: 7 additions & 0 deletions packages/did-eth-registry/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"JuanBlanco.solidity"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
Expand Down
2 changes: 0 additions & 2 deletions packages/did-eth-registry/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.git/
cache/
artifacts/
lib/
build/
typechain/
typechain-types/
Expand Down
6 changes: 6 additions & 0 deletions packages/did-eth-registry/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"juanblanco.solidity"
]
}
106 changes: 106 additions & 0 deletions packages/did-eth-registry/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "preinstall",
"type": "shell",
"command": "forge install",
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build"
}
},
{
"label": "install",
"type": "shell",
"command": "yarn install --frozen-lockfile",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "preinstall",
"group": {
"kind": "build"
}
},
{
"label": "prettier",
"type": "shell",
"command": "yarn prettier:check",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "install",
"group": {
"kind": "build"
}
},
{
"label": "lint",
"type": "shell",
"command": "yarn lint",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "prettier",
"group": {
"kind": "build"
}
},
{
"label": "build",
"type": "shell",
"command": "forge build --sizes",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test",
"type": "shell",
"command": "forge test -vvv",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "coverage",
"type": "shell",
"command": "forge coverage",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "test",
"isDefault": false
}
},
{
"label": "gas",
"type": "shell",
"command": "forge test --gas-report",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "test",
"isDefault": false
}
}
]
}
5 changes: 3 additions & 2 deletions packages/did-eth-registry/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ COPY --chown=did:did . .
RUN yarn install --frozen-lockfile
RUN yarn prettier:check
RUN yarn lint
RUN yarn build
RUN yarn test
RUN forge test -v
RUN forge geiger --check contracts/*.sol
RUN forge coverage

USER did
31 changes: 28 additions & 3 deletions packages/did-eth-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,30 @@ needed. The list of delegateTypes to include is still to be determined.
Iterate through `DIDAttributeChanged` events for service entries, encrypted public keys, and other public names. The
attribute names are still to be determined.

## Quick Start

### Submodules

First, init submodules from the project root

```bash
$ git submodule update --recursive --init -f
```

### Registry Development

This contract supports containerized development. From Visual Studio Code Remote Containers extension

`Reopen in Container`

or

Command line build using docker

```bash
$ docker build packages/did-eth-registry -t did-eth:1
```

## Deploy contract

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

```bash
yarn install
yarn build
yarn test
$ yarn install --frozen-lockfile
$ yarn prettier:check
$ yarn lint
$ forge test -v
```
24 changes: 12 additions & 12 deletions packages/did-eth-registry/contracts/EthereumDIDRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ contract EthereumDIDRegistry {
uint8 sigV,
bytes32 sigR,
bytes32 sigS,
bytes32 hash
bytes32 digest
) internal returns (address) {
address signer = ecrecover(hash, sigV, sigR, sigS);
address signer = ecrecover(digest, sigV, sigR, sigS);
require(signer == identityOwner(identity), "bad_signature");
nonce[signer]++;
return signer;
Expand Down Expand Up @@ -82,7 +82,7 @@ contract EthereumDIDRegistry {
bytes32 sigS,
address newOwner
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
Expand All @@ -93,7 +93,7 @@ contract EthereumDIDRegistry {
newOwner
)
);
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, hash), newOwner);
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, digest), newOwner);
}

function addDelegate(
Expand Down Expand Up @@ -126,7 +126,7 @@ contract EthereumDIDRegistry {
address delegate,
uint256 validity
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
Expand All @@ -139,7 +139,7 @@ contract EthereumDIDRegistry {
validity
)
);
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate, validity);
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, digest), delegateType, delegate, validity);
}

function revokeDelegate(
Expand Down Expand Up @@ -169,7 +169,7 @@ contract EthereumDIDRegistry {
bytes32 delegateType,
address delegate
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
Expand All @@ -181,7 +181,7 @@ contract EthereumDIDRegistry {
delegate
)
);
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate);
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, digest), delegateType, delegate);
}

function setAttribute(
Expand Down Expand Up @@ -213,7 +213,7 @@ contract EthereumDIDRegistry {
bytes memory value,
uint256 validity
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
Expand All @@ -226,7 +226,7 @@ contract EthereumDIDRegistry {
validity
)
);
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value, validity);
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, digest), name, value, validity);
}

function revokeAttribute(
Expand Down Expand Up @@ -255,7 +255,7 @@ contract EthereumDIDRegistry {
bytes32 name,
bytes memory value
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
Expand All @@ -267,6 +267,6 @@ contract EthereumDIDRegistry {
value
)
);
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value);
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, digest), name, value);
}
}
2 changes: 1 addition & 1 deletion packages/did-eth-registry/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[profile.default]
src = "contracts"
out = "out"
libs = ["node_modules"]
libs = ["node_modules", "lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions packages/did-eth-registry/lib/forge-std
Submodule forge-std added at 1d9650
5 changes: 2 additions & 3 deletions packages/did-eth-registry/scripts/submitDeployTxs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ const { Transaction } = require('ethereumjs-tx')
const EthUtils = require('ethereumjs-util')
const ls = require('ls')
const path = require('path')
const ethers = require('ethers')

const gasLimits = {
EthereumDIDRegistry: 2811144, // If this value needs to be recalculated, it can be done by deploying the rawTx once and looking at gasUsed in the receipt
}

const generateDeployTx = (code, name) => {
console.log("go gen.")
console.log('go gen.')
const rawTx = {
nonce: 0,
gasPrice: 100000000000, // 100 Gwei
Expand All @@ -21,7 +20,7 @@ const generateDeployTx = (code, name) => {
data: code,
v: 27,
r: '0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798',
s: '0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
s: '0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
}
const tx = new Transaction(rawTx)
const res = {
Expand Down
Loading

0 comments on commit 228ecc4

Please sign in to comment.