-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from litentry/p-976-replicate-contracts-tests-i…
…nfrastructure-for-idhub P-976 replicate contracts tests infrastructure for idhub
- Loading branch information
Showing
129 changed files
with
17,399 additions
and
10,494 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ node_modules | |
.env | ||
.idea | ||
typechain-types | ||
coverage | ||
coverage | ||
pnpm-lock.yaml |
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,22 +1,22 @@ | ||
{ | ||
"plugins": ["prettier-plugin-solidity"], | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": false, | ||
"singleQuote": false, | ||
"useTabs": true, | ||
"printWidth": 80, | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"parser": "solidity-parse", | ||
"printWidth": 80, | ||
"tabWidth": 4, | ||
"useTabs": true, | ||
"singleQuote": false, | ||
"bracketSpacing": true | ||
} | ||
} | ||
] | ||
"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 | ||
} | ||
} | ||
] | ||
} |
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,55 +1,69 @@ | ||
![Logo](https://avatars.githubusercontent.com/u/51339301?s=200&v=4) | ||
1. ## Description | ||
|
||
## Litentry Dynamic Assertion Contracts | ||
Dynamic VC assertion contract written by solidity, using [Hardhat](https://hardhat.org) for compile and test. | ||
|
||
This repo is the contracts part separated from the [litentry-parachain](https://github.com/litentry/litentry-parachain). | ||
## Environment setup | ||
|
||
## System Requirements | ||
- 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`. | ||
|
||
- Node.js | ||
- Typescript | ||
- [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview) | ||
- Solidity | ||
## Installation | ||
|
||
## Configuration | ||
```shell | ||
nvm use | ||
corepack enable pnpm | ||
pnpm install | ||
``` | ||
|
||
- [Solidity versions](https://hardhat.org/hardhat-runner/docs/advanced/multiple-solidity-versions) | ||
- [Configuration Variables](https://hardhat.org/hardhat-runner/docs/config#configuration) | ||
## Usage | ||
|
||
## Getting started | ||
### Compile | ||
|
||
1. Install Node V18 | ||
1. Using hardhat. | ||
|
||
2. Clone this repo | ||
```shell | ||
pnpm compile | ||
``` | ||
|
||
3. Switch to the right Node.js version using NVM. | ||
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`. | ||
|
||
```typescript | ||
# From the repo's root | ||
nvm use | ||
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 | ||
``` | ||
|
||
4. Install dependencies with `npm` | ||
If you have not install remixd before, rub below script to install it. | ||
|
||
```typescript | ||
# From the repo's root | ||
npm install | ||
```shell | ||
npm install -g @remix-project/remixd | ||
``` | ||
|
||
5. Compile contracts | ||
### Testing | ||
|
||
- Test all: `pnpm test`. | ||
|
||
```typescript | ||
# From the repo's root | ||
npm run compile or npx hardhat compile | ||
```shell | ||
pnpm test | ||
``` | ||
|
||
[Compiled directory structure](https://hardhat.org/hardhat-runner/docs/advanced/artifacts#directory-structure) | ||
- Test single file: `pnpm test {testFilePath}`. | ||
|
||
6. Run ts-tests | ||
Example: | ||
|
||
```typescript | ||
# From the repo's root | ||
npm run test:all or npx hardhat test | ||
```shell | ||
pnpm test tests/token-holding-amount.ts | ||
``` | ||
|
||
[More tesing contracts details](https://hardhat.org/hardhat-runner/docs/guides/test-contracts) | ||
#### Vc DI tests(integration tests) | ||
|
||
1. Start parachain&&worker | ||
2. `pnpm install` | ||
3. `pnpm --filter integration-tests run test assertion_contracts.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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/AssertionLogic.sol"; | ||
import "./libraries/Identities.sol"; | ||
import "./DynamicAssertion.sol"; | ||
|
||
contract A1 is DynamicAssertion { | ||
function execute( | ||
Identity[] memory identities, | ||
string[] memory /*secrets*/, | ||
bytes memory /*params*/ | ||
) | ||
public | ||
override | ||
returns ( | ||
string memory, | ||
string memory, | ||
string[] memory, | ||
string memory, | ||
bool | ||
) | ||
{ | ||
string | ||
memory description = "You've identified at least one account/address in both Web2 and Web3."; | ||
string memory assertion_type = "Basic Identity Verification"; | ||
schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/1-basic-identity-verification/1-0-0.json"; | ||
|
||
bool result; | ||
|
||
bool has_web3_identity = false; | ||
bool has_web2_identity = false; | ||
|
||
for (uint256 i = 0; i < identities.length; i++) { | ||
if (Identities.is_web2(identities[i])) { | ||
has_web2_identity = true; | ||
} else if (Identities.is_web3(identities[i])) { | ||
has_web3_identity = true; | ||
} | ||
} | ||
result = has_web2_identity && has_web3_identity; | ||
|
||
AssertionLogic.CompositeCondition memory cc = AssertionLogic | ||
.CompositeCondition(new AssertionLogic.Condition[](2), true); | ||
AssertionLogic.andOp( | ||
cc, | ||
0, | ||
"$has_web2_account", | ||
AssertionLogic.Op.Equal, | ||
"true" | ||
); | ||
AssertionLogic.andOp( | ||
cc, | ||
1, | ||
"$has_web3_account", | ||
AssertionLogic.Op.Equal, | ||
"true" | ||
); | ||
|
||
string[] memory assertions = new string[](1); | ||
assertions[0] = AssertionLogic.toString(cc); | ||
|
||
return (description, assertion_type, assertions, schema_url, result); | ||
} | ||
} |
Oops, something went wrong.