Skip to content

Commit

Permalink
Merge pull request #3 from litentry/p-976-replicate-contracts-tests-i…
Browse files Browse the repository at this point in the history
…nfrastructure-for-idhub

P-976 replicate contracts tests infrastructure for idhub
  • Loading branch information
0xverin authored Sep 2, 2024
2 parents b86fe88 + 77f4c56 commit c8b4943
Show file tree
Hide file tree
Showing 129 changed files with 17,399 additions and 10,494 deletions.
77 changes: 65 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- dev
paths-ignore:
- "**/README.md"
- '**/README.md'
pull_request:
branches:
- dev
Expand All @@ -26,6 +26,18 @@ jobs:
node-version: 18

fmt:
runs-on: ubuntu-latest
needs:
- set-env
steps:
- uses: actions/checkout@v4

- name: Fmt check
run: |
corepack enable && corepack enable pnpm && pnpm install --frozen-lockfile
pnpm run check-format
contracts-uint-tests:
runs-on: ubuntu-latest
needs:
- set-env
Expand All @@ -34,27 +46,68 @@ jobs:

- name: Install deps
run: |
npm install
npm install --save-dev hardhat
- name: Fmt check
- name: Run contracts unit tests
run: |
npx hardhat test
- name: Run contracts unit tests
run: |
npm run fmt-check
npx hardhat test
compile-tests:
integration-tests:
runs-on: ubuntu-latest
needs:
- fmt
- contracts-uint-tests
steps:
- uses: actions/checkout@v4

- name: Install deps
- name: Pull litentry image optionally
run: |
docker pull litentry/identity-worker:latest
docker pull litentry/identity-cli:latest
docker pull litentry/litentry-chain-aio:latest
- run: docker images --all

- name: Create env file with secrets
run: |
mkdir -p /opt/worker_configs
echo "TWITTER_AUTH_TOKEN_V2=${{ secrets.TWITTER_AUTH_TOKEN_V2 }}" >> /opt/worker_configs/worker_env
echo "DISCORD_AUTH_TOKEN=${{ secrets.DISCORD_AUTH_TOKEN }}" >> /opt/worker_configs/worker_env
echo "ACHAINABLE_AUTH_KEY=${{ secrets.ACHAINABLE_AUTH_KEY }}" >> /opt/worker_configs/worker_env
echo "ONEBLOCK_NOTION_KEY=${{ secrets.ONEBLOCK_NOTION_KEY }}" >> /opt/worker_configs/worker_env
echo "NODEREAL_API_KEY=${{ secrets.NODEREAL_API_KEY }}" >> /opt/worker_configs/worker_env
echo "GENIIDATA_API_KEY=${{ secrets.GENIIDATA_API_KEY }}" >> /opt/worker_configs/worker_env
echo "MORALIS_API_KEY=${{ secrets.MORALIS_API_KEY }}" >> /opt/worker_configs/worker_env
echo "MAGIC_CRAFT_API_KEY=${{ secrets.MAGIC_CRAFT_API_KEY }}" >> /opt/worker_configs/worker_env
shell: bash

- name: Start parachain-worker
run: |
./scripts/run_parachain_worker.sh
docker ps
- name: Compile contracts
run: |
npm install
npm install --save-dev hardhat
npx hardhat compile
- name: Compile solidity
- name: Run integration tests
working-directory: ./vc-di-tests/integration-tests
run: |
npm run compile
corepack enable && corepack enable pnpm && pnpm install --no-frozen-lockfile
pnpm run test assertion_contracts.test.ts
- name: Run hardhat test
- name: Stop docker
run: |
npm run test:all
docker rm -f $(docker ps -aq)
- name: Upload docker logs if test fails
uses: actions/upload-artifact@v4
if: failure()
with:
name: integration-tests-docker-logs
path: docker-logs
if-no-files-found: ignore
retention-days: 3
19 changes: 13 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ node_modules
.env

# Hardhat files
/cache
/artifacts
cache
artifacts

# TypeChain files
/typechain
/typechain-types
typechain
typechain-types

# solidity-coverage files
/coverage
/coverage.json
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
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
.env
.idea
typechain-types
coverage
coverage
pnpm-lock.yaml
40 changes: 20 additions & 20 deletions .prettierrc
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
}
}
]
}
78 changes: 46 additions & 32 deletions README.md
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`


82 changes: 82 additions & 0 deletions contracts/A1.sol
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);
}
}
Loading

0 comments on commit c8b4943

Please sign in to comment.