-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
93c07d8
commit eabb481
Showing
98 changed files
with
7,031 additions
and
2,733 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 22 additions & 2 deletions
24
tee-worker/litentry/core/assertion-build/src/dynamic/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
.deps | ||
node_modules | ||
.env | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
.prettierrc.json | ||
|
||
# TypeChain files | ||
typechain | ||
typechain-types | ||
|
||
# solidity-coverage files | ||
coverage | ||
coverage.json | ||
|
||
# Hardhat Ignition default folder for deployments against a local node | ||
ignition/deployments/chain-31337 | ||
|
||
.deps | ||
!*.sol | ||
|
||
# Remix | ||
compiler_config.json | ||
remix-compiler.config.js |
8 changes: 8 additions & 0 deletions
8
tee-worker/litentry/core/assertion-build/src/dynamic/.prettierignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
artifacts | ||
cache | ||
node_modules | ||
.env | ||
.idea | ||
typechain-types | ||
coverage | ||
pnpm-lock.yaml |
22 changes: 22 additions & 0 deletions
22
tee-worker/litentry/core/assertion-build/src/dynamic/.prettierrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"plugins": ["prettier-plugin-solidity"], | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": false, | ||
"singleQuote": true, | ||
"useTabs": false, | ||
"printWidth": 80, | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"parser": "solidity-parse", | ||
"printWidth": 80, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"bracketSpacing": true | ||
} | ||
} | ||
] | ||
} |
38 changes: 0 additions & 38 deletions
38
tee-worker/litentry/core/assertion-build/src/dynamic/.prettierrc.json
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
tee-worker/litentry/core/assertion-build/src/dynamic/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## Description | ||
|
||
Dynamic VC assertion contract written by solidity, using [Hardhat](https://hardhat.org) for compile and test. | ||
|
||
## Environment setup | ||
|
||
- Install [nvm](https://github.com/nvm-sh/nvm) | ||
- Inside the repository, run `nvm use` to set the correct Node version. | ||
- If the version is not installed, run `nvm install`. | ||
|
||
## Installation | ||
|
||
```shell | ||
nvm use | ||
corepack enable pnpm | ||
pnpm install | ||
``` | ||
|
||
## Usage | ||
|
||
### Compile | ||
|
||
1. Using hardhat. | ||
|
||
```shell | ||
pnpm compile | ||
``` | ||
|
||
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`. | ||
|
||
2. Using [Remix IDE](https://remix.ethereum.org). | ||
|
||
Should use the `dynamic` as your project root path in Remix IDE as below: | ||
|
||
```shell | ||
remixd -s your_repo_path/tee-worker/litentry/core/assertion-build/src/dynamic --remix-ide https://remix.ethereum.org | ||
``` | ||
|
||
If you have not install remixd before, rub below script to install it. | ||
|
||
```shell | ||
npm install -g @remix-project/remixd | ||
``` | ||
|
||
### Testing | ||
|
||
- Test all: `pnpm test`. | ||
|
||
```shell | ||
pnpm test | ||
``` | ||
|
||
- Test single file: `pnpm test {testFilePath}`. | ||
|
||
Example: | ||
|
||
```shell | ||
pnpm test tests/token-holding-amount.ts | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
tee-worker/litentry/core/assertion-build/src/dynamic/contracts/ProxyDynamicAssertion.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2020-2024 Trust Computing GmbH. | ||
// This file is part of Litentry. | ||
// | ||
// Litentry is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Litentry is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Litentry. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import "./libraries/Identities.sol"; | ||
|
||
interface IDynamicAssertion { | ||
function execute( | ||
Identity[] memory identities, | ||
string[] memory secrets, | ||
bytes memory params | ||
) | ||
external | ||
returns ( | ||
string memory description, | ||
string memory assertionType, | ||
string[] memory assertions, | ||
string memory schemaUrl, | ||
bool result | ||
); | ||
} | ||
|
||
// This proxy is for test purpose. | ||
contract ProxyDynamicAssertion { | ||
address private target; | ||
|
||
event DynamicAssertionGenerated( | ||
string description, | ||
string assertionType, | ||
string[] assertions, | ||
string schemaUrl, | ||
bool result | ||
); | ||
|
||
constructor(address _target) { | ||
target = _target; | ||
} | ||
|
||
function execute( | ||
Identity[] memory identities, | ||
string[] memory secrets, | ||
bytes memory params | ||
) | ||
public | ||
returns ( | ||
string memory description, | ||
string memory assertionType, | ||
string[] memory assertions, | ||
string memory schemaUrl, | ||
bool result | ||
) | ||
{ | ||
IDynamicAssertion dynamicAssertion = IDynamicAssertion(target); | ||
( | ||
description, | ||
assertionType, | ||
assertions, | ||
schemaUrl, | ||
result | ||
) = dynamicAssertion.execute(identities, secrets, params); | ||
emit DynamicAssertionGenerated( | ||
description, | ||
assertionType, | ||
assertions, | ||
schemaUrl, | ||
result | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.