Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rosetta Tests #1079

Merged
merged 68 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b874139
initial commit
emilypi Jun 15, 2020
e75d182
Merge branch 'master' into rosetta-tests
emilypi Jun 15, 2020
090986e
fix exports
emilypi Jun 15, 2020
bdff193
Merge branch 'master' into rosetta-tests
emilypi Jun 17, 2020
fda98c0
boilerplate extravaganza
emilypi Jun 17, 2020
c13b9ba
she compiles
emilypi Jun 18, 2020
80e841a
merge master
emilypi Jun 18, 2020
955791a
merge maseter
emilypi Jun 18, 2020
ffd8841
prep
emilypi Jun 18, 2020
6ac6d7d
remove multinode code dupe
emilypi Jun 18, 2020
cd8213a
put back extra dep
emilypi Jun 18, 2020
0ef7169
partition out common code
emilypi Jun 18, 2020
dde28f2
first batch of tests work
emilypi Jun 18, 2020
74ea49a
account balance
emilypi Jun 19, 2020
42d9107
remove target chain
emilypi Jun 19, 2020
74124fd
remove target chain
emilypi Jun 19, 2020
e94ddf8
remove chainweb network
emilypi Jun 19, 2020
e3dd33b
add block stuff
emilypi Jun 19, 2020
fa7a771
implement block tests
emilypi Jun 22, 2020
b73b9b1
merge master
emilypi Jun 22, 2020
b114ff0
add simple checks fro network list/options/status
emilypi Jun 23, 2020
741c334
making progress. TODO's listed
emilypi Jun 23, 2020
d493098
update status test
emilypi Jun 23, 2020
256621d
make options test a little nicer
emilypi Jun 24, 2020
c9bd5ef
fix account balance test
emilypi Jun 24, 2020
1dcc5ff
small changes
emilypi Jun 24, 2020
e6fa205
add async tests for mempool
emilypi Jun 25, 2020
5f7ee94
add fixes to mempool test, keep going on mempool transaction
emilypi Jun 25, 2020
5cfc8c4
Merge branch 'master' into rosetta-tests
emilypi Jun 25, 2020
0c67a2a
remove cruft, finish block tx test
emilypi Jun 26, 2020
2d8ab02
Merge branch 'rosetta-tests' of github.com:kadena-io/chainweb-node in…
emilypi Jun 26, 2020
0225549
add construction submit endpoint test
emilypi Jun 30, 2020
6493ef2
Merge branch 'master' into rosetta-tests
emilypi Jun 30, 2020
efb4500
unnecessary scheduling
emilypi Jun 30, 2020
d632f0f
done for the day
emilypi Jun 30, 2020
9ad98f3
Merge branch 'master' into rosetta-tests
emilypi Jul 3, 2020
45460d1
Merge branch 'master' into rosetta-tests
emilypi Jul 6, 2020
2e36deb
last thing: remeds
emilypi Jul 6, 2020
fb73811
use actual devnet remediations (hash-changing update)
emilypi Jul 6, 2020
8e15889
remove fasttimed cpm payload
emilypi Jul 6, 2020
a099c52
rosetta tests done, TODO: fix the tests broken by using actual remedi…
emilypi Jul 7, 2020
1c7e371
fix pact in proc api test
emilypi Jul 7, 2020
7558a3c
unmask -Werror
emilypi Jul 7, 2020
18bc7dc
pare back some cruft
emilypi Jul 7, 2020
f7b6be1
Merge branch 'master' into rosetta-tests
emilypi Jul 7, 2020
cb0dd1c
clean up module tests
emilypi Jul 7, 2020
f00de17
Merge branch 'rosetta-tests' of github.com:kadena-io/chainweb-node in…
emilypi Jul 7, 2020
c95e9e0
revert coinv2 block height increase
emilypi Jul 7, 2020
5a1450d
revert adding remediation to txs
emilypi Jul 8, 2020
afd67e8
remove hie.yaml
emilypi Jul 8, 2020
cd552ae
revert whitespace changes
emilypi Jul 8, 2020
e0ba6b4
Merge branch 'master' into rosetta-tests
emilypi Jul 8, 2020
ca30b4d
add note about 20-chain upgrades
emilypi Jul 8, 2020
97400fe
bad merge
emilypi Jul 8, 2020
90e0a1f
Merge branch 'master' into rosetta-tests
emilypi Jul 8, 2020
88f94ad
remove comment + whitespace
emilypi Jul 8, 2020
65b00f8
Merge branch 'rosetta-tests' of github.com:kadena-io/chainweb-node in…
emilypi Jul 8, 2020
dda1f2e
Merge branch 'master' into rosetta-tests
emilypi Jul 9, 2020
11a3c35
Merge branch 'master' into rosetta-tests
emilypi Jul 9, 2020
dc04db7
Merge branch 'master' into rosetta-tests
emilypi Jul 9, 2020
dba49b1
fix conflicts
emilypi Jul 9, 2020
7884c6f
Merge branch 'rosetta-tests' of github.com:kadena-io/chainweb-node in…
emilypi Jul 9, 2020
4095877
update header
emilypi Jul 9, 2020
c906aa0
remove some cruft
emilypi Jul 9, 2020
6a2f1a0
Merge branch 'master' into rosetta-tests
emilypi Jul 9, 2020
3697c84
Update test/Chainweb/Test/Rosetta/RestAPI.hs
emilypi Jul 9, 2020
e2cefe9
address linda's comments
emilypi Jul 9, 2020
79ce35d
add note
emilypi Jul 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_
)
emilypi marked this conversation as resolved.
Show resolved Hide resolved

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