From 4134612ebf4173830c58a2c21405a550cf097613 Mon Sep 17 00:00:00 2001
From: Stefano Cunego <93382903+kukkok3@users.noreply.github.com>
Date: Wed, 20 Nov 2024 18:55:37 +0100
Subject: [PATCH 1/4] Feat: update testplan template (#1243)
* chore: update testplan
* fix
* fix
* fix
* fix
---
.github/ISSUE_TEMPLATE/test_plan.yml | 52 ++++++++++++++++++++++++++--
1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/.github/ISSUE_TEMPLATE/test_plan.yml b/.github/ISSUE_TEMPLATE/test_plan.yml
index 889d205f99b..7486a894875 100644
--- a/.github/ISSUE_TEMPLATE/test_plan.yml
+++ b/.github/ISSUE_TEMPLATE/test_plan.yml
@@ -1,5 +1,5 @@
name: Test Plan
-description: Create a test plan
+description: Create a test plan.
title: "[Test plan]:
"
labels: ["testplan"]
projects: ["/input-output-hk/102"]
@@ -11,18 +11,64 @@ body:
validations:
required: true
+ - type: textarea
+ attributes:
+ label: Stakeholders
+ description: Insert the relevant stakeholders that need to understand, review and approve the test plan
+ placeholder: |
+ | Name | Role | Approval |
+ |:-:|:-:|:-:|
+ | | | ☐|
+ validations:
+ required: true
+
- type: input
attributes:
label: Test plan document
placeholder: https://input-output-hk.github.io/catalyst-voices/architecture/10_quality/testplans/template.md
- description: A link to the test plan document.
+ description: A link to the test plan document if it is needed.
+ validations:
+ required: false
+
+ - type: textarea
+ attributes:
+ label: Requirements
+ description: Business requirements, insert links to relevant Github or JIRA tickets, list what platforms are supported, what will not be tested, etc
+ validations:
+ required: true
+
+ - type: textarea
+ attributes:
+ label: Acceptance criteria
+ description: List the acceptance criteria for this feature
+ validations:
+ required: true
+
+ - type: textarea
+ attributes:
+ label: Risks
+ description: Describe what risks can affect the accomplishment of the testplan. For example documentation is missing, not enough resources etc
+ validations:
+ required: true
+
+ - type: textarea
+ attributes:
+ label: Tools
+ description: Describe what tools will be needed for the testing, if new tools are needed to be developed
+ validations:
+ required: true
+
+ - type: textarea
+ attributes:
+ label: Test strategy
+ description: Describe the strategy for testing
validations:
required: true
- type: textarea
attributes:
label: Test cases
- description: The list of the test cases that are part of the test plan
+ description: The list of the test cases that are part of the test plan. Use the ACC framework [https://input-output-hk.github.io/catalyst-voices/architecture/10_quality/testplans/template/#acc-framework] to help you define testcases
placeholder: |
-[] https://github.com/input-output-hk/catalyst-voices/issues/1
-[] https://github.com/input-output-hk/catalyst-voices/issues/1
From c89f7424736e8a36dc954577fd8f64349d4edb08 Mon Sep 17 00:00:00 2001
From: Stefano Cunego <93382903+kukkok3@users.noreply.github.com>
Date: Thu, 21 Nov 2024 10:27:19 +0100
Subject: [PATCH 2/4] fix: testplan template (#1245)
---
.github/ISSUE_TEMPLATE/test_plan.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/ISSUE_TEMPLATE/test_plan.yml b/.github/ISSUE_TEMPLATE/test_plan.yml
index 7486a894875..c728dd6d20a 100644
--- a/.github/ISSUE_TEMPLATE/test_plan.yml
+++ b/.github/ISSUE_TEMPLATE/test_plan.yml
@@ -17,8 +17,8 @@ body:
description: Insert the relevant stakeholders that need to understand, review and approve the test plan
placeholder: |
| Name | Role | Approval |
- |:-:|:-:|:-:|
- | | | ☐|
+ |:-: |:-:|:-:|
+ | | | |
validations:
required: true
From 3bf0ccf6cbc38359e888e53cb24ada753b0f2ebc Mon Sep 17 00:00:00 2001
From: Steven Johnson
Date: Mon, 25 Nov 2024 23:03:34 +0700
Subject: [PATCH 3/4] feat(cat-gateway): Finliaze CIP36 Endpoint Cleanup
(#1241)
* fix: api endpoint draft
Signed-off-by: bkioshn
* fix: api health endpoint v1
Signed-off-by: bkioshn
* fix: remove bad request from errorResponses
Signed-off-by: bkioshn
* fix: add bad req to get /registration
Signed-off-by: bkioshn
* fix: error logging
Signed-off-by: bkioshn
* fix: remove validation error
Signed-off-by: bkioshn
* fix: registration get error name
Signed-off-by: bkioshn
* chore:format
Signed-off-by: bkioshn
* fix: get json schema from openapi spec
Signed-off-by: bkioshn
* fix: move schema utils
Signed-off-by: bkioshn
* fix: optional field
Signed-off-by: bkioshn
* fix: config key
Signed-off-by: bkioshn
* fix: cat-gateway code gen
Signed-off-by: bkioshn
* fix: api name in cat-voice
Signed-off-by: bkioshn
* fix: cat-voice format
Signed-off-by: bkioshn
* chore: fix spacing
Signed-off-by: bkioshn
* chore: fix spacing
Signed-off-by: bkioshn
* chore: change tag config description
* test: add test for default validator
* fix: add spectral ruleset
Signed-off-by: bkioshn
* fix(cat-gateway): Sort the spelling words, and use latest deny.toml
* fix(cat-gateway): Fix broken pre-push justfile target
* docs(cat-gateway): cleanup
* docs(cat-gateway): Fix API Groups and document them better
* docs(cat-gateway): Add documentation to the health/inspection endpoint
* docs(cat-gateway): Add descriptions for cardano/cip36/latest_registration/stake_addr
* docs(cat-gateway): Document stake key hash and vote key endpoints for cardano
* docs(cat-gateway): add documentation to config/frontend
* docs(cat-gateway): Add api docs for frontend schema
* docs(cat-gateway): Move legacy registration endpoints into the Legacy TAG.
* docs(cat-gateway): Remaining documentable entities documented
* fix: update openapi linter
Signed-off-by: bkioshn
* docs(cat-gateway): Add more constraints to parameters and json bodies
* fix: openapi lint FUNCTION name
Signed-off-by: bkioshn
* fix: CIP36 example and description
Signed-off-by: bkioshn
* fix(cat-gateway): cleanup error handling, and add a global 429 response to all endpoints.
* fix: config endpoint example, desc, and return
Signed-off-by: bkioshn
* chore: remove todo
Signed-off-by: bkioshn
* fix: move config object
Signed-off-by: bkioshn
* fix: move cip36 object
Signed-off-by: bkioshn
* docs(cat-gateway): Add missing headers to responses
* docs(cat-gateway): Cleanup the rest of the documentation in the api
* fix(cat-gateway): Fix OpenAPI linting and add autogenerated api file for dart.
* refactor(cat-gateway): Better generalize the OpenAPI simple string type creation macro.
* fix(cat-gateway): Add APIKey and CatToken auth to some endpoints. Add 401 and 403 common responses.
* fix(cat-gateway): Add universal 422 response to all endpoints, and try and make all endpoint validation use it.
* fix: add cardano stake address type
Signed-off-by: bkioshn
* fix(cat-gateway): stake address type
Signed-off-by: bkioshn
* fix(cat-gateway): Refactor the RBAC Token auth, so it's easier to maintain.
* fix(cat-gateway): stake address name
Signed-off-by: bkioshn
* fix(cat-gateway): Add no auth and no-auth+rbac auth schemes
* fix(cat-gateway): format + stake addr example
Signed-off-by: bkioshn
* fix(cat-gateway): code format
* fix(cat-gateway): openapi spectral example rules
Signed-off-by: bkioshn
* fix(cat-gateway): Move legacy registration endpoint under Legacy Tag
* fix(cat-gateway): Add Auth to all endpoints
* fix(docs): Remove obsolete lint config file
* fix(cat-gateway): Make config.toml match upstream
* docs(docs): update project dictionary
* feat(cat-gateway): add target to make it quick to check openapi lints locally
* fix(cat-gateway): Remove reference to hermes
* fix(cat-gateway): Add auth to rbac endpoints
* docs(cat-gateway): Add full docs for v1/votes/plan/account-votes
* docs(cat-gateway): Add example for ip address query argument
* fix(cat-gateway): Define and abstract Ed25519 Public Keys as hex encoded parameters
* fix(cat-gateway): Make sure string api types do not directly expose the internal string
* fix(cat-gateway): Make conversion from a Ed25519 pub key hex value to a Verifyingkey infallible
* fix(cat-gateway): Fix native asset response types
* docs(cat-gateway): fix comments
* fix(cat-gateway): Autogenerate flutter files
* fix(cat-gateway): Exclude legacy endpoints from needing api examples
* fix(cat-gateway): WIP improving cip36 endpoint docs
* fix(docs): Make targets to re-check the generated schema easy.
* fix: spectral ruleset for linting query params description
* feat: parameter rule
* fix: debug function
* docs(cat-gateway): Make schema lint accept description inside a schema in a query parameter
* fix(cat-gateway): remove debug logic from api docs lint
* fix(cat-gateway): Don't put expanded program into git
* Make error response comments consistent
* test(cat-gateway): Add local operation to easily expand macros in the service code
* fix(cat-gateway): CIP36 Structured endpoint
* fix: speling
* fix(rust): cleanup/normalize nonce validation
* fix(rust): code format
* Update catalyst-gateway/bin/src/service/common/types/cardano/cip19_shelley_address.rs
Co-authored-by: bkioshn <35752733+bkioshn@users.noreply.github.com>
* Update catalyst-gateway/bin/src/service/common/types/cardano/cip19_shelley_address.rs
Co-authored-by: bkioshn <35752733+bkioshn@users.noreply.github.com>
---------
Signed-off-by: bkioshn
Co-authored-by: bkioshn
Co-authored-by: bkioshn <35752733+bkioshn@users.noreply.github.com>
Co-authored-by: Dominik Toton <166132265+dtscalac@users.noreply.github.com>
Co-authored-by: Apisit Ritreungroj
---
.config/dictionaries/project.dic | 3 +-
catalyst-gateway/.gitignore | 3 +-
catalyst-gateway/Justfile | 21 +-
catalyst-gateway/bin/Cargo.toml | 1 +
catalyst-gateway/bin/Justfile | 12 +
.../src/service/api/cardano/cip36/endpoint.rs | 32 ++
.../bin/src/service/api/cardano/cip36/mod.rs | 140 +++++++
.../{cip36.rs => cip36/old_endpoint.rs} | 0
.../src/service/api/cardano/cip36/response.rs | 166 ++++++++
.../bin/src/service/api/cardano/mod.rs | 105 +----
.../api/cardano/rbac/chain_root_get.rs | 4 +-
.../service/api/cardano/staking/assets_get.rs | 5 +-
.../src/service/api/cardano/staking/mod.rs | 2 +-
catalyst-gateway/bin/src/service/api/mod.rs | 2 +-
.../bin/src/service/common/auth/api_key.rs | 19 +-
.../service/common/objects/cardano/cip36.rs | 3 +
.../service/common/objects/cardano/hash.rs | 4 +-
.../src/service/common/objects/cardano/mod.rs | 8 +-
.../objects/cardano/registration_info.rs | 8 +-
.../common/objects/cardano/sync_state.rs | 2 +-
.../src/service/common/objects/generic/mod.rs | 3 +
.../common/objects/generic/pagination.rs | 48 +++
.../bin/src/service/common/objects/mod.rs | 1 +
.../common/responses/code_401_unauthorized.rs | 23 +-
.../common/responses/code_403_forbidden.rs | 7 +-
.../code_422_unprocessable_content.rs | 90 ++---
.../responses/code_429_too_many_requests.rs | 6 +-
.../code_500_internal_server_error.rs | 6 +-
.../responses/code_503_service_unavailable.rs | 9 +-
.../bin/src/service/common/responses/mod.rs | 2 +-
.../common/types/cardano/asset_value.rs | 2 +
.../types/cardano/cip19_shelley_address.rs | 144 +++++++
.../{address.rs => cip19_stake_address.rs} | 70 +++-
.../service/common/types/cardano/hash28.rs | 11 +-
.../src/service/common/types/cardano/mod.rs | 7 +-
.../src/service/common/types/cardano/nonce.rs | 126 ++++++
.../common/types/cardano/query/as_at.rs | 169 ++++++++
.../service/common/types/cardano/query/mod.rs | 9 +
.../types/cardano/query/stake_or_voter.rs | 200 ++++++++++
.../service/common/types/cardano/slot_no.rs | 131 +++++++
.../service/common/types/cardano/txn_index.rs | 147 +++++++
.../types/generic/ed25519_public_key.rs | 60 ++-
.../service/common/types/generic/error_msg.rs | 79 ++++
.../src/service/common/types/generic/mod.rs | 2 +
.../service/common/types/generic/query/mod.rs | 12 +
.../common/types/generic/query/pagination.rs | 360 ++++++++++++++++++
.../src/service/common/types/string_types.rs | 10 +-
.../bin/src/service/utilities/mod.rs | 23 +-
catalyst-gateway/bin/src/settings/mod.rs | 7 +
catalyst-gateway/rustfmt.toml | 2 +-
catalyst-gateway/tests/Earthfile | 2 +-
.../.spectral.yml} | 26 +-
.../openapi-v3.0-lints/functions/debug.js | 28 ++
.../functions/description-required.js | 117 ++++++
.../api/cat-gateway/stoplight_template.html | 7 +-
55 files changed, 2238 insertions(+), 248 deletions(-)
create mode 100644 catalyst-gateway/bin/Justfile
create mode 100644 catalyst-gateway/bin/src/service/api/cardano/cip36/endpoint.rs
create mode 100644 catalyst-gateway/bin/src/service/api/cardano/cip36/mod.rs
rename catalyst-gateway/bin/src/service/api/cardano/{cip36.rs => cip36/old_endpoint.rs} (100%)
create mode 100644 catalyst-gateway/bin/src/service/api/cardano/cip36/response.rs
create mode 100644 catalyst-gateway/bin/src/service/common/objects/generic/mod.rs
create mode 100644 catalyst-gateway/bin/src/service/common/objects/generic/pagination.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/cardano/cip19_shelley_address.rs
rename catalyst-gateway/bin/src/service/common/types/cardano/{address.rs => cip19_stake_address.rs} (66%)
create mode 100644 catalyst-gateway/bin/src/service/common/types/cardano/nonce.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/cardano/query/as_at.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/cardano/query/mod.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/cardano/query/stake_or_voter.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/cardano/slot_no.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/cardano/txn_index.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/generic/error_msg.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/generic/query/mod.rs
create mode 100644 catalyst-gateway/bin/src/service/common/types/generic/query/pagination.rs
rename catalyst-gateway/tests/{.oapi-v3.spectral.yml => openapi-v3.0-lints/.spectral.yml} (93%)
create mode 100644 catalyst-gateway/tests/openapi-v3.0-lints/functions/debug.js
create mode 100644 catalyst-gateway/tests/openapi-v3.0-lints/functions/description-required.js
diff --git a/.config/dictionaries/project.dic b/.config/dictionaries/project.dic
index 9288b68c6b9..a61c56ea5a4 100644
--- a/.config/dictionaries/project.dic
+++ b/.config/dictionaries/project.dic
@@ -14,6 +14,7 @@ Arbritrary
ARCHS
ARGB
Arissara
+asat
asmjs
asyncio
asyncpg
@@ -241,6 +242,7 @@ rustflags
rustfmt
rustls
rxdart
+ryszard-schossler
saibatizoku
Schemathesis
Scripthash
@@ -286,7 +288,6 @@ trailings
TXNZD
txos
Typer
-ryszard-schossler
unawaited
unchunk
Unlogged
diff --git a/catalyst-gateway/.gitignore b/catalyst-gateway/.gitignore
index fea35a6a809..699900d6cce 100644
--- a/catalyst-gateway/.gitignore
+++ b/catalyst-gateway/.gitignore
@@ -13,4 +13,5 @@ target/
# Build artifacts
cat-gateway.coverage.info
cat-gateway.junit-report.xml
-cat-gateway-api.*
\ No newline at end of file
+cat-gateway-api.*
+expanded.rs
\ No newline at end of file
diff --git a/catalyst-gateway/Justfile b/catalyst-gateway/Justfile
index 9d16e79ea20..32ae8fa693f 100644
--- a/catalyst-gateway/Justfile
+++ b/catalyst-gateway/Justfile
@@ -57,7 +57,22 @@ run-cat-gateway-mainnet: build-cat-gateway
RUST_LOG="error,cat_gateway=debug,cardano_chain_follower=debug,mithril-client=debug" \
./target/release/cat-gateway run --log-level debug
-# Do the minimal work needed to test the schema generated by cat-gateway
-quick-schema-lint: build-cat-gateway
+# expand all macros and produce a single unified source file.
+expand-macros:
+ just bin/expand-macros
+
+# Generate the current openapi schema file locally.
+generate-openapi-schema: build-cat-gateway
./target/release/cat-gateway docs cat-gateway-api.json
- docker run --rm -it -v $(pwd):/tmp stoplight/spectral:latest lint --ruleset "/tmp/tests/.oapi-v3.spectral.yml" "/tmp/cat-gateway-api.json"
\ No newline at end of file
+
+# Lint an openapi schema that has already been generated
+lint-generated-schema:
+ docker run --rm -it -v $(pwd):/tmp stoplight/spectral:latest lint --ruleset "/tmp/tests/openapi-v3.0-lints/.spectral.yml" "/tmp/cat-gateway-api.json"
+
+# Lint an openapi schema that has already been generated locally.
+# Make sure before running this command, you have installed "spectral" locally.
+lint-generated-schema-local:
+ spectral lint --ruleset "./tests/openapi-v3.0-lints/.spectral.yml" "cat-gateway-api.json"
+
+# Do the minimal work needed to test the schema generated by cat-gateway
+quick-schema-lint: generate-openapi-schema lint-generated-schema
diff --git a/catalyst-gateway/bin/Cargo.toml b/catalyst-gateway/bin/Cargo.toml
index ca17f018695..2eaedb86a82 100644
--- a/catalyst-gateway/bin/Cargo.toml
+++ b/catalyst-gateway/bin/Cargo.toml
@@ -92,6 +92,7 @@ der-parser = "9.0.0"
jsonschema = "0.26.1"
bech32 = "0.11.0"
const_format = "0.2.33"
+regex = "1.11.1"
[dev-dependencies]
proptest = "1.5.0"
diff --git a/catalyst-gateway/bin/Justfile b/catalyst-gateway/bin/Justfile
new file mode 100644
index 00000000000..1c02f5933f6
--- /dev/null
+++ b/catalyst-gateway/bin/Justfile
@@ -0,0 +1,12 @@
+# use with https://github.com/casey/just
+#
+# Developer convenience functions
+
+# cspell: words prereqs, commitlog, rustls, nocapture
+
+default:
+ @just --list --unsorted
+
+# expand all macros and produce a single unified source file.
+expand-macros:
+ cargo expand --release --bin cat-gateway > ../expanded.rs
diff --git a/catalyst-gateway/bin/src/service/api/cardano/cip36/endpoint.rs b/catalyst-gateway/bin/src/service/api/cardano/cip36/endpoint.rs
new file mode 100644
index 00000000000..cfd5d5f2a51
--- /dev/null
+++ b/catalyst-gateway/bin/src/service/api/cardano/cip36/endpoint.rs
@@ -0,0 +1,32 @@
+//! Implementation of the GET `/cardano/cip36` endpoint
+
+use std::time::Duration;
+
+use poem::http::HeaderMap;
+use tokio::time::sleep;
+
+use super::{
+ cardano::{self},
+ response, NoneOrRBAC, SlotNo,
+};
+use crate::service::common::{self};
+
+/// Process the endpoint operation
+pub(crate) async fn cip36_registrations(
+ _lookup: Option, _asat: Option,
+ _page: common::types::generic::query::pagination::Page,
+ _limit: common::types::generic::query::pagination::Limit, _auth: NoneOrRBAC,
+ _headers: &HeaderMap,
+) -> response::AllRegistration {
+ // Dummy sleep, remove it
+ sleep(Duration::from_millis(1)).await;
+
+ // Todo: refactor the below into a single operation here.
+
+ // If _asat is None, then get the latest slot number from the chain follower and use that.
+ // If _for is not defined, use the stake addresses defined for Role0 in the _auth
+ // parameter. _auth not yet implemented, so put placeholder for that, and return not
+ // found until _auth is implemented.
+
+ response::Cip36Registration::NotFound.into()
+}
diff --git a/catalyst-gateway/bin/src/service/api/cardano/cip36/mod.rs b/catalyst-gateway/bin/src/service/api/cardano/cip36/mod.rs
new file mode 100644
index 00000000000..549dc776443
--- /dev/null
+++ b/catalyst-gateway/bin/src/service/api/cardano/cip36/mod.rs
@@ -0,0 +1,140 @@
+//! CIP36 Registration Endpoints
+
+use ed25519_dalek::VerifyingKey;
+use poem::http::{HeaderMap, StatusCode};
+use poem_openapi::{param::Query, OpenApi};
+
+use self::cardano::slot_no::SlotNo;
+use super::Ed25519HexEncodedPublicKey;
+use crate::service::common::{
+ self,
+ auth::none_or_rbac::NoneOrRBAC,
+ tags::ApiTags,
+ types::cardano::{self},
+};
+
+pub(crate) mod endpoint;
+pub(crate) mod old_endpoint;
+pub(crate) mod response;
+
+/// Cardano Staking API Endpoints
+pub(crate) struct Api;
+
+#[OpenApi(tag = "ApiTags::Cardano")]
+impl Api {
+ /// CIP36 registrations.
+ ///
+ /// This endpoint gets the latest registration given either the voting key, stake
+ /// address, stake public key or the auth token.
+ ///
+ /// Registration can be the latest to date, or at a particular date-time or slot
+ /// number.
+ // Required To be able to look up for:
+ // 1. Voting Public Key
+ // 2. Cip-19 stake address
+ // 3. All - Hidden option and would need a hidden api key header (used to create a snapshot
+ // replacement.)
+ // 4. Stake addresses associated with current Role0 registration (if none of the above
+ // provided).
+ // If none of the above provided, return not found.
+ #[oai(
+ path = "/draft/cardano/registration/cip36",
+ method = "get",
+ operation_id = "cardanoRegistrationCip36"
+ )]
+ async fn get_registration(
+ &self, lookup: Query