Skip to content

Commit

Permalink
cleaning plus adding more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Sep 14, 2021
1 parent fa83ed7 commit 430d16c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ data TransactionCtx = TransactionCtx
, txDelegationAction :: Maybe DelegationAction
-- ^ An additional delegation to take.
, txPlutusScriptExecutionCost :: Coin
-- ^ An execution cost of plutus script determined by execution units
-- and prices obtained from network
-- ^ Total execution cost of plutus scripts, determined by their execution units
-- and prices obtained from network.
} deriving (Show, Generic, Eq)

data Withdrawal
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 @@ -172,8 +172,6 @@ import GHC.Generics
( Generic )
import GHC.Stack
( HasCallStack )
import Numeric.Natural
( Natural )
import Ouroboros.Network.Block
( SlotNo )

Expand Down Expand Up @@ -508,7 +506,7 @@ _calcScriptExecutionCost pp sealedTx = case (prices, mexecutionUnits sealedTx) o
. ceiling
. sum
$ map (costOfExecutionUnits exPrices) units
(Nothing, Just units) ->
(Nothing, Just _units) ->
-- This case probably means that the node tip is not yet in Alonzo.
--
-- TODO: Not sure what the calling code would look like. Should we
Expand Down
40 changes: 31 additions & 9 deletions lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ spec = do
[(1,73),(5,69),(10,65),(20,56),(50,27)]

describe "calculate fee execution costs" $ do
let ppWithoutPrices :: ProtocolParameters
ppWithoutPrices = dummyProtocolParameters
{ executionUnitPrices = Nothing
}

let ppWithPrices :: ProtocolParameters
ppWithPrices = dummyProtocolParameters
{ executionUnitPrices = Just (ExecutionUnitPrices 1 1)
Expand All @@ -242,13 +237,13 @@ spec = do
let (Right bs) = fromHex $ T.encodeUtf8 txt
in SealedTx bs

describe "without prices" $ do
forM_ matrixPlutusExamples $ \(title, cborHex, _) ->
describe "with prices txs without plutus scripts" $ do
forM_ matrixNormalTxExamples $ \(title, cborHex, _) ->
it title $
_calcScriptExecutionCost ppWithoutPrices (unsafeFromCBORhex cborHex)
_calcScriptExecutionCost ppWithPrices (unsafeFromCBORhex cborHex)
`shouldBe` Coin 0

describe "with prices" $ do
describe "with prices txs with plutus scripts" $ do
forM_ matrixPlutusExamples $ \(title, cborHex, executionUnits) -> do
let calcPrice (ExecutionUnits {executionSteps, executionMemory}) =
Coin $ executionMemory + executionSteps
Expand Down Expand Up @@ -1383,3 +1378,30 @@ matrixPlutusExamples =
, [ExecutionUnits { executionMemory = 10250, executionSteps = 40975000 }]
)
]

matrixNormalTxExamples :: [(String, Text, [ExecutionUnits])]
matrixNormalTxExamples =
[ ( "multiple outputs tx"
, "84a600818258200eaa33be8780935ca5a7c1e628a2d54402446f96236c\
\a8f1770e07fa22ba8648000d80018482583901a65f0e7aea387adbc109\
\123a571cfd8d0d139739d359caaf966aa5b9a062de6ec013404d4f9909\
\877d452fc57dfe4f8b67f94e0ea1e8a0ba1a000f422a82583901ac9a56\
\280ec283eb7e12146726bfe68dcd69c7a85123ce2f7a10e7afa062de6e\
\c013404d4f9909877d452fc57dfe4f8b67f94e0ea1e8a0ba1a000f422a\
\825839011a2f2f103b895dbe7388acc9cc10f90dc4ada53f46c841d2ac\
\44630789fc61d21ddfcbd4d43652bf05c40c346fa794871423b65052d7\
\614c1b0000000ba42b176a82583901c59701fee28ad31559870ecd6ea9\
\2b143b1ce1b68ccb62f8e8437b3089fc61d21ddfcbd4d43652bf05c40c\
\346fa794871423b65052d7614c1b0000000ba42b176a021a000234d803\
\198ceb0e80a0f5f6"
, [])
, ( "single output tx"
, "84a600818258200eaa33be8780935ca5a7c1e628a2d54402446f96236ca8f1\
\770e07fa22ba86480d0d800182825839010acce4f85ade867308f048fe4516\
\c0383b38cc04602ea6f7a6a1e75f29450899547b0e4bb194132452d45fea30\
\212aebeafc69bca8744ea61a002dc67e8258390110a9b4666ba80e4878491d\
\1ac20465c9893a8df5581dc705770626203d4d23fe6a7acdda5a1b41f56100\
\f02bfa270a3c560c4e55cf8312331b00000017484721ca021a0001ffb80319\
\8d280e80a0f5f6"
, [])
]

0 comments on commit 430d16c

Please sign in to comment.