Skip to content

Commit

Permalink
Rosetta Tests (#1079)
Browse files Browse the repository at this point in the history
* initial commit

* fix exports

* boilerplate extravaganza

* she compiles

* merge maseter

* prep

* remove multinode code dupe

* put back extra dep

* partition out common code

* first batch of tests work

* account balance

* remove target chain

* remove target chain

* remove chainweb network

* add block stuff

* implement block tests

* add simple checks fro network list/options/status

* making progress. TODO's listed

* update status test

* make options test a little nicer

* fix account balance test

* small changes

* add async tests for mempool

* add fixes to mempool test, keep going on mempool transaction

* remove cruft, finish block tx test

* add construction submit endpoint test

* unnecessary scheduling

* done for the day

* last thing: remeds

* use actual devnet remediations (hash-changing update)

* remove fasttimed cpm payload

* rosetta tests done, TODO: fix the tests broken by using actual remediations

* fix pact in proc api test

* unmask -Werror

* pare back some cruft

* clean up module tests

* revert coinv2 block height increase

* revert adding remediation to txs

* remove hie.yaml

* revert whitespace changes

* add note about 20-chain upgrades

* bad merge

* remove comment + whitespace

* update header

* remove some cruft

* Update test/Chainweb/Test/Rosetta/RestAPI.hs

Co-authored-by: Linda Ortega <[email protected]>

* address linda's comments

* add note

Co-authored-by: Linda Ortega <[email protected]>
  • Loading branch information
emilypi and LindaOrtega authored Jul 9, 2020
1 parent 35e3cad commit 518a3d2
Show file tree
Hide file tree
Showing 17 changed files with 1,640 additions and 504 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/kadena-io/rosetta.git
tag: d20b0012c6f5e1d28843b89a4edd5ea652ade0c3
tag: 1ccb68d7aec0414f494fb06f591214e7cf845627

package vault
documentation: false
7 changes: 6 additions & 1 deletion chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ library
, Chainweb.RestAPI.Utils
, Chainweb.Rosetta.Internal
, Chainweb.Rosetta.RestAPI
, Chainweb.Rosetta.RestAPI.Client
, Chainweb.Rosetta.RestAPI.Server
, Chainweb.Rosetta.Util
, Chainweb.Rosetta.Utils
, Chainweb.SPV
, Chainweb.SPV.CreateProof
, Chainweb.SPV.VerifyProof
Expand Down Expand Up @@ -466,7 +467,9 @@ test-suite chainweb-tests
Chainweb.Test.Pact.Utils
Chainweb.Test.RestAPI
Chainweb.Test.RestAPI.Client_
Chainweb.Test.RestAPI.Utils
Chainweb.Test.Rosetta
Chainweb.Test.Rosetta.RestAPI
Chainweb.Test.Roundtrips
Chainweb.Test.SPV
Chainweb.Test.Store.CAS
Expand Down Expand Up @@ -666,6 +669,7 @@ executable cwtool
, chainweb-storage >= 0.1
, clock >= 0.7
, configuration-tools >= 0.5
, connection >=0.2
, containers >= 0.5
, cryptonite >= 0.25
, deepseq >= 1.4
Expand All @@ -675,6 +679,7 @@ executable cwtool
, file-embed
, errors >= 2.3
, exceptions >= 0.8
, extra >= 1.6
, file-embed >= 0.0
, formatting >= 6.3
, http-client >= 0.5
Expand Down
19 changes: 19 additions & 0 deletions src/Chainweb/Pact/TransactionExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,18 @@ applyUpgrades v cid height
applyTxs txsIO = do
infoLog "Applying upgrade!"
txs <- map (fmap payloadObj) <$> liftIO txsIO

--
-- Note (emily): the historical use of 'mapM_' here means that we are not
-- threading the updated module cache from tx to tx in our upgrades.
-- This means that the outputed module cache is the set of modules
-- loaded in the /last/ tx, and that result will go into the hash.
--
-- Whether this can be fixed in the future should be explored, but we've
-- already built fixes to address this problem that also affect the
-- hashes of later blocks.
--

local (set txExecutionConfig def) $
mapM_ applyTx txs
mc <- use txCache
Expand Down Expand Up @@ -464,6 +476,13 @@ applyTwentyChainUpgrade v cid bh
infoLog $ "Applying 20-chain upgrades on chain " <> sshow cid

let txs = fmap payloadObj <$> txlist

--
-- Note (emily): This function does not need to care about
-- module caching, because it is already seeded with the correct cache
-- state, and is not updating the module cache, unlike 'applyUpgrades'.
--

traverse_ applyTx txs
| otherwise = return ()
where
Expand Down
3 changes: 1 addition & 2 deletions src/Chainweb/Rosetta/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ import Chainweb.Pact.Service.Types (Domain'(..), BlockTxHistory(..))
import Chainweb.Payload hiding (Transaction(..))
import Chainweb.Payload.PayloadStore
import Chainweb.Rosetta.RestAPI
import Chainweb.Rosetta.Utils
import Chainweb.TreeDB (seekAncestor)
import Chainweb.Utils
import Chainweb.Version
import Chainweb.WebPactExecutionService (PactExecutionService(..))

import Chainweb.Rosetta.Util

---

--------------------------------------------------------------------------------
Expand Down
224 changes: 181 additions & 43 deletions src/Chainweb/Rosetta/RestAPI.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

Expand All @@ -14,8 +15,29 @@
--
module Chainweb.Rosetta.RestAPI
( -- * Endpoints
RosettaApi_
, RosettaApi
RosettaApi
, rosettaApi
-- * Standalone APIs for client derivation
, RosettaAccountBalanceApi
, rosettaAccountBalanceApi
, RosettaBlockTransactionApi
, rosettaBlockTransactionApi
, RosettaBlockApi
, rosettaBlockApi
, RosettaConstructionMetadataApi
, rosettaConstructionMetadataApi
, RosettaConstructionSubmitApi
, rosettaConstructionSubmitApi
, RosettaMempoolTransactionApi
, rosettaMempoolTransactionApi
, RosettaMempoolApi
, rosettaMempoolApi
, RosettaNetworkListApi
, rosettaNetworkListApi
, RosettaNetworkOptionsApi
, rosettaNetworkOptionsApi
, RosettaNetworkStatusApi
, rosettaNetworkStatusApi
-- * Errors
, RosettaFailure(..)
, rosettaError
Expand All @@ -25,16 +47,14 @@ module Chainweb.Rosetta.RestAPI

import Control.Error.Util
import Control.Monad (when)
import Control.Monad.Except (throwError)
import Control.Monad.Trans.Except (ExceptT)

import Data.Aeson (encode)
import qualified Data.Text as T

import Rosetta

import Servant.API
import Servant.Server
import Servant

import Text.Read (readMaybe)

Expand All @@ -46,46 +66,165 @@ import Chainweb.Version

---

type RosettaApi_ =
-- Accounts --
"rosetta" :> "account" :> "balance"
:> ReqBody '[JSON] AccountBalanceReq
:> Post '[JSON] AccountBalanceResp
-- Blocks --
:<|> "rosetta" :> "block" :> "transaction"
:> ReqBody '[JSON] BlockTransactionReq
:> Post '[JSON] BlockTransactionResp
:<|> "rosetta" :> "block"
:> ReqBody '[JSON] BlockReq
:> Post '[JSON] BlockResp
-- Construction --
:<|> "rosetta" :> "construction" :> "metadata"
:> ReqBody '[JSON] ConstructionMetadataReq
:> Post '[JSON] ConstructionMetadataResp
:<|> "rosetta" :> "construction" :> "submit"
:> ReqBody '[JSON] ConstructionSubmitReq
:> Post '[JSON] ConstructionSubmitResp
-- Mempool --
:<|> "rosetta" :> "mempool" :> "transaction"
:> ReqBody '[JSON] MempoolTransactionReq
:> Post '[JSON] MempoolTransactionResp
:<|> "rosetta" :> "mempool"
:> ReqBody '[JSON] MempoolReq
:> Post '[JSON] MempoolResp
-- Network --
:<|> "rosetta" :> "network" :> "list"
:> ReqBody '[JSON] MetadataReq
:> Post '[JSON] NetworkListResp
:<|> "rosetta" :> "network" :> "options"
:> ReqBody '[JSON] NetworkReq
:> Post '[JSON] NetworkOptionsResp
:<|> "rosetta" :> "network" :> "status"
:> ReqBody '[JSON] NetworkReq
:> Post '[JSON] NetworkStatusResp
-- ------------------------------------------------------------------ --
-- Rosetta Api

type RosettaApi (v :: ChainwebVersionT) = 'ChainwebEndpoint v :> Reassoc RosettaApi_

-- TODO: Investigate if Rosetta Erros can be dynamic?
type RosettaApi_ = "rosetta" :>
( -- Accounts --
RosettaAccountBalanceApi_
-- Blocks --
:<|> RosettaBlockTransactionApi_
:<|> RosettaBlockApi_
-- Construction --
:<|> RosettaConstructionMetadataApi_
:<|> RosettaConstructionSubmitApi_
-- Mempool --
:<|> RosettaMempoolTransactionApi_
:<|> RosettaMempoolApi_
-- Network --
:<|> RosettaNetworkListApi_
:<|> RosettaNetworkOptionsApi_
:<|> RosettaNetworkStatusApi_
)

rosettaApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaApi v)
rosettaApi = Proxy

-- ------------------------------------------------------------------ --
-- Standalone Endpoints + Witnesses

type RosettaApiEndpoint (v :: ChainwebVersionT) api
= 'ChainwebEndpoint v
:> "rosetta"
:> api

type RosettaAccountBalanceApi v = RosettaApiEndpoint v RosettaAccountBalanceApi_
type RosettaBlockTransactionApi v = RosettaApiEndpoint v RosettaBlockTransactionApi_
type RosettaBlockApi v = RosettaApiEndpoint v RosettaBlockApi_
type RosettaConstructionSubmitApi v = RosettaApiEndpoint v RosettaConstructionSubmitApi_
type RosettaConstructionMetadataApi v = RosettaApiEndpoint v RosettaConstructionMetadataApi_
type RosettaMempoolTransactionApi v = RosettaApiEndpoint v RosettaMempoolTransactionApi_
type RosettaMempoolApi v = RosettaApiEndpoint v RosettaMempoolApi_
type RosettaNetworkListApi v = RosettaApiEndpoint v RosettaNetworkListApi_
type RosettaNetworkOptionsApi v = RosettaApiEndpoint v RosettaNetworkOptionsApi_
type RosettaNetworkStatusApi v = RosettaApiEndpoint v RosettaNetworkStatusApi_

type RosettaAccountBalanceApi_
= "account"
:> "balance"
:> ReqBody '[JSON] AccountBalanceReq
:> Post '[JSON] AccountBalanceResp

type RosettaBlockTransactionApi_
= "block"
:> "transaction"
:> ReqBody '[JSON] BlockTransactionReq
:> Post '[JSON] BlockTransactionResp

type RosettaBlockApi_
= "block"
:> ReqBody '[JSON] BlockReq
:> Post '[JSON] BlockResp

type RosettaConstructionMetadataApi_
= "construction"
:> "metadata"
:> ReqBody '[JSON] ConstructionMetadataReq
:> Post '[JSON] ConstructionMetadataResp

type RosettaConstructionSubmitApi_
= "construction"
:> "submit"
:> ReqBody '[JSON] ConstructionSubmitReq
:> Post '[JSON] ConstructionSubmitResp

type RosettaMempoolTransactionApi_
= "mempool"
:> "transaction"
:> ReqBody '[JSON] MempoolTransactionReq
:> Post '[JSON] MempoolTransactionResp

type RosettaMempoolApi_
= "mempool"
:> ReqBody '[JSON] MempoolReq
:> Post '[JSON] MempoolResp

type RosettaNetworkListApi_
= "network"
:> "list"
:> ReqBody '[JSON] MetadataReq
:> Post '[JSON] NetworkListResp

type RosettaNetworkOptionsApi_
= "network"
:> "options"
:> ReqBody '[JSON] NetworkReq
:> Post '[JSON] NetworkOptionsResp

type RosettaNetworkStatusApi_
= "network"
:> "status"
:> ReqBody '[JSON] NetworkReq
:> Post '[JSON] NetworkStatusResp

rosettaAccountBalanceApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaAccountBalanceApi v)
rosettaAccountBalanceApi = Proxy

rosettaBlockTransactionApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaBlockTransactionApi v)
rosettaBlockTransactionApi = Proxy

rosettaBlockApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaBlockApi v)
rosettaBlockApi = Proxy

rosettaConstructionMetadataApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaConstructionMetadataApi v)
rosettaConstructionMetadataApi = Proxy

rosettaConstructionSubmitApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaConstructionSubmitApi v)
rosettaConstructionSubmitApi = Proxy

rosettaMempoolTransactionApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaMempoolTransactionApi v)
rosettaMempoolTransactionApi = Proxy

rosettaMempoolApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaMempoolApi v)
rosettaMempoolApi = Proxy

rosettaNetworkListApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaNetworkListApi v)
rosettaNetworkListApi = Proxy

rosettaNetworkOptionsApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaNetworkOptionsApi v)
rosettaNetworkOptionsApi = Proxy

rosettaNetworkStatusApi
:: forall (v :: ChainwebVersionT)
. Proxy (RosettaNetworkStatusApi v)
rosettaNetworkStatusApi = Proxy

-- ------------------------------------------------------------------ --
-- Rosetta Exceptions

-- TODO: Investigate if Rosetta Erros can be dynamic
data RosettaFailure
= RosettaChainUnspecified
| RosettaInvalidChain
Expand Down Expand Up @@ -167,4 +306,3 @@ readChainIdText :: ChainwebVersion -> T.Text -> Maybe ChainId
readChainIdText v c = do
cid <- readMaybe @Word (T.unpack c)
mkChainId v maxBound cid

Loading

0 comments on commit 518a3d2

Please sign in to comment.