Skip to content

Commit

Permalink
update benchmarks & shelley transaction specs to work with new transa…
Browse files Browse the repository at this point in the history
…ction layer.
  • Loading branch information
KtorZ committed Jan 27, 2021
1 parent 5264ba9 commit e6319b1
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ import Cardano.Wallet.Primitive.AddressDerivation
( PaymentAddress )
import Cardano.Wallet.Primitive.AddressDerivation.Shelley
( ShelleyKey )
import Cardano.Wallet.Primitive.Fee
( FeePolicy (..) )
import Cardano.Wallet.Primitive.Types
( PoolId (..)
( FeePolicy (..)
, PoolId (..)
, PoolMetadataGCStatus (..)
, PoolMetadataSource (..)
, StakePoolMetadata (..)
Expand Down
37 changes: 16 additions & 21 deletions lib/core/test/unit/Cardano/WalletSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ import Control.Monad
import Control.Monad.IO.Class
( liftIO )
import Control.Monad.Trans.Except
( ExceptT (..), runExceptT )
import Control.Monad.Trans.State.Strict
( State, evalState, state )
( runExceptT )
import Crypto.Hash
( hash )
import Data.ByteString
Expand Down Expand Up @@ -164,7 +162,6 @@ import Test.QuickCheck
, arbitrarySizedBoundedIntegral
, checkCoverage
, choose
, counterexample
, cover
, elements
, label
Expand All @@ -175,7 +172,6 @@ import Test.QuickCheck
, shrinkIntegral
, vector
, withMaxSuccess
, (.&&.)
, (===)
, (==>)
)
Expand Down Expand Up @@ -525,7 +521,7 @@ walletKeyIsReencrypted (wid, wname) (xprv, pwd) newPwd =
W.signTransaction @_ @_ wl wid () credentials newPwd ctx selection
txOld `shouldBe` txNew
where
selection = SelectionResult TxOut
selection = SelectionResult
{ inputsSelected = NE.fromList
[ ( TxIn (Hash "eb4ab6028bd0ac971809d514c92db1") 1
, TxOut (Address "source") (TokenBundle.fromCoin $ Coin 42)
Expand All @@ -536,7 +532,7 @@ walletKeyIsReencrypted (wid, wname) (xprv, pwd) newPwd =
, outputsCovered =
[ TxOut (Address "destination") (TokenBundle.fromCoin $ Coin 14) ]
, changeGenerated = NE.fromList
[ TxOut (Address "change") (TokenBundle.fromCoin $ Coin 14) ]
[ (TokenBundle.fromCoin $ Coin 1) ]
, utxoRemaining =
UTxOIndex.empty
}
Expand Down Expand Up @@ -628,28 +624,27 @@ setupFixture (wid, wname, wstate) = do
-- implements a fake signer that still produces sort of witnesses
dummyTransactionLayer :: TransactionLayer ShelleyKey
dummyTransactionLayer = TransactionLayer
{ mkStdTx = \_ _ keyFrom _slot _md cs -> do
let inps' = map (second txOutCoin) (CS.inputs cs)
let tid = mkTxId inps' (CS.outputs cs) mempty Nothing
let tx = Tx tid Nothing inps' (CS.outputs cs) mempty Nothing
wit <- forM (CS.inputs cs) $ \(_, TxOut addr _) -> do
{ mkTransaction = \_era _stakeCredentials keystore _pp _ctx cs -> do
let inps' = NE.toList $ second txOutCoin <$> inputsSelected cs
let tid = mkTxId inps' (outputsCovered cs) mempty Nothing
let tx = Tx tid Nothing inps' (outputsCovered cs) mempty Nothing
wit <- forM (inputsSelected cs) $ \(_, TxOut addr _) -> do
(xprv, Passphrase pwd) <- withEither
(ErrKeyNotFoundForAddress addr) $ keyFrom addr
(ErrKeyNotFoundForAddress addr) $ keystore addr
let (Hash sigData) = txId tx
let sig = CC.unXSignature $ CC.sign pwd (getKey xprv) sigData
return $ xpubToBytes (getKey $ publicKey xprv) <> sig

-- (tx1, wit1) == (tx2, wit2) <==> fakebinary1 == fakebinary2
let fakeBinary = SealedTx . B8.pack $ show (tx, wit)
return (tx, fakeBinary)
, initDelegationSelection =
error "dummyTransactionLayer: initDelegationSelection not implemented"
, mkDelegationJoinTx =
error "dummyTransactionLayer: mkDelegationJoinTx not implemented"
, mkDelegationQuitTx =
error "dummyTransactionLayer: mkDelegationQuitTx not implemented"
, minimumFee =
error "dummyTransactionLayer: minimumFee not implemented"

, initSelectionCriteria =
error "dummyTransactionLayer: initSelectionCriteria not implemented"
, calcMinimumCost =
error "dummyTransactionLayer: calcMinimumCost not implemented"
, calcMinimumCoinValue =
error "dummyTransactionLayer: calcMinimumCoinValue not implemented"
, estimateMaxNumberOfInputs =
error "dummyTransactionLayer: estimateMaxNumberOfInputs not implemented"
, decodeSignedTx =
Expand Down
14 changes: 10 additions & 4 deletions lib/shelley/bench/Restore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ import Cardano.Wallet.Primitive.AddressDiscovery.Sequential
, mkSeqAnyState
, purposeCIP1852
)
import Cardano.Wallet.Primitive.CoinSelection.MA.RoundRobin
( selectionDelta )
import Cardano.Wallet.Primitive.Model
( Wallet, currentTip, getState, totalUTxO )
import Cardano.Wallet.Primitive.Slotting
Expand Down Expand Up @@ -446,8 +448,10 @@ benchmarksRnd _ w wid wname benchname restoreTime = do

(_, estimateFeesTime) <- bench "estimate tx fee" $ do
let out = TxOut (dummyAddress @n) (TokenBundle.fromCoin $ Coin 1)
runExceptT $ withExceptT show $ W.estimateFeeForPayment @_ @s @k
w wid (out :| []) (Coin 0) Nothing
let txCtx = defaultTransactionCtx
let getFee = const (selectionDelta TokenBundle.getCoin)
let runSelection = W.selectAssets @_ @s @k w wid txCtx (out :| []) getFee
runExceptT $ withExceptT show $ W.estimateFee runSelection

oneAddress <- genAddresses 1 cp
(_, importOneAddressTime) <- bench "import one addresses" $ do
Expand Down Expand Up @@ -533,8 +537,10 @@ benchmarksSeq _ w wid _wname benchname restoreTime = do

(_, estimateFeesTime) <- bench "estimate tx fee" $ do
let out = TxOut (dummyAddress @n) (TokenBundle.fromCoin $ Coin 1)
runExceptT $ withExceptT show $ W.estimateFeeForPayment @_ @s @k
w wid (out :| []) (Coin 0) Nothing
let txCtx = defaultTransactionCtx
let getFee = const (selectionDelta TokenBundle.getCoin)
let runSelection = W.selectAssets @_ @s @k w wid txCtx (out :| []) getFee
runExceptT $ withExceptT show $ W.estimateFee runSelection

let walletOverview = WalletOverview{utxo,addresses,transactions}

Expand Down
4 changes: 1 addition & 3 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ import Cardano.Wallet.Primitive.CoinSelection.MA.RoundRobin
, prepareOutputsWith
, selectionDelta
)
import Cardano.Wallet.Primitive.Fee
( FeePolicy (..) )
import Cardano.Wallet.Primitive.Types
( ProtocolParameters (..), TxParameters (..) )
( FeePolicy (..), ProtocolParameters (..), TxParameters (..) )
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
import Cardano.Wallet.Primitive.Types.Coin
Expand Down
Loading

0 comments on commit e6319b1

Please sign in to comment.