Skip to content

Commit 822d8b7

Browse files
committed
tx-generator: Fix selftest.
'cabal run tx-generator:benchmark:tx-generator-bench' now works.
1 parent 0818647 commit 822d8b7

File tree

5 files changed

+55
-32
lines changed

5 files changed

+55
-32
lines changed

Diff for: bench/tx-generator/src/Cardano/Benchmarking/Script/Core.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ submitInEra submitMode generator era = do
245245
Benchmark nodes threadName tpsRate txCount -> benchmarkTxStream txStream nodes threadName tpsRate txCount era
246246
LocalSocket -> submitAll (void . localSubmitTx . Utils.mkTxInModeCardano) txStream
247247
DumpToFile filePath -> liftIO $ Streaming.writeFile filePath $ Streaming.map showTx txStream
248-
DiscardTX -> liftIO $ Streaming.effects txStream
248+
DiscardTX -> liftIO $ Streaming.mapM_ forceTx txStream
249249
where
250+
forceTx (Right _) = return ()
251+
forceTx (Left err) = error err
250252
showTx (Left err) = error err
251253
showTx (Right tx) = '\n' : show tx
252254
-- todo: use Streaming.run

Diff for: bench/tx-generator/src/Cardano/Benchmarking/Script/Selftest.hs

+32-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Data.Dependent.Sum ((==>))
99
import Data.String
1010

1111
import Control.Monad
12-
import Control.Monad.IO.Class (liftIO)
1312

1413
import Cardano.Api
1514
import Ouroboros.Network.NodeToClient (IOManager)
@@ -20,7 +19,7 @@ import Cardano.Benchmarking.Script.Env as Script
2019
import Cardano.Benchmarking.Script.Setters
2120
import Cardano.Benchmarking.Script.Store
2221
import Cardano.Benchmarking.Script.Types
23-
import Cardano.Benchmarking.Tracer (initDefaultTracers)
22+
import Cardano.Benchmarking.Tracer (initNullTracers)
2423

2524
import Paths_tx_generator
2625

@@ -30,7 +29,7 @@ runSelftest iom outFile = do
3029
let
3130
submitMode = maybe DiscardTX DumpToFile outFile
3231
fullScript = do
33-
liftIO initDefaultTracers >>= set BenchTracers
32+
set BenchTracers initNullTracers
3433
forM_ (testScript protocolFile submitMode) action
3534
runActionM fullScript iom >>= \case
3635
(Right a , _ , ()) -> return $ Right a
@@ -40,28 +39,44 @@ printJSON :: IO ()
4039
printJSON = BSL.putStrLn $ prettyPrint $ testScript "/dev/zero" DiscardTX
4140

4241
testScript :: FilePath -> SubmitMode -> [Action]
43-
testScript protocolFile _submitMode =
42+
testScript protocolFile submitMode =
4443
[ SetProtocolParameters (UseLocalProtocolFile protocolFile)
4544
, Set (TTTL ==> SlotNo 1000000)
4645
, Set (TNetworkId ==> Testnet (NetworkMagic {unNetworkMagic = 42}))
47-
, InitWallet wallet
46+
, InitWallet genesisWallet
47+
, InitWallet splitWallet1
48+
, InitWallet splitWallet2
49+
, InitWallet splitWallet3
50+
, InitWallet doneWallet
4851
, DefineSigningKey key
4952
(TextEnvelope { teType = TextEnvelopeType "GenesisUTxOSigningKey_ed25519"
5053
, teDescription = fromString "Genesis Initial UTxO Signing Key"
51-
, teRawCBOR = "X \vl1~\182\201v(\152\250A\202\157h0\ETX\248h\153\171\SI/m\186\242D\228\NAK\182(&\162"})
52-
, AddFund era wallet
54+
, teRawCBOR = "X \vl1~\182\201v(\152\250A\202\157h0\ETX\248h\153\171\SI/m\186\242D\228\NAK\182(&\162"})
55+
, AddFund era genesisWallet
5356
(TxIn "900fc5da77a0747da53f7675cbb7d149d46779346dea2f879ab811ccc72a2162" (TxIx 0))
5457
(Lovelace 90000000000000) key
55-
, createChange 2200000000000 10
56-
, createChange 70000000000 300
57-
, createChange 2300000000 9000
58-
-- , Submit era submitMode $ Take 4000 $ Cycle $ BechmarkTx wallet extraArgs Nothing
58+
, createChange genesisWallet splitWallet1 1 10
59+
, createChange splitWallet1 splitWallet2 10 30 -- 10 TXs with 30 outputs -> in total 300 outputs
60+
, createChange splitWallet2 splitWallet3 300 30
61+
{-
62+
, createChange genesisWallet splitWallet3 1 10
63+
-- Fifo implementation should also work fine when sourceWallet==destWallet
64+
, createChange splitWallet3 splitWallet3 10 30
65+
, createChange splitWallet3 splitWallet3 300 30
66+
-}
67+
68+
, Submit era submitMode $ Take 4000 $ Cycle
69+
$ NtoM fee splitWallet3 (PayToAddr key doneWallet) 2 2 Nothing Nothing
5970
]
60-
where
71+
where
6172
era = AnyCardanoEra AllegraEra
62-
wallet = WalletName "test-wallet"
73+
fee = 1000000
74+
genesisWallet = WalletName "genesisWallet"
75+
splitWallet1 = WalletName "SplitWallet-1"
76+
splitWallet2 = WalletName "SplitWallet-2"
77+
splitWallet3 = WalletName "SplitWallet-3"
78+
doneWallet = WalletName "doneWallet"
6379
key = KeyName "pass-partout"
64-
-- payMode = PayToAddr key wallet
65-
createChange :: Int -> Int -> Action
66-
createChange _val _count
67-
= LogMsg "TODO: Fix this " -- CreateChange era wallet submitMode payMode payMode (Lovelace val) count
80+
createChange :: WalletName -> WalletName -> Int -> Int -> Action
81+
createChange src dest txCount outputs
82+
= Submit era submitMode $ Take txCount $ Cycle $ SplitN fee src (PayToAddr key dest) outputs

Diff for: bench/tx-generator/src/Cardano/Benchmarking/Tracer.hs

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
module Cardano.Benchmarking.Tracer
2222
( initDefaultTracers
23-
) where
23+
, initNullTracers
24+
)
25+
where
2426

2527
import "contra-tracer" Control.Tracer (Tracer (..))
2628
import GHC.Generics
@@ -49,6 +51,15 @@ generatorTracer namesFor tracerName tr = do
4951
$ appendName tracerName
5052
tr''
5153

54+
initNullTracers :: BenchTracers
55+
initNullTracers = BenchTracers
56+
{ btTxSubmit_ = Tracer ignore
57+
, btConnect_ = Tracer ignore
58+
, btSubmission2_ = Tracer ignore
59+
, btN2N_ = Tracer ignore
60+
}
61+
where ignore _ = return ()
62+
5263
initDefaultTracers :: IO BenchTracers
5364
initDefaultTracers = do
5465
st <- standardTracer

Diff for: bench/tx-generator/src/Cardano/TxGenerator/Types.hs

+2-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Cardano.TxGenerator.Types
66
where
77

88
import Cardano.Api
9-
import Cardano.Prelude (Text)
109

1110
import Cardano.TxGenerator.Fund (Fund)
1211

@@ -69,17 +68,8 @@ data TxGenPlutusParams =
6968
| PlutusOff -- ^ Do not generate Plutus Txs
7069
deriving Show
7170

72-
73-
data TxGenError =
74-
InsufficientFundsForRecipientTx !Lovelace !Lovelace
75-
-- ^ The calculated expenditure (second value) was not available as a single
76-
-- UTxO entry. The first value is the largest single UTxO available.
77-
| TxFileError !(FileError TextEnvelopeError)
78-
| SplittingSubmissionError !Text
79-
| SuppliedUtxoTooSmall !Int !Int
80-
-- ^ The supplied UTxO size (second value) was less than the requested
81-
-- number of transactions to send (first value).
82-
| BadPayloadSize !Text
71+
newtype TxGenError
72+
= TxFileError !(FileError TextEnvelopeError)
8373
deriving Show
8474

8575
{-

Diff for: bench/tx-generator/test/Bench.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE LambdaCase #-}
12
{-# LANGUAGE Trustworthy #-}
23
module Main (main) where
34

@@ -8,6 +9,10 @@ import Cardano.Benchmarking.Script.Selftest
89
main :: IO ()
910
main = defaultMain [
1011
bgroup "cardano-tx-generator-integration" [
11-
bench "tx-gen" $ whnfIO $ runSelftest (error "noIOManager") Nothing
12+
bench "tx-gen" $ whnfIO $ do
13+
runSelftest (error "noIOManager") Nothing >>= \case
14+
Right _ -> return ()
15+
Left err -> error $ show err
1216
]
1317
]
18+

0 commit comments

Comments
 (0)