From 9fa68b8b65ba8d895e9fe2d16d8ddde76792218f Mon Sep 17 00:00:00 2001 From: toktar Date: Tue, 21 Nov 2023 20:27:11 +0300 Subject: [PATCH] Add Indy-Besu CI (#9) * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * Bebug Signed-off-by: toktar * added ci for indy-besu Signed-off-by: DenisRybas * run localnet error fix Signed-off-by: DenisRybas * fixed error with cargo fmt Signed-off-by: DenisRybas * removed comments Signed-off-by: DenisRybas * removed styles from scripts Signed-off-by: DenisRybas * removed styles from scripts Signed-off-by: DenisRybas * cleanup Signed-off-by: DenisRybas * removed extra actions Signed-off-by: DenisRybas * test workflow trigger Signed-off-by: DenisRybas * separated tests from lint Signed-off-by: DenisRybas * changed jobs sequence for indy-besu workflow Signed-off-by: DenisRybas * removed updated needs section for tests-vdr Signed-off-by: DenisRybas * added demos run to ci Signed-off-by: DenisRybas * Fixed errors in tests Signed-off-by: DenisRybas * renamed creator, updated docs Signed-off-by: DenisRybas * removed comments Signed-off-by: DenisRybas * fixed linter errors Signed-off-by: DenisRybas * updated post-merge hook Signed-off-by: DenisRybas * workflow trigger test Signed-off-by: DenisRybas * updated design doc Signed-off-by: DenisRybas --------- Signed-off-by: toktar Signed-off-by: DenisRybas Co-authored-by: DenisRybas --- .github/workflows/indy-besu.yml | 105 ++++++++++++++++++ indy-besu/docs/design/did-doc.md | 4 + indy-besu/network/scripts/common.sh | 4 - indy-besu/network/scripts/list.sh | 4 +- indy-besu/network/scripts/remove.sh | 4 +- indy-besu/network/scripts/resume.sh | 4 +- indy-besu/network/scripts/run.sh | 4 +- indy-besu/network/scripts/stop.sh | 4 +- indy-besu/smart_contracts/.husky/post-merge | 9 ++ indy-besu/smart_contracts/.solhintignore | 2 +- indy-besu/smart_contracts/package.json | 3 + .../vdr/src/contracts/did/types/did_doc.rs | 2 +- indy-besu/vdr/src/lib.rs | 11 +- .../src/migration/credential_definition.rs | 13 ++- 14 files changed, 148 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/indy-besu.yml create mode 100755 indy-besu/smart_contracts/.husky/post-merge diff --git a/.github/workflows/indy-besu.yml b/.github/workflows/indy-besu.yml new file mode 100644 index 000000000..a56842e65 --- /dev/null +++ b/.github/workflows/indy-besu.yml @@ -0,0 +1,105 @@ +name: CI + +on: + pull_request: + paths: "indy-besu/**" + + workflow_dispatch: + +jobs: + lint-contracts: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: "20.x" + - name: Install dependencies + run: yarn install + working-directory: indy-besu/smart_contracts + - name: Lint + run: yarn lint-check + working-directory: indy-besu/smart_contracts + + test-contracts: + needs: lint-contracts + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: "20.x" + - name: Install dependencies + run: yarn install + working-directory: indy-besu/smart_contracts + - name: Unit tests + run: yarn test + working-directory: indy-besu/smart_contracts + - name: Run localnet + run: ./network/scripts/run.sh && sleep 40 + working-directory: indy-besu + - name: Demos + run: yarn demos + working-directory: indy-besu/smart_contracts + + lint-vdr: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install latest rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Lint + run: cargo fmt --check + working-directory: indy-besu/vdr + + store-artifacts: + needs: lint-vdr + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: "20.x" + - name: Install dependencies + run: yarn add hardhat + working-directory: indy-besu/smart_contracts + - name: Compile smart contracts + run: yarn compile + working-directory: indy-besu/smart_contracts + - name: Archive contract artifacts + uses: actions/upload-artifact@v3 + with: + name: smart-contracts-artifacts + path: indy-besu/smart_contracts/artifacts/** + retention-days: 3 + + test-vdr: + needs: store-artifacts + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install latest rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Download contract artifcats + uses: actions/download-artifact@v3 + with: + name: smart-contracts-artifacts + path: indy-besu/smart_contracts/artifacts + - name: Run localnet + run: ./network/scripts/run.sh && sleep 40 + working-directory: indy-besu + - name: Test + run: cargo test --features=ledger_test -- --test-threads=1 + working-directory: indy-besu/vdr diff --git a/indy-besu/docs/design/did-doc.md b/indy-besu/docs/design/did-doc.md index e4f46ef7b..8d3216dbc 100644 --- a/indy-besu/docs/design/did-doc.md +++ b/indy-besu/docs/design/did-doc.md @@ -23,6 +23,7 @@ } struct DidMetadata { + address creator; uint256 created; uint256 updated; bool deactivated; @@ -69,6 +70,7 @@ "did:indy2:testnet:SEp33q43PsdP7nDATyySSH": { document: DidDoc, metadata: { + creator: 0x93917cadbace5dfce132b991732c6cda9bcc5b8a, created: 1234, updated: 1234, deactivated: false @@ -184,6 +186,7 @@ Contract name: **DidRegistry** * Restrictions: * DID must exist * DID must be active + * Sender must be DID creator * Format: ``` DidRegistry.updateDid( @@ -220,6 +223,7 @@ Contract name: **DidRegistry** * Restrictions: * DID must exist * DID must be active + * Sender must be DID creator * Format: ``` DidRegistry.deactivateDid( diff --git a/indy-besu/network/scripts/common.sh b/indy-besu/network/scripts/common.sh index 47c2cb604..983c4e479 100755 --- a/indy-besu/network/scripts/common.sh +++ b/indy-besu/network/scripts/common.sh @@ -7,10 +7,6 @@ if [ "$me" = ".common.sh" ];then exit 1 fi -# bold and normal text styles -bold=$(tput bold) -normal=$(tput sgr0) - # checks docker installed hash docker 2>/dev/null || { echo >&2 "This script requires Docker but it's not installed." diff --git a/indy-besu/network/scripts/list.sh b/indy-besu/network/scripts/list.sh index 491431da5..1600169a8 100755 --- a/indy-besu/network/scripts/list.sh +++ b/indy-besu/network/scripts/list.sh @@ -20,9 +20,9 @@ maxRetryCount=50 HOST=${DOCKER_PORT_2375_TCP_ADDR:-"localhost"} # Displays links to exposed services -echo "${bold}*************************************" +echo "*************************************" echo "Localnet " -echo "*************************************${normal}" +echo "*************************************" echo "----------------------------------" echo "List endpoints and services" diff --git a/indy-besu/network/scripts/remove.sh b/indy-besu/network/scripts/remove.sh index 3e02111a9..08ca38adb 100755 --- a/indy-besu/network/scripts/remove.sh +++ b/indy-besu/network/scripts/remove.sh @@ -22,9 +22,9 @@ removeDockerImage(){ fi } -echo "${bold}*************************************" +echo "*************************************" echo "Localnet" -echo "*************************************${normal}" +echo "*************************************" echo "Stop and remove network..." docker compose --profile services down -v diff --git a/indy-besu/network/scripts/resume.sh b/indy-besu/network/scripts/resume.sh index b7134eef6..4dd898c6a 100755 --- a/indy-besu/network/scripts/resume.sh +++ b/indy-besu/network/scripts/resume.sh @@ -16,9 +16,9 @@ NO_LOCK_REQUIRED=false . ./.env source "$(dirname "$0")/common.sh" -echo "${bold}*************************************" +echo "*************************************" echo "Localnet" -echo "*************************************${normal}" +echo "*************************************" echo "Resuming network..." echo "----------------------------------" diff --git a/indy-besu/network/scripts/run.sh b/indy-besu/network/scripts/run.sh index 5cf92831e..5a4fe089e 100755 --- a/indy-besu/network/scripts/run.sh +++ b/indy-besu/network/scripts/run.sh @@ -19,9 +19,9 @@ source "$(dirname "$0")/common.sh" # Build and run containers and network echo "docker-compose.yml" > ${LOCK_FILE} -echo "${bold}*************************************" +echo "*************************************" echo "Localnet" -echo "*************************************${normal}" +echo "*************************************" echo "Start network" echo "--------------------" diff --git a/indy-besu/network/scripts/stop.sh b/indy-besu/network/scripts/stop.sh index c0d9c44f3..faa6f3de9 100755 --- a/indy-besu/network/scripts/stop.sh +++ b/indy-besu/network/scripts/stop.sh @@ -16,9 +16,9 @@ NO_LOCK_REQUIRED=false . ./.env source "$(dirname "$0")/common.sh" -echo "${bold}*************************************" +echo "*************************************" echo "Localnet" -echo "*************************************${normal}" +echo "*************************************" echo "Stopping network" echo "----------------------------------" diff --git a/indy-besu/smart_contracts/.husky/post-merge b/indy-besu/smart_contracts/.husky/post-merge new file mode 100755 index 000000000..e5a1d3af5 --- /dev/null +++ b/indy-besu/smart_contracts/.husky/post-merge @@ -0,0 +1,9 @@ +#!/bin/bash + +CONTRACTS_DIR="indy-besu/smart_contracts" + +# Change to the smart contracts directory +cd "$CONTRACTS_DIR" || exit + +# Run yarn compile to compile new smart contracts +yarn compile diff --git a/indy-besu/smart_contracts/.solhintignore b/indy-besu/smart_contracts/.solhintignore index 2cb78b4d2..384fcaea7 100644 --- a/indy-besu/smart_contracts/.solhintignore +++ b/indy-besu/smart_contracts/.solhintignore @@ -1,2 +1,2 @@ -# generated regex contract +# Generated regex contract. DidRegex.sol \ No newline at end of file diff --git a/indy-besu/smart_contracts/package.json b/indy-besu/smart_contracts/package.json index c5cc896d3..1acafcf36 100644 --- a/indy-besu/smart_contracts/package.json +++ b/indy-besu/smart_contracts/package.json @@ -9,6 +9,9 @@ "ts-lint": "tslint --fix -p tsconfig.json -c tslint.json", "solhint": "solhint --fix -f unix -c solhint.json contracts/**/*.sol", "lint": "yarn ts-lint && yarn solhint", + "ts-lint-check": "tslint -p tsconfig.json -c tslint.json", + "solhint-check": "solhint -c solhint.json contracts/**/*.sol", + "lint-check": "yarn ts-lint-check && yarn solhint-check", "format": "prettier --write \"contracts/**/*.sol\" \"scripts/**/*.ts\" \"contracts-ts/**/*.ts\" \"demos/**/*.ts\" \"test/**/*.ts\"", "run-on-besu": "hardhat run --network besu", "demos": "find demos -name '*.ts' -maxdepth 1 -print0 | xargs -0 -n 1 yarn run-on-besu", diff --git a/indy-besu/vdr/src/contracts/did/types/did_doc.rs b/indy-besu/vdr/src/contracts/did/types/did_doc.rs index dc28146a3..15be01935 100644 --- a/indy-besu/vdr/src/contracts/did/types/did_doc.rs +++ b/indy-besu/vdr/src/contracts/did/types/did_doc.rs @@ -61,7 +61,7 @@ pub struct DidDocument { #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct DidMetadata { - pub creator_address: Address, + pub creator: Address, pub created: u128, pub updated: u128, pub deactivated: bool, diff --git a/indy-besu/vdr/src/lib.rs b/indy-besu/vdr/src/lib.rs index 2204f4475..487c44bfe 100644 --- a/indy-besu/vdr/src/lib.rs +++ b/indy-besu/vdr/src/lib.rs @@ -437,8 +437,9 @@ mod tests { } mod validator { - use crate::contracts::network::ValidatorAddresses; - use crate::signer::basic_signer::test::basic_signer; + use crate::{ + contracts::network::ValidatorAddresses, signer::basic_signer::test::basic_signer, + }; use super::*; @@ -495,7 +496,8 @@ mod tests { let signer = basic_signer(); let (new_validator_address, _) = signer.create_account(None).unwrap(); let client = client(Some(signer)); - role::build_and_submit_assign_role_transaction(&client, &ACCOUNT, &Role::Steward).await; + role::build_and_submit_assign_role_transaction(&client, &TRUSTEE_ACC, &Role::Steward) + .await; let receipt = build_and_submit_add_validator_transaction(&client, &new_validator_address).await; @@ -522,7 +524,8 @@ mod tests { let signer = basic_signer(); let (new_validator_address, _) = signer.create_account(None).unwrap(); let client = client(Some(signer)); - role::build_and_submit_assign_role_transaction(&client, &ACCOUNT, &Role::Steward).await; + role::build_and_submit_assign_role_transaction(&client, &TRUSTEE_ACC, &Role::Steward) + .await; ValidatorControl::add_validator(&client, &TRUSTEE_ACC, &new_validator_address) .await diff --git a/indy-besu/vdr/src/migration/credential_definition.rs b/indy-besu/vdr/src/migration/credential_definition.rs index 3ee1a3118..e88c4a419 100644 --- a/indy-besu/vdr/src/migration/credential_definition.rs +++ b/indy-besu/vdr/src/migration/credential_definition.rs @@ -39,7 +39,8 @@ impl CredentialDefinitionId { vdr_error })?; let schema_id = parts.get(3).ok_or_else(|| { - let vdr_error = VdrError::CommonInvalidData("Invalid indy cred def schema id".to_string()); + let vdr_error = + VdrError::CommonInvalidData("Invalid indy cred def schema id".to_string()); warn!( "Error: {:?} during converting CredentialDefinitionId from indy format", @@ -64,7 +65,8 @@ impl CredentialDefinitionId { trace!( "CredentialDefinitionId convert from Indy format: {} has finished. Result: {:?}", - id, cred_def_id + id, + cred_def_id ); Ok(cred_def_id) @@ -85,7 +87,8 @@ impl CredentialDefinition { trace!( "CredentialDefinition convert from Indy format: {} has finished. Result: {:?}", - credential_definition, besu_cred_def + credential_definition, + besu_cred_def ); besu_cred_def @@ -104,7 +107,7 @@ impl TryFrom for CredentialDefinition { let parts: Vec<&str> = cred_def.id.split(':').collect(); let id = parts.get(0).ok_or_else(|| { let vdr_error = VdrError::CommonInvalidData("Invalid indy cred def id".to_string()); - + warn!("Error: {:?} during converting CredentialDefinition from IndyCredentialDefinitionFormat", vdr_error); vdr_error @@ -145,7 +148,7 @@ impl Into for CredentialDefinition { self ); - let indy_cred_def =IndyCredentialDefinitionFormat { + let indy_cred_def = IndyCredentialDefinitionFormat { id: format!( "{}:3:{}:{}:{}", self.issuer_id.value(),