From 3aadd4d4190fd28904ce72a59e1003272d8812cb Mon Sep 17 00:00:00 2001 From: 0xawaz Date: Mon, 25 Nov 2024 12:17:20 +0100 Subject: [PATCH] fix: insert test tenant binary keys instead of paths --- fhevm-engine/fhevm-db/Dockerfile | 4 +-- fhevm-engine/fhevm-db/initialize_db.sh | 29 +++++++++++++++++++ ...20241120173212_insert_test_tenant.down.sql | 1 - .../20241120173212_insert_test_tenant.up.sql | 19 ------------ 4 files changed, 31 insertions(+), 22 deletions(-) delete mode 100644 fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.down.sql delete mode 100644 fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.up.sql diff --git a/fhevm-engine/fhevm-db/Dockerfile b/fhevm-engine/fhevm-db/Dockerfile index a2bc3d97..6d60f280 100644 --- a/fhevm-engine/fhevm-db/Dockerfile +++ b/fhevm-engine/fhevm-db/Dockerfile @@ -3,7 +3,7 @@ FROM rust:1.74 # Install dependencies and tools RUN apt-get update && \ - apt-get install -y libpq-dev && \ + apt-get install -y libpq-dev postgresql-client vim-common && \ cargo install sqlx-cli --no-default-features --features postgres --locked && \ apt-get clean && rm -rf /var/lib/apt/lists/* @@ -16,4 +16,4 @@ COPY fhevm-engine/fhevm-keys /fhevm-keys RUN chmod +x /initialize_db.sh # Run the initialization script as the entrypoint -ENTRYPOINT ["/bin/bash", "/initialize_db.sh"] \ No newline at end of file +ENTRYPOINT ["/bin/bash", "/initialize_db.sh"] diff --git a/fhevm-engine/fhevm-db/initialize_db.sh b/fhevm-engine/fhevm-db/initialize_db.sh index 301f43c1..90285436 100644 --- a/fhevm-engine/fhevm-db/initialize_db.sh +++ b/fhevm-engine/fhevm-db/initialize_db.sh @@ -8,4 +8,33 @@ sqlx database create echo "Running migrations..." sqlx migrate run --source /migrations || { echo "Failed to run migrations."; exit 1; } +# 3. Insert test tenant with keys +echo "Running Insert test tenant..." +TENANT_API_KEY=a1503fb6-d79b-4e9e-826d-44cf262f3e05 +ACL_CONTRACT_ADDRESS=0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2 +INPUT_VERIFIER_ADDRESS=0x69dE3158643e738a0724418b21a35FAA20CBb1c5 + +PKS="$(cat /fhevm-keys/pks | xxd -p | tr -d '\n')" +SKS="$(cat /fhevm-keys/sks | xxd -p | tr -d '\n')" +PUBLIC_PARAMS="$(cat /fhevm-keys/pp | xxd -p | tr -d '\n')" +CKS="$(cat /fhevm-keys/cks | xxd -p | tr -d '\n')" + +QUERY=" +INSERT INTO tenants(tenant_api_key, chain_id, acl_contract_address, verifying_contract_address, pks_key, sks_key, public_params, cks_key) + VALUES ( + '${TENANT_API_KEY}', + 12345, + '${ACL_CONTRACT_ADDRESS}', + '${INPUT_VERIFIER_ADDRESS}', + decode('${PKS}', 'hex'), + decode('${SKS}', 'hex'), + decode('${PUBLIC_PARAMS}', 'hex'), + decode('${CKS}', 'hex') + ) +" + +echo $QUERY | psql $DATABASE_URL + +echo 'Test tenant insertion done' + echo "Database initialization complete." \ No newline at end of file diff --git a/fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.down.sql b/fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.down.sql deleted file mode 100644 index 0ae3b2a5..00000000 --- a/fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.down.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE FROM tenants WHERE tenant_api_key = 'a1503fb6-d79b-4e9e-826d-44cf262f3e05'; \ No newline at end of file diff --git a/fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.up.sql b/fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.up.sql deleted file mode 100644 index 9fdef746..00000000 --- a/fhevm-engine/fhevm-db/migrations/20241120173212_insert_test_tenant.up.sql +++ /dev/null @@ -1,19 +0,0 @@ -INSERT INTO tenants ( - tenant_api_key, - chain_id, - acl_contract_address, - verifying_contract_address, - pks_key, - sks_key, - public_params, - cks_key -) VALUES ( - 'a1503fb6-d79b-4e9e-826d-44cf262f3e05', - 12345, - '0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2', - '0x69dE3158643e738a0724418b21a35FAA20CBb1c5', - '/fhevm-keys/pks', - '/fhevm-keys/sks', - '/fhevm-keys/pp', - '/fhevm-keys/cks' -) ON CONFLICT DO NOTHING; \ No newline at end of file