Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

812 deploy contract on e2e test start #819

Merged
merged 8 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/bri-3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/bri-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions examples/bri-3/ccsm/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -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);
});
51 changes: 51 additions & 0 deletions examples/bri-3/test/e2e-test.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading