diff --git a/.github/workflows/bri-3.yml b/.github/workflows/bri-3.yml index 6ffbe82b8..ae33b3122 100644 --- a/.github/workflows/bri-3.yml +++ b/.github/workflows/bri-3.yml @@ -108,6 +108,16 @@ jobs: - name: Run prisma db seed working-directory: examples/bri-3 run: npx prisma db seed + + - name: Install hardhat dependencies + working-directory: examples/bri-3/ccsm + run: npm ci + + - name: Run hardhat and deploy contracts + working-directory: examples/bri-3/ccsm + run: | + npx hardhat node & + npx hardhat run scripts/deploy.ts - name: Run e2e tests working-directory: examples/bri-3 diff --git a/examples/bri-3/README.md b/examples/bri-3/README.md index 73d90c99a..f313eb50f 100644 --- a/examples/bri-3/README.md +++ b/examples/bri-3/README.md @@ -83,12 +83,12 @@ $ npm run test -- transactions.agent.spec.ts ```bash -# e2e testing - .e2e.spec files located in ./test folder +# e2e testing - .e2e.spec files and the bash script used for running located in ./test folder # before running the tests, make sure that postgres and nats are running -# and the database is properly populated with the seed.ts command (explained above) # also make sure that the .env file contains correct values for DID login to work (as explained in the .env.sample) -$ npm run test:e2e +$ cd test +$ sh ./e2e-test.sh ``` ## Architecture diff --git a/examples/bri-3/ccsm/scripts/deploy.ts b/examples/bri-3/ccsm/scripts/deploy.ts new file mode 100644 index 000000000..9972289cc --- /dev/null +++ b/examples/bri-3/ccsm/scripts/deploy.ts @@ -0,0 +1,21 @@ +const hre = require("hardhat"); + +async function main() { + const [owner, adminAccount] = await hre.ethers.getSigners(); + + const CcsmBpiStateAnchor = await hre.ethers.getContractFactory("CcsmBpiStateAnchor"); + + const ccsmBpiStateAnchor = await CcsmBpiStateAnchor.deploy([ + await owner.getAddress(), + await adminAccount.getAddress(), + ]); + + console.log("CcsmBpiStateAnchor deployed to:", await ccsmBpiStateAnchor.getAddress()); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); \ No newline at end of file diff --git a/examples/bri-3/test/e2e-test.sh b/examples/bri-3/test/e2e-test.sh new file mode 100755 index 000000000..a8de68d6c --- /dev/null +++ b/examples/bri-3/test/e2e-test.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Function to print messages with timestamps +log_message() { + echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" +} + +# Function to run a command and log its output +run_command() { + log_message "Running command: $1" + eval $1 + if [ $? -ne 0 ]; then + log_message "Error: Command failed: $1" + exit 1 + fi +} + +# Change to ccsm directory +log_message "Changing to ccsm directory" +run_command "cd ../ccsm" + +# Start Hardhat node in the background +log_message "Starting Hardhat node" +run_command "npx hardhat node &" +HARDHAT_PID=$! +log_message "Hardhat node started with PID $HARDHAT_PID" + +# Wait for the node to start (adjust sleep time if needed) +sleep 5 + +# Deploy contracts +log_message "Deploying contracts" +run_command "npx hardhat run scripts/deploy.ts" + +# Change to test directory +log_message "Changing to root directory" +run_command "cd .." + +# Prep database +log_message "Reset and reseed database" +run_command "npx prisma migrate reset --force" + +# Run e2e tests +log_message "Running e2e tests" +run_command "npm run test:e2e" + +# Stop Hardhat node +log_message "Stopping Hardhat node" +kill $HARDHAT_PID + +log_message "Script execution completed" \ No newline at end of file