Skip to content

Commit

Permalink
[ADP-3479] Update fake data for UI testing (#4841)
Browse files Browse the repository at this point in the history
- Fix a bug in the discretization lib
- Remove fake deposits data for the UI
- Add 1 mock transaction with 1M ada on the first customer in the
deposit state at boot time to test `payments` page

ADP-3479
  • Loading branch information
paolino authored Nov 14, 2024
2 parents 3f9b5b6 + c454a87 commit b49617f
Show file tree
Hide file tree
Showing 26 changed files with 263 additions and 487 deletions.
3 changes: 0 additions & 3 deletions lib/customer-deposit-wallet/customer-deposit-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ library
, MonadRandom
, monoidal-containers
, mtl
, mwc-random
, OddWord
, operational
, random
, text
, time
, transformers
Expand All @@ -99,7 +97,6 @@ library
Cardano.Wallet.Deposit.Pure
Cardano.Wallet.Deposit.Pure.API.Address
Cardano.Wallet.Deposit.Pure.API.TxHistory
Cardano.Wallet.Deposit.Pure.API.TxHistory.Mock
Cardano.Wallet.Deposit.Pure.Balance
Cardano.Wallet.Deposit.Pure.State.Creation
Cardano.Wallet.Deposit.Pure.State.Payment.Inspect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module Cardano.Wallet.Deposit.REST
, walletPublicIdentity
, deleteWallet
, deleteTheDepositWalletOnDisk
-- * Internals
, onWalletInstance

) where

import Prelude
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{-# LANGUAGE NumericUnderscores #-}

module Cardano.Wallet.Deposit.REST.Start
( loadDepositWalletFromDisk
, fakeBootEnv
, newFakeBootEnv
, mockFundTheWallet
)
where

Expand All @@ -9,18 +12,46 @@ import Prelude
import Cardano.Wallet.Deposit.IO
( WalletBootEnv (..)
)
import Cardano.Wallet.Deposit.IO.Network.Mock
( newNetworkEnvMock
)
import Cardano.Wallet.Deposit.IO.Network.Type
( NetworkEnv
, mapBlock
, postTx
)
import Cardano.Wallet.Deposit.REST
( WalletResource
( ErrWalletResource
, WalletResource
, availableBalance
, customerAddress
, getTxHistoryByCustomer
, getTxHistoryByTime
, listCustomers
, loadWallet
, runWalletResourceM
, walletExists
)
import Cardano.Wallet.Deposit.Write
( addTxOut
, emptyTxBody
, mkAda
, mkTx
, mkTxOut
)
import Control.Concurrent
( threadDelay
)
import Control.Monad
( when
)
import Control.Monad.IO.Class
( MonadIO (..)
)
import Control.Monad.Trans.Except
( ExceptT (..)
, runExceptT
)
import Control.Tracer
( Tracer
, stdoutTracer
Expand All @@ -42,20 +73,49 @@ loadDepositWalletFromDisk
-> WalletResource
-> IO ()
loadDepositWalletFromDisk tr dir env resource = do
result <- flip runWalletResourceM resource $ do
test <- walletExists dir
when test $ do
lg tr "Loading wallet from" dir
loadWallet env dir
lg tr "Wallet loaded from" dir
result <- runExceptT $ do
exists <- ExceptT $ flip runWalletResourceM resource $ do
test <- walletExists dir
liftIO $ print test
when test $ do
lg tr "Loading wallet from" dir
loadWallet env dir
lg tr "Wallet loaded from" dir
pure test
liftIO $ threadDelay 1_000_000
when exists $ do
ExceptT $ mockFundTheWallet (networkEnv env) resource
ExceptT $ flip runWalletResourceM resource $ do
liftIO $ putStrLn "Available balance"
availableBalance >>= liftIO . print
liftIO $ putStrLn "Tx history by customer"
getTxHistoryByCustomer >>= liftIO . print
liftIO $ putStrLn "Tx history by time"
getTxHistoryByTime >>= liftIO . print
liftIO $ putStrLn "List customers"
listCustomers >>= liftIO . print
liftIO $ putStrLn "UTxO"
case result of
Left e -> error $ show e
Right _ -> pure ()

fakeBootEnv :: MonadIO m => WalletBootEnv m
fakeBootEnv =
( WalletBootEnv
mockFundTheWallet
:: NetworkEnv IO z
-> WalletResource
-> IO (Either ErrWalletResource ())
mockFundTheWallet network resource = flip runWalletResourceM resource $ do
Just address <- customerAddress 0
let tx =
mkTx
$ fst
$ addTxOut (mkTxOut address (mkAda 1_000_000)) emptyTxBody
Right () <- liftIO $ postTx network tx
pure ()

newFakeBootEnv :: IO (WalletBootEnv IO)
newFakeBootEnv =
WalletBootEnv
(show >$< stdoutTracer)
Read.mockGenesisDataMainnet
(error "network env not defined")
)
. mapBlock Read.EraValue
<$> newNetworkEnvMock
3 changes: 3 additions & 0 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module Cardano.Wallet.Deposit.IO
-- *** Submit transactions
, submitTx
, listTxsInSubmission

-- * Internals
, onWalletState
) where

import Prelude
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module Cardano.Wallet.Deposit.Write
, mkTxOut
, toConwayTx
, addTxIn
, emptyTxBody
, addTxOut
, emptyTxBody
) where

import Prelude
Expand Down
Loading

0 comments on commit b49617f

Please sign in to comment.