Skip to content

Commit eabb481

Browse files
authored
Hardhat test with brc20 contract (#2927)
* feat: P-886 integrate hardhat into dynamic assertions, wrap contract in proxy contract so as to get the return value in unit test, added test for BRC20 TokenHoldingAmount. Fixed openzipline import with @ import working with remix too * fix: formatted all contracts * fix: update ci install script for Dynamic-contract step * fix: prevent lockfile update because it may cause check-format fail * fix: remove frozen-lockfile option from pnpm install, ignore pnpm-lock.yaml for prettier * fix: use hardhat instead of foundry to compile contracts * fix: use Strings.equal to simplify string compare, add remixd install step to README * add remix config file to .gitignore --------- Co-authored-by: higherordertech <higherordertech>
1 parent 93c07d8 commit eabb481

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+7031
-2733
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ jobs:
197197
- name: Tee-worker check ts code format
198198
working-directory: ./tee-worker/ts-tests
199199
run: pnpm run check-format
200+
201+
- name: Dynamic-contract install npm deps
202+
working-directory: ./tee-worker/litentry/core/assertion-build/src/dynamic
203+
run: pnpm install
204+
205+
- name: Dynamic-contract check code format
206+
working-directory: ./tee-worker/litentry/core/assertion-build/src/dynamic
207+
run: pnpm run check-format
200208

201209
- name: Fail early
202210
if: failure()

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ update-ts-dep:
186186

187187
# format
188188

189-
.PHONY: fmt ## (cargo, taplo, ts) fmt
190-
fmt: fmt-cargo fmt-taplo fmt-ts
189+
.PHONY: fmt ## (cargo, taplo, ts, solidity) fmt
190+
fmt: fmt-cargo fmt-taplo fmt-ts fmt-contract
191191

192192
.PHONY: fmt-cargo ## cargo fmt
193193
fmt-cargo:
@@ -208,6 +208,10 @@ fmt-ts:
208208
@cd ts-tests && pnpm install && pnpm run format
209209
@cd tee-worker/ts-tests && pnpm install && pnpm run format
210210

211+
.PHONY: fmt-contract ## contract fmt
212+
fmt-contract:
213+
@cd tee-worker/litentry/core/assertion-build/src/dynamic && pnpm install && pnpm run format
214+
211215
.PHONY: githooks ## install the githooks
212216
githooks:
213217
git config core.hooksPath .githooks

tee-worker/cli/lit_ts_integration_test.sh

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,14 @@ pnpm install
6868
pnpm run build
6969

7070
if [ "$TEST" = "assertion_contracts.test.ts" ]; then
71-
cd /
72-
ls assertion-contracts/
73-
cp -r assertion-contracts /ts-tests/integration-tests/contracts
74-
75-
cd /ts-tests
76-
curl -L https://foundry.paradigm.xyz | bash
77-
source /root/.bashrc
78-
apt install -y git
79-
foundryup
80-
81-
pnpm install
82-
pnpm --filter integration-tests run compile-contracts
83-
84-
else
85-
cd /ts-tests
71+
cd /assertion-contracts
8672
pnpm install
87-
73+
# compile contracts
74+
pnpm compile
75+
ln -s /assertion-contracts/artifacts/contracts /ts-tests/integration-tests/contracts
8876
fi
8977

78+
cd /ts-tests
79+
pnpm install
80+
9081
NODE_ENV=staging pnpm --filter integration-tests run test $TEST

tee-worker/docker/lit-assertion-contracts-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
- ../ts-tests:/ts-tests
77
- ../client-api:/client-api
88
- ../cli:/usr/local/worker-cli
9-
- ../litentry/core/assertion-build/src/dynamic/contracts:/assertion-contracts
9+
- ../litentry/core/assertion-build/src/dynamic:/assertion-contracts
1010

1111
build:
1212
context: ..
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
.deps
1+
node_modules
2+
.env
3+
4+
# Hardhat files
5+
cache
26
artifacts
3-
.prettierrc.json
7+
8+
# TypeChain files
9+
typechain
10+
typechain-types
11+
12+
# solidity-coverage files
13+
coverage
14+
coverage.json
15+
16+
# Hardhat Ignition default folder for deployments against a local node
17+
ignition/deployments/chain-31337
18+
19+
.deps
420
!*.sol
21+
22+
# Remix
23+
compiler_config.json
24+
remix-compiler.config.js
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
artifacts
2+
cache
3+
node_modules
4+
.env
5+
.idea
6+
typechain-types
7+
coverage
8+
pnpm-lock.yaml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"plugins": ["prettier-plugin-solidity"],
3+
"trailingComma": "es5",
4+
"tabWidth": 4,
5+
"semi": false,
6+
"singleQuote": true,
7+
"useTabs": false,
8+
"printWidth": 80,
9+
"overrides": [
10+
{
11+
"files": "*.sol",
12+
"options": {
13+
"parser": "solidity-parse",
14+
"printWidth": 80,
15+
"tabWidth": 4,
16+
"useTabs": false,
17+
"singleQuote": false,
18+
"bracketSpacing": true
19+
}
20+
}
21+
]
22+
}

tee-worker/litentry/core/assertion-build/src/dynamic/.prettierrc.json

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Description
2+
3+
Dynamic VC assertion contract written by solidity, using [Hardhat](https://hardhat.org) for compile and test.
4+
5+
## Environment setup
6+
7+
- Install [nvm](https://github.com/nvm-sh/nvm)
8+
- Inside the repository, run `nvm use` to set the correct Node version.
9+
- If the version is not installed, run `nvm install`.
10+
11+
## Installation
12+
13+
```shell
14+
nvm use
15+
corepack enable pnpm
16+
pnpm install
17+
```
18+
19+
## Usage
20+
21+
### Compile
22+
23+
1. Using hardhat.
24+
25+
```shell
26+
pnpm compile
27+
```
28+
29+
After compiled, the contract bytecode will generate in file `artifacts/contracts/**/{contractName}.sol/{contractName}.json`, e.g. the bytecode of A1 is in the file `artifacts/contracts/A1.sol/A1.json`.
30+
31+
2. Using [Remix IDE](https://remix.ethereum.org).
32+
33+
Should use the `dynamic` as your project root path in Remix IDE as below:
34+
35+
```shell
36+
remixd -s your_repo_path/tee-worker/litentry/core/assertion-build/src/dynamic --remix-ide https://remix.ethereum.org
37+
```
38+
39+
If you have not install remixd before, rub below script to install it.
40+
41+
```shell
42+
npm install -g @remix-project/remixd
43+
```
44+
45+
### Testing
46+
47+
- Test all: `pnpm test`.
48+
49+
```shell
50+
pnpm test
51+
```
52+
53+
- Test single file: `pnpm test {testFilePath}`.
54+
55+
Example:
56+
57+
```shell
58+
pnpm test tests/token-holding-amount.ts
59+
```

tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
pragma solidity ^0.8.8;
2020

21-
import "./openzeppelin/Strings.sol";
21+
import "@openzeppelin/contracts/utils/Strings.sol";
2222
import "./libraries/AssertionLogic.sol";
2323
import "./libraries/Http.sol";
2424
import "./libraries/Identities.sol";
@@ -123,22 +123,18 @@ contract A6 is DynamicAssertion {
123123
return (description, assertion_type, assertions, schema_url, result);
124124
}
125125

126-
function prepareHeaders(string memory apiKey)
127-
private
128-
pure
129-
returns (HttpHeader[] memory)
130-
{
126+
function prepareHeaders(
127+
string memory apiKey
128+
) private pure returns (HttpHeader[] memory) {
131129
HttpHeader[] memory headers = new HttpHeader[](1);
132130
// we expect first secret to be twitter api key
133131
headers[0] = HttpHeader("authorization", prepareAuthHeader(apiKey));
134132
return headers;
135133
}
136134

137-
function prepareAuthHeader(string memory apiKey)
138-
private
139-
pure
140-
returns (string memory)
141-
{
135+
function prepareAuthHeader(
136+
string memory apiKey
137+
) private pure returns (string memory) {
142138
return string(abi.encodePacked("Bearer ", apiKey));
143139
}
144140
}

0 commit comments

Comments
 (0)