Skip to content

Commit

Permalink
Merge pull request #1144 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
Enhanced Integration Tests, Bug Fixes, and Infrastructure Updates
  • Loading branch information
pmbinapps authored Jun 3, 2024
2 parents 64ebaf7 + aaced8b commit 846cf58
Show file tree
Hide file tree
Showing 51 changed files with 863 additions and 763 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test_integration_playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ jobs:
name: allure-results
path: tests/govtool-frontend/playwright/allure-results

- name: Upload lock logs
uses: actions/upload-artifact@v3
if: always()
with:
name: lock-logs
path: tests/govtool-frontend/playwright/lock_logs.txt

env:
HOST_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io' }}
API_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io' }}/api
Expand Down
34 changes: 34 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
{
description = "GovTool and utilities monorepo.";
inputs = {
default_nixpkgs.url = "github:nixos/nixpkgs/c9ece0059f42e0ab53ac870104ca4049df41b133";
node_nixpkgs.url = "github:nixos/nixpkgs/9957cd48326fe8dbd52fdc50dd2502307f188b0d";
flake-utils.url = "github:numtide/flake-utils";
nix-inclusive.url = "github:input-output-hk/nix-inclusive";
};

inputs.default_nixpkgs.url = "github:nixos/nixpkgs/c9ece0059f42e0ab53ac870104ca4049df41b133";
inputs.node_nixpkgs.url = "github:nixos/nixpkgs/9957cd48326fe8dbd52fdc50dd2502307f188b0d";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, default_nixpkgs, node_nixpkgs, flake-utils, ... }:
outputs = { self, default_nixpkgs, node_nixpkgs, flake-utils, nix-inclusive, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
defaultPkgs = import default_nixpkgs { inherit system; config.allowBroken = true; };
nodePkgs = import node_nixpkgs { inherit system; config.allowUnfree = true; };
frontend = nodePkgs.callPackage ./govtool/frontend { pkgs = nodePkgs; };
frontend = nodePkgs.callPackage ./govtool/frontend { pkgs = nodePkgs; incl = nix-inclusive.lib.inclusive; };
in
{
packages.scripts = defaultPkgs.callPackage ./scripts/govtool { pkgs = nodePkgs; };
packages.infra = defaultPkgs.callPackage ./infra/terraform { pkgs = nodePkgs; };
packages.backend = defaultPkgs.callPackage ./govtool/backend { pkgs = defaultPkgs; };
packages.frontendModules = frontend.nodeModules;
packages.frontend = frontend.staticSite;
packages.backend = defaultPkgs.callPackage ./govtool/backend { pkgs = defaultPkgs; incl = nix-inclusive.lib.inclusive; };
packages.frontend = frontend;
packages.webserver = defaultPkgs.callPackage frontend.webserver {
staticSiteRoot = frontend.staticSite.overrideAttrs (finalAttrs: prevAttrs: {
VITE_BASE_URL = "/api";
});
};

# Example of how to change VITE variables
#packages.frontendOverride = frontend.staticSite.overrideAttrs (finalAttrs: prevAttrs: {
#packages.frontendOverride = frontend.overrideAttrs (finalAttrs: prevAttrs: {
# VITE_BASE_URL = "https://example.com:8443";
#});

Expand Down
10 changes: 8 additions & 2 deletions govtool/backend/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs ? import <nixpkgs> { } }:
{ pkgs ? import <nixpkgs> { }, incl }:
let
inherit (pkgs.lib.trivial) pipe;
inherit (pkgs) haskell;
Expand All @@ -22,7 +22,13 @@ let
modifier = drv: pipe drv [ appendLibraries appendTools ];

project = ghcPackages.developPackage {
root = ./.;
root = incl ./. [
./vva-be.cabal
./app
./src
./CHANGELOG.md
./sql
];
modifier = modifier;
overrides = self: super: { openapi3 = useBroken super.openapi3; };
};
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ "${CARDANO_NETWORK}" = "mainnet" ]]; then
else
export VITE_NETWORK_FLAG=0
fi
export VITE_BASE_URL=http://localhost
export VITE_BASE_URL=http://localhost:9999
export VITE_IS_DEV=true
export VITE_GTM_ID="${GTM_ID}"
export VITE_SENTRY_DSN="${SENTRY_DSN}"
Expand Down
43 changes: 40 additions & 3 deletions govtool/frontend/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ pkgs ? import <nixpkgs> {}
, incl
, VITE_BASE_URL ? "http://localhost"
, VITE_IS_DEV ? "true"
, VITE_GTM_ID ? ""
Expand All @@ -7,16 +8,26 @@
}:
let
VITE_NETWORK_FLAG = if CARDANO_NETWORK == "mainnet" then "1" else "0";
frontendSrc = incl ./. [
./package.json
./yarn.lock
./src
./public
./patches
./vite.config.ts
./index.html
];

nodeModules = pkgs.mkYarnPackage {
name = "govtool-node-modules";
src = ./.;
src = frontendSrc;
packageJSON = ./package.json;
yarnLock = ./yarn.lock;
nodejs = pkgs.nodejs_18;
};
staticSite = pkgs.stdenv.mkDerivation {
name = "govtool-website";
src = ./.;
src = frontendSrc;
buildInputs = [pkgs.yarn nodeModules];
inherit VITE_BASE_URL VITE_IS_DEV VITE_GTM_ID VITE_SENTRY_DSN VITE_NETWORK_FLAG;
buildPhase = ''
Expand All @@ -27,7 +38,33 @@ let
mv dist $out
'';
};
webserver = { staticSiteRoot ? staticSite, backendUrl ? "http://localhost:9999" }: let
nginxConfig = pkgs.writeText "govtool-nginx.conf" ''
daemon off;
pid /tmp/govtool-nginx.pid;
events {
}
error_log /dev/stdout info;
http {
access_log /dev/stdout combined;
server {
listen 8081;
include ${pkgs.nginx}/conf/mime.types;
root ${staticSiteRoot}/;
index index.html;
try_files $uri $uri /index.html;
location /api/ {
proxy_pass ${backendUrl}/;
}
}
}
'';
in pkgs.writeScriptBin "govtool-webserver" ''
echo "Starting nginx from site root ${staticSiteRoot}... at http://localhost:8081"
${pkgs.nginx}/bin/nginx -c ${nginxConfig} -e /dev/stderr
'';
devShell = pkgs.mkShell {
buildInputs = [pkgs.nodejs_18 pkgs.yarn];
shellHook = ''
function warn() { tput setaf $2; echo "$1"; tput sgr0; }
Expand All @@ -39,4 +76,4 @@ let
ln -s ${nodeModules.out}/libexec/voltaire-voting-app/node_modules ./node_modules
'';
};
in { inherit nodeModules devShell staticSite; }
in staticSite // { inherit nodeModules devShell staticSite webserver; }
1 change: 1 addition & 0 deletions govtool/frontend/src/components/organisms/BgCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const BgCard = ({
isActionButtonDisabled,
isLoadingActionButton,
isMobile,
onClickActionButton,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ export const ReviewCreatedGovernanceAction = ({
{label}
</Typography>
<Typography
data-testid={`governance-action-${testIdFromLabel(label)}-
content`}
data-testid={`governance-action-${testIdFromLabel(
label,
)}-content`}
sx={{ mt: 0.5, wordBreak: "break-word" }}
variant="body2"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const EditDRepForm = ({
</Box>
<ControlledField.Input
{...{ control, errors }}
dataTestId="name-input"
helpfulText={t("forms.editMetadata.dRepNameHelpfulText")}
label={t("forms.editMetadata.dRepName")}
name="dRepName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const RegisterAsDRepForm = ({
</Box>
<ControlledField.Input
{...{ control, errors }}
dataTestId="name-input"
helpfulText={t("forms.registerAsDRep.dRepNameHelpfulText")}
label={t("forms.registerAsDRep.dRepName")}
name="dRepName"
Expand Down Expand Up @@ -129,7 +130,6 @@ export const RegisterAsDRepForm = ({
placeholder={t("forms.registerAsDRep.bioPlaceholder")}
helpfulText={t("forms.registerAsDRep.bioHelpfulText")}
rules={Rules.BIO}
data-testid="bio-input"
/>
<Spacer y={4} />
<p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ export const useCreateGovernanceActionForm = (
try {
setIsLoading(true);
showLoadingModal();
if (!hash) {
throw new Error(MetadataValidationStatus.INVALID_HASH);
}
if (!hash) throw MetadataValidationStatus.INVALID_HASH;
const { status } = await validateMetadata({
url: data.storingURL,
hash,
Expand Down
6 changes: 0 additions & 6 deletions govtool/metadata-validation/src/dto/validateMetadata.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { IsUrl, IsNotEmpty, IsEnum, IsOptional } from 'class-validator';

import { MetadataStandard } from '@types';

export class ValidateMetadataDTO {
@IsNotEmpty()
hash: string;

@IsUrl()
url: string;

@IsOptional()
@IsEnum(MetadataStandard)
standard?: MetadataStandard;
}
7 changes: 6 additions & 1 deletion govtool/metadata-validation/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

app.useGlobalPipes(new ValidationPipe());
app.useGlobalPipes(
new ValidationPipe({
// Do not throw error on missing fields
exceptionFactory: () => ({ status: 200, valid: false }),
}),
);
await app.listen(process.env.PORT);
}
bootstrap();
38 changes: 38 additions & 0 deletions govtool/metadata-validation/src/schemas/cipStandardSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const CIP100_URL =
const CIP108_URL =
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#';

// Temporary URL for the CIP-119 metadata
const CIPQQQ_URL =
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-QQQ/README.md#';

export const cipStandardSchema: StandardSpecification = {
// Source of CIP-108: https://github.com/Ryun1/CIPs/blob/governance-metadata-actions/CIP-0108/README.md
[MetadataStandard.CIP108]: Joi.object({
Expand Down Expand Up @@ -46,4 +50,38 @@ export const cipStandardSchema: StandardSpecification = {
),
}),
}),
[MetadataStandard.CIPQQQ]: Joi.object({
'@context': Joi.object({
'@language': Joi.string().required(),
CIP100: Joi.string().valid(CIP100_URL).required(),
CIPQQQ: Joi.string().valid(CIPQQQ_URL).required(),
hashAlgorithm: Joi.string().valid('CIP100:hashAlgorithm').required(),
body: Joi.object(),
authors: Joi.object(),
}),
authors: Joi.array(),
hashAlgorithm: Joi.object({
'@value': Joi.string().valid('blake2b-256').required(),
}),
body: Joi.object({
bio: Joi.object({ '@value': Joi.string() }),
dRepName: Joi.object({ '@value': Joi.string() }),
email: Joi.object({ '@value': Joi.string() }),
references: Joi.array().items(
Joi.object({
'@type': Joi.string(),
'CIPQQQ:reference-label': Joi.object({
'@value': Joi.string().required(),
}),
'CIPQQQ:reference-uri': Joi.object({
'@value': Joi.string().uri().required(),
}),
'CIPQQQ:reference-hash': Joi.object({
hashDigest: Joi.string().required(),
hashAlgorithm: Joi.string().required(),
}),
}),
),
}),
}),
};
1 change: 1 addition & 0 deletions govtool/metadata-validation/src/types/validateMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MetadataValidationStatus } from '@enums';

export enum MetadataStandard {
CIP108 = 'CIP108',
CIPQQQ = 'CIPQQQ',
}

export type ValidateMetadataResult = {
Expand Down
19 changes: 18 additions & 1 deletion govtool/metadata-validation/src/utils/parseMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { MetadataStandard } from '@/types';

const CIP_108_VALUE_KEYS = ['abstract', 'motivation', 'rationale', 'title'];
export const parseMetadata = (metadata: any, standard: MetadataStandard) => {
const CIP_QQQ_VALUE_KEYS = ['bio', 'dRepName', 'email', 'references'];
export const parseMetadata = (
metadata: any,
standard = MetadataStandard.CIP108,
) => {
const parsedMetadata = {};
switch (standard) {
case MetadataStandard.CIP108:
Expand All @@ -17,6 +21,19 @@ export const parseMetadata = (metadata: any, standard: MetadataStandard) => {
}
}
return parsedMetadata;

case MetadataStandard.CIPQQQ:
for (const [key, value] of Object.entries(metadata)) {
if (CIP_QQQ_VALUE_KEYS.includes(key)) {
parsedMetadata[key] = value['@value'];
}
if (key === 'references') {
parsedMetadata[key] = (Array.isArray(value) ? value : [])?.map(
(reference) => reference['CIPQQQ:reference-uri']['@value'],
);
}
}
return parsedMetadata;
default:
return;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/govtool-frontend/playwright/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ allure-report/
.vars
.lock-pool/
.logs/
lib/_mock/wallets.json
lib/_mock/*.json

./lock_logs.txt
Loading

0 comments on commit 846cf58

Please sign in to comment.