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

Extract Http-Bridge specifics into a dedicated package #212

Merged
merged 6 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions .buildkite/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ echo "--- Build code and benchmarks"
stack build --bench --no-run-benchmarks

echo "+++ Run benchmarks - $NETWORK"
stack bench cardano-wallet-core:restore --interleaved-output --ba "$NETWORK +RTS -N2 -qg -A1m -I0 -T -M8G -h -RTS"
stack bench cardano-wallet-http-bridge:restore --interleaved-output --ba "$NETWORK +RTS -N2 -qg -A1m -I0 -T -M8G -h -RTS"

ARTIFACT=lib/core/restore.hp
ARTIFACT=lib/http-bridge/restore

hp2pretty $ARTIFACT
hp2pretty $ARTIFACT.hp

if [ -n "${BUILDKITE:-}" ]; then
buildkite-agent artifact upload $ARTIFACT
printf '\033]1338;url='"artifact://restore.svg"';alt='"Heap profile"'\a\n'
buildkite-agent artifact upload $ARTIFACT.svg
printf '\033]1338;url='"artifact://$ARTIFACT.svg"';alt='"Heap profile"'\a\n'
fi
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
name: "Compiling"
script:
- mkdir -p ~/.local/bin
- travis_retry curl -L -o cardano-node-simple.tar.gz https://raw.githubusercontent.com/input-output-hk/cardano-wallet/master/lib/core/test/data/cardano-node-simple/cardano-node-simple-3.0.1.tar.gz
- travis_retry curl -L -o cardano-node-simple.tar.gz https://raw.githubusercontent.com/input-output-hk/cardano-wallet/KtorZ/extract-http-bridge/lib/http-bridge/test/data/cardano-node-simple/cardano-node-simple-3.0.1.tar.gz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, temporary, will change after merged.

- tar xzf cardano-node-simple.tar.gz -C $HOME/.local/bin
- cardano-node-simple --version
- test "$(cardano-http-bridge --version)" = "cardano-http-bridge 0.0.1" || travis_retry cargo install --force --branch cardano-wallet-integration --git https://github.com/KtorZ/cardano-http-bridge.git
Expand Down Expand Up @@ -93,14 +93,14 @@ jobs:
script:
- export NETWORK=mainnet
- tar xzf $STACK_WORK_CACHE
- stack --no-terminal test cardano-wallet-core:unit
- stack --no-terminal test cardano-wallet-http-bridge:unit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in CI, we have two jobs running tests. One for testnet which run everything including integration tests. And another one for mainnet, to run a couple of unit tests with a different protocol magic. Yet, we only pattern-match on the protocol magic (and actually, have access to it) in the bridge code so there's no need to re-run the core tests on mainnet.


- stage: checks 🔬
name: "Tests (testnet)"
script:
- export NETWORK=testnet
- tar xzf $STACK_WORK_CACHE
- travis_retry curl -L -o hermes-testnet.tar.gz https://raw.githubusercontent.com/input-output-hk/cardano-wallet/master/lib/core/test/data/cardano-http-bridge/hermes-testnet.tar.gz
- travis_retry curl -L -o hermes-testnet.tar.gz https://raw.githubusercontent.com/input-output-hk/cardano-wallet/KtorZ/extract-http-bridge/lib/http-bridge/test/data/cardano-http-bridge/hermes-testnet.tar.gz
- tar xzf hermes-testnet.tar.gz -C $HOME
- stack --no-terminal test --coverage
- tar czf $STACK_WORK_CACHE .stack-work lib/**/.stack-work
Expand Down
4 changes: 2 additions & 2 deletions .weeder.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- package:
- name: cardano-wallet-core
- name: cardano-wallet-http-bridge
- section:
- name: test:integration
- message:
Expand All @@ -26,11 +26,11 @@
- module:
- name: Spec
- identifier: main

- package:
- name: cardano-wallet-launcher
- section:
- name: library
- message:
- name: Module not compiled
- module: Cardano.Launcher.Windows

3 changes: 2 additions & 1 deletion cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ executable cardano-wallet
base
, cardano-wallet-cli
, cardano-wallet-core
, cardano-wallet-http-bridge
, docopt
, servant-server
, text
Expand All @@ -57,7 +58,7 @@ executable cardano-wallet-launcher
build-depends:
base
, cardano-wallet-cli
, cardano-wallet-core
, cardano-wallet-http-bridge
, cardano-wallet-launcher
, docopt
, fmt
Expand Down
2 changes: 1 addition & 1 deletion exe/wallet/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Cardano.Wallet.Api
( Api )
import Cardano.Wallet.Api.Server
( server )
import Cardano.Wallet.Compatibility
import Cardano.Wallet.Compatibility.HttpBridge
( HttpBridge )
import Cardano.Wallet.Primitive.AddressDerivation
( FromMnemonic (..), Passphrase (..) )
Expand Down
117 changes: 0 additions & 117 deletions lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,18 @@ library
, base
, base58-bytestring
, basement
, binary
, bytestring
, cardano-crypto
, cborg
, containers
, cryptonite
, deepseq
, digest
, exceptions
, fmt
, generic-lens
, http-api-data
, http-client
, http-media
, http-types
, memory
, servant
, servant-client
, servant-client-core
, servant-server
, text
, text-class
Expand All @@ -64,32 +57,24 @@ library
hs-source-dirs:
src
exposed-modules:
Cardano.Environment
Cardano.Wallet
Cardano.Wallet.Compatibility
Cardano.Wallet.Api
Cardano.Wallet.Api.Server
Cardano.Wallet.Api.Types
Cardano.Wallet.Binary
Cardano.Wallet.Binary.Packfile
Cardano.Wallet.CoinSelection
Cardano.Wallet.CoinSelection.Fee
Cardano.Wallet.CoinSelection.Policy.LargestFirst
Cardano.Wallet.CoinSelection.Policy.Random
Cardano.Wallet.DB
Cardano.Wallet.DB.MVar
Cardano.Wallet.Network
Cardano.Wallet.Network.HttpBridge
Cardano.Wallet.Network.HttpBridge.Api
Cardano.Wallet.Primitive.AddressDerivation
Cardano.Wallet.Primitive.AddressDiscovery
Cardano.Wallet.Primitive.Mnemonic
Cardano.Wallet.Primitive.Model
Cardano.Wallet.Primitive.Types
Cardano.Wallet.Transaction
Cardano.Wallet.Transaction.HttpBridge
Data.Quantity
Servant.Extra.ContentTypes
other-modules:
Paths_cardano_wallet_core

Expand All @@ -111,15 +96,12 @@ test-suite unit
, aeson
, aeson-qq
, async
, base58-bytestring
, bytestring
, cardano-crypto
, cardano-wallet-core
, cborg
, containers
, cryptonite
, deepseq
, digest
, file-embed
, fmt
, generic-arbitrary
Expand All @@ -143,118 +125,19 @@ test-suite unit
main-is:
Main.hs
other-modules:
Cardano.EnvironmentSpec
Cardano.Wallet.Api.TypesSpec
Cardano.Wallet.ApiSpec
Cardano.Wallet.Binary.PackfileSpec
Cardano.Wallet.BinarySpec
Cardano.Wallet.CoinSelection.FeeSpec
Cardano.Wallet.CoinSelection.Policy.LargestFirstSpec
Cardano.Wallet.CoinSelection.Policy.RandomSpec
Cardano.Wallet.CoinSelectionSpec
Cardano.Wallet.DB.MVarSpec
Cardano.Wallet.DBSpec
Cardano.Wallet.Network.HttpBridge.ApiSpec
Cardano.Wallet.Network.HttpBridgeSpec
Cardano.Wallet.NetworkSpec
Cardano.Wallet.Primitive.AddressDerivationSpec
Cardano.Wallet.Primitive.AddressDiscoverySpec
Cardano.Wallet.Primitive.MnemonicSpec
Cardano.Wallet.Primitive.ModelSpec
Cardano.Wallet.Primitive.TypesSpec
Cardano.Wallet.Primitive.SigningSpec
Cardano.WalletSpec
Data.QuantitySpec
Servant.Extra.ContentTypesSpec
Spec

test-suite integration
default-language:
Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings
ghc-options:
-threaded -rtsopts
-Wall
-O2
if (!flag(development))
ghc-options:
-Werror
build-depends:
base
, aeson
, aeson-qq
, async
, bytestring
, cardano-wallet-core
, cardano-wallet-launcher
, cborg
, cryptonite
, exceptions
, generic-lens
, hspec
, hspec-core
, hspec-expectations-lifted
, http-client
, http-api-data
, http-types
, process
, template-haskell
, text
, text-class
, time
, transformers
type:
exitcode-stdio-1.0
hs-source-dirs:
test/integration
main-is:
Main.hs
other-modules:
Cardano.WalletSpec
Cardano.Wallet.Network.HttpBridgeSpec
Test.Integration.Framework.DSL
Test.Integration.Framework.Request
Test.Integration.Scenario.Wallets

benchmark restore
default-language:
Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings
ghc-options:
-threaded -rtsopts
-Wall
-O2
if (!flag(development))
ghc-options:
-Werror
build-depends:
base
, async
, bytestring
, cardano-wallet-core
, cardano-wallet-launcher
, containers
, criterion-measurement
, cryptonite
, deepseq
, digest
, fmt
, generic-lens
, process
, say
, text
, text-class
, time
, transformers
type:
exitcode-stdio-1.0
hs-source-dirs:
test/bench
main-is:
Main.hs
other-modules:
Cardano.Wallet.Primitive.AddressDiscovery.Any
6 changes: 1 addition & 5 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ module Cardano.Wallet

import Prelude

import Cardano.Wallet.Binary
( encodeSignedTx, toByteString )
import Cardano.Wallet.CoinSelection
( CoinSelection (..)
, CoinSelectionError (..)
Expand Down Expand Up @@ -81,7 +79,6 @@ import Cardano.Wallet.Primitive.Types
( Block (..)
, Coin (..)
, Direction (..)
, SignedTx (..)
, SlotId (..)
, Tx
, TxId (..)
Expand Down Expand Up @@ -319,8 +316,7 @@ mkWalletLayer db nw tl = WalletLayer
throwE $ ErrSignTx e

, submitTx = \wid (tx, meta, wit) -> do
let signed = SignedTx $ toByteString $ encodeSignedTx (tx, wit)
withExceptT ErrSubmitTxNetwork $ postTx nw signed
withExceptT ErrSubmitTxNetwork $ postTx nw (tx, wit)
DB.withLock db $ withExceptT ErrSubmitTxNoSuchWallet $ do
(w, _) <- _readWallet wid
let history = Map.fromList [(txId @t tx, (tx, meta))]
Expand Down
21 changes: 19 additions & 2 deletions lib/core/src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ import Cardano.Wallet.Api.Types
)
import Cardano.Wallet.Primitive.Types
( AddressState, WalletId )
import Data.List.NonEmpty
( NonEmpty ((:|)) )
import Network.HTTP.Media
( (//), (/:) )
import Servant.API
( (:<|>)
, (:>)
, Accept (..)
, Capture
, DeleteNoContent
, Get
Expand All @@ -28,8 +33,6 @@ import Servant.API
, QueryParam
, ReqBody
)
import Servant.Extra.ContentTypes
( Any )

type Api = Addresses :<|> Wallets :<|> Transactions

Expand Down Expand Up @@ -109,3 +112,17 @@ type CreateTransaction = "wallets"
:> "transactions"
:> ReqBody '[JSON] PostTransactionData
:> PostAccepted '[JSON] ApiTransaction

{-------------------------------------------------------------------------------
Internals
-------------------------------------------------------------------------------}

-- | Any media type
data Any

instance Accept Any where
contentTypes _ = ("*" // "*") :|
-- We also 'conveniently' accept JSON format
[ "application" // "json"
, "application" // "json" /: ("charset", "utf-8")
]
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Cardano.Wallet.Network
import Prelude

import Cardano.Wallet.Primitive.Types
( Block (..), BlockHeader (..), Hash (..), SignedTx, SlotId (..) )
( Block (..), BlockHeader (..), Hash (..), SlotId (..), Tx, TxWitness )
import Control.Exception
( Exception )
import Control.Monad.Trans.Except
Expand All @@ -40,7 +40,7 @@ data NetworkLayer m = NetworkLayer
-- ^ Get the current network tip from the chain producer

, postTx
:: SignedTx -> ExceptT ErrPostTx m ()
:: (Tx, [TxWitness]) -> ExceptT ErrPostTx m ()
-- ^ Broadcast a transaction to the chain producer
}

Expand Down
5 changes: 0 additions & 5 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ module Cardano.Wallet.Primitive.Types
, TxMeta(..)
, Direction(..)
, TxStatus(..)
, SignedTx (..)
, TxWitness (..)
, txIns

Expand Down Expand Up @@ -412,10 +411,6 @@ instance Buildable Direction where
Outgoing -> "outgoing"
Incoming -> "incoming"

-- | Wrapper around the final CBOR representation of a signed tx
newtype SignedTx = SignedTx { signedTx :: ByteString }
deriving (Show, Eq, Generic)

data TxWitness
= PublicKeyWitness ByteString (Hash "signature")
| ScriptWitness ByteString
Expand Down
Loading