Skip to content

Commit

Permalink
Merge pull request #2515 from IntersectMBO/test
Browse files Browse the repository at this point in the history
fix(#2446): fix mzero parsing error on /proposal/list
  • Loading branch information
MSzalowski authored Dec 12, 2024
2 parents ba65d02 + 90c8092 commit 2402453
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 78 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-and-deploy-test-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
cd $DEST_DIR/tests/test-infrastructure
./build-and-deploy.sh update-images
yes | docker system prune -f || echo "Ignoring system prune eror"
envs: GOVTOOL_TAG, GRAFANA_ADMIN_PASSWORD, GRAFANA_SLACK_RECIPIENT, GRAFANA_SLACK_OAUTH_TOKEN, SENTRY_DSN_BACKEND, GTM_ID, NPMRC_TOKEN, SENTRY_DSN_FRONTEND, PIPELINE_URL, USERSNAP_SPACE_API_KEY, APP_ENV, PDF_API_URL, KUBER_API_KEY
envs: GOVTOOL_TAG, GRAFANA_ADMIN_PASSWORD, GRAFANA_SLACK_RECIPIENT, GRAFANA_SLACK_OAUTH_TOKEN, SENTRY_DSN_BACKEND, GTM_ID, NPMRC_TOKEN, SENTRY_DSN_FRONTEND, PIPELINE_URL, USERSNAP_SPACE_API_KEY, APP_ENV, PDF_API_URL, KUBER_API_KEY, IPFS_GATEWAY, IPFS_PROJECT_ID
env:
GOVTOOL_TAG: ${{ github.sha }}
GRAFANA_ADMIN_PASSWORD: ${{ secrets.GRAFANA_ADMIN_PASSWORD }}
Expand All @@ -76,3 +76,5 @@ jobs:
APP_ENV: test
PDF_API_URL: ${{ secrets.PDF_API_URL }}
KUBER_API_KEY: ${{ secrets.KUBER_API_KEY }}
IPFS_GATEWAY: $${{secrets.IPFS_GATEWAY}}
IPFS_PROJECT_ID: $${{secrets.IPFS_PROJECT_ID}}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ changes.

### Fixed

-
- Fix mzero parsing error on fetching the /proposal/list [Issue 2446](https://github.com/IntersectMBO/govtool/issues/2446)

### Changed

Expand Down
29 changes: 13 additions & 16 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,29 +274,21 @@ newtype GovernanceActionDetails
deriving newtype (Show)

instance FromJSON GovernanceActionDetails where
parseJSON v@(Aeson.Object o) = do
let kvpList = map snd $ Aeson.toList o
forM_ kvpList $ \case
(Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects"
(Aeson.Array a) -> forM_ (toList a) $ \case
(Aeson.Object _) -> fail "GovernanceActionDetails cannot have nested objects"
(Aeson.Array _) -> fail "GovernanceActionDetails cannot have nested arrays"
_ -> pure ()
_ -> pure ()
return $ GovernanceActionDetails v
parseJSON _ = fail "GovernanceActionDetails has to be an object"
parseJSON v = return $ GovernanceActionDetails v

instance ToJSON GovernanceActionDetails where
toJSON (GovernanceActionDetails g) = g

instance ToSchema GovernanceActionDetails where
declareNamedSchema _ = pure $ NamedSchema (Just "GovernanceActionDetails") $ mempty
& type_ ?~ OpenApiObject
& description ?~ "A simple JSON value, with object type values, and no nested arrays"
& example
?~ toJSON
("{\"some_key\": \"some value\", \"some_key2\": [1,2,3]}" :: Text)

& description ?~ "A JSON value that can include nested objects and arrays"
& example ?~ toJSON
(Aeson.object
[ "some_key" .= ("some value" :: String)
, "nested_key" .= Aeson.object ["inner_key" .= (1 :: Int)]
, "array_key" .= [1, 2, 3 :: Int]
])

newtype GovernanceActionMetadata
= GovernanceActionMetadata Value
Expand Down Expand Up @@ -440,6 +432,11 @@ exampleProposalResponse = "{ \"id\": \"proposalId123\","
<> "\"prevGovActionIndex\": 0,"
<> "\"prevGovActionTxHash\": \"47c14a128cd024f1b990c839d67720825921ad87ed875def42641ddd2169b39c\"}"

instance ToSchema Value where
declareNamedSchema _ = pure $ NamedSchema (Just "Value") $ mempty
& type_ ?~ OpenApiObject
& description ?~ "Arbitrary JSON value"

instance ToSchema ProposalResponse where
declareNamedSchema proxy = do
NamedSchema name_ schema_ <-
Expand Down
4 changes: 2 additions & 2 deletions govtool/backend/src/VVA/Proposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ getProposals mSearchTerms = withPool $ \conn -> do
)
case result of
Left (e :: SomeException) -> do
putStrLn $ "Error fetching proposals: " <> show e
return []
Right rows -> do
return rows
Right rows -> return rows
112 changes: 56 additions & 56 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,69 +122,69 @@ data DRepRegistration
, dRepRegistrationImageHash :: Maybe Text
}

data Proposal
data Proposal
= Proposal
{ proposalId :: Integer
, proposalTxHash :: Text
, proposalIndex :: Integer
, proposalType :: Text
, proposalDetails :: Maybe Value
, proposalExpiryDate :: Maybe LocalTime
, proposalExpiryEpochNo :: Maybe Integer
, proposalCreatedDate :: LocalTime
, proposalCreatedEpochNo :: Integer
, proposalUrl :: Text
, proposalDocHash :: Text
, proposalProtocolParams :: Maybe Value
, proposalTitle :: Maybe Text
, proposalAbstract :: Maybe Text
, proposalMotivation :: Maybe Text
, proposalRationale :: Maybe Text
, proposalDRepYesVotes :: Integer
, proposalDRepNoVotes :: Integer
, proposalDRepAbstainVotes :: Integer
, proposalPoolYesVotes :: Integer
, proposalPoolNoVotes :: Integer
, proposalPoolAbstainVotes :: Integer
, proposalCcYesVotes :: Integer
, proposalCcNoVotes :: Integer
, proposalCcAbstainVotes :: Integer
, proposalPrevGovActionIndex :: Maybe Integer
, proposalPrevGovActionTxHash :: Maybe Text
{ proposalId :: Integer
, proposalTxHash :: Text
, proposalIndex :: Integer
, proposalType :: Text
, proposalDetails :: Maybe Value
, proposalExpiryDate :: Maybe LocalTime
, proposalExpiryEpochNo :: Maybe Integer
, proposalCreatedDate :: LocalTime
, proposalCreatedEpochNo :: Integer
, proposalUrl :: Text
, proposalDocHash :: Text
, proposalProtocolParams :: Maybe Value
, proposalTitle :: Maybe Text
, proposalAbstract :: Maybe Text
, proposalMotivation :: Maybe Text
, proposalRationale :: Maybe Text
, proposalDRepYesVotes :: Integer
, proposalDRepNoVotes :: Integer
, proposalDRepAbstainVotes :: Integer
, proposalPoolYesVotes :: Integer
, proposalPoolNoVotes :: Integer
, proposalPoolAbstainVotes :: Integer
, proposalCcYesVotes :: Integer
, proposalCcNoVotes :: Integer
, proposalCcAbstainVotes :: Integer
, proposalPrevGovActionIndex :: Maybe Integer
, proposalPrevGovActionTxHash :: Maybe Text
}
deriving (Show)

instance FromRow Proposal where
fromRow =
Proposal
<$> field
<*> field
<*> (floor @Scientific <$> field)
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> field
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> (floor @Scientific <$> field)
<*> field
<*> field
<$> field -- proposalId
<*> field -- proposalTxHash
<*> (floor @Scientific <$> field) -- proposalIndex
<*> field -- proposalType
<*> field -- proposalDetails
<*> field -- proposalExpiryDate
<*> field -- proposalExpiryEpochNo
<*> field -- proposalCreatedDate
<*> field -- proposalCreatedEpochNo
<*> field -- proposalUrl
<*> field -- proposalDocHash
<*> field -- proposalProtocolParams
<*> field -- proposalTitle
<*> field -- proposalAbstract
<*> field -- proposalMotivation
<*> field -- proposalRationale
<*> (floor @Scientific <$> field) -- proposalDRepYesVotes
<*> (floor @Scientific <$> field) -- proposalDRepNoVotes
<*> (floor @Scientific <$> field) -- proposalDRepAbstainVotes
<*> (floor @Scientific <$> field) -- proposalPoolYesVotes
<*> (floor @Scientific <$> field) -- proposalPoolNoVotes
<*> (floor @Scientific <$> field) -- proposalPoolAbstainVotes
<*> (floor @Scientific <$> field) -- proposalCcYesVotes
<*> (floor @Scientific <$> field) -- proposalCcNoVotes
<*> (floor @Scientific <$> field) -- proposalCcAbstainVotes
<*> field -- prevGovActionIndex
<*> field -- prevGovActionTxHash

data TransactionStatus = TransactionStatus
{ transactionConfirmed :: Bool
, votingProcedure :: Maybe Value
Expand Down
Loading

0 comments on commit 2402453

Please sign in to comment.