1
1
{-# LANGUAGE CPP #-}
2
2
{-# LANGUAGE NumericUnderscores #-}
3
+ {-# LANGUAGE OverloadedStrings #-}
3
4
{-# LANGUAGE TypeApplications #-}
4
5
5
6
#if __GLASGOW_HASKELL__ >= 908
@@ -33,14 +34,17 @@ module Test.Cardano.Db.Mock.Unit.Conway.Plutus (
33
34
mintMultiAssets ,
34
35
swapMultiAssets ,
35
36
swapMultiAssetsDisabled ,
37
+ multiAssetsTxOut ,
36
38
) where
37
39
38
40
import Cardano.Crypto.Hash.Class (hashToBytes )
39
41
import qualified Cardano.Db as DB
40
42
import qualified Cardano.Db.Schema.Core.TxOut as C
41
43
import qualified Cardano.Db.Schema.Variant.TxOut as V
42
- import Cardano.DbSync.Era.Shelley.Generic.Util (renderAddress )
44
+ import Cardano.DbSync.Era.Shelley.Generic (TxOutMultiAsset (.. ))
45
+ import Cardano.DbSync.Era.Shelley.Generic.Util (renderAddress , unTxHash )
43
46
import Cardano.Ledger.Coin (Coin (.. ))
47
+ import Cardano.Ledger.Core (txIdTx )
44
48
import Cardano.Ledger.Mary.Value (MaryValue (.. ), MultiAsset (.. ), PolicyID (.. ))
45
49
import Cardano.Ledger.Plutus.Data
46
50
import Cardano.Ledger.SafeHash (extractHash )
@@ -49,8 +53,10 @@ import Cardano.Mock.Forging.Interpreter (withConwayLedgerState)
49
53
import qualified Cardano.Mock.Forging.Tx.Alonzo.ScriptsExamples as Examples
50
54
import qualified Cardano.Mock.Forging.Tx.Conway as Conway
51
55
import Cardano.Mock.Forging.Types
52
- import Cardano.Mock.Query (queryMultiAssetCount )
56
+ import Cardano.Mock.Query (queryMultiAssetCount , queryTxOutMultiAssets )
53
57
import Cardano.Prelude hiding (head )
58
+ import qualified Data.Aeson as Aeson
59
+ import Data.ByteString.Lazy (fromStrict )
54
60
import qualified Data.Map as Map
55
61
import Data.Maybe.Strict (StrictMaybe (.. ))
56
62
import GHC.Base (error )
@@ -70,7 +76,7 @@ import Test.Cardano.Db.Mock.Config (
70
76
)
71
77
import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
72
78
import Test.Cardano.Db.Mock.Validate
73
- import Test.Tasty.HUnit (Assertion () )
79
+ import Test.Tasty.HUnit (Assertion )
74
80
import Prelude (head , tail , (!!) )
75
81
76
82
------------------------------------------------------------------------------
@@ -834,3 +840,59 @@ swapMultiAssetsDisabled =
834
840
835
841
testLabel = " conwayConfigMultiAssetsDisabled"
836
842
cfgDir = conwayConfigDir
843
+
844
+ multiAssetsTxOut :: IOManager -> [(Text , Text )] -> Assertion
845
+ multiAssetsTxOut =
846
+ withFullConfig conwayConfigDir testLabel $ \ interpreter server dbSync -> do
847
+ let txOutVariant = txOutTableTypeFromConfig dbSync
848
+
849
+ startDBSync dbSync
850
+
851
+ -- Forge a multi-asset transaction
852
+ let assetName = head Examples. assetNames
853
+ policy = PolicyID Examples. alwaysMintScriptHash
854
+ assets = Map. singleton (head Examples. assetNames) 5
855
+ outValue = MaryValue (Coin 20 ) (MultiAsset $ Map. singleton policy assets)
856
+ mintValue = MultiAsset $ Map. singleton policy assets
857
+
858
+ tx <- withConwayLedgerState interpreter $ \ state' ->
859
+ Conway. mkMultiAssetsScriptTx
860
+ [UTxOIndex 0 ]
861
+ (UTxOIndex 1 )
862
+ [(UTxOAddress Examples. alwaysMintScriptAddr, outValue)]
863
+ []
864
+ mintValue
865
+ True
866
+ 100
867
+ state'
868
+
869
+ -- Submit it
870
+ void $
871
+ Api. withConwayFindLeaderAndSubmitTx interpreter server $
872
+ const (Right tx)
873
+
874
+ let txHash = unTxHash (txIdTx tx)
875
+ txIndex = 0
876
+ expectedMultiAssets =
877
+ Just
878
+ [ TxOutMultiAsset
879
+ { txOutMaPolicyId = policy
880
+ , txOutMaAssetName = assetName
881
+ , txOutMaAmount = 5
882
+ }
883
+ ]
884
+
885
+ -- Wait for it to sync
886
+ assertBlockNoBackoff dbSync 1
887
+
888
+ -- Should now have tx_out.ma_tx_out
889
+ assertEqBackoff dbSync queryMultiAssetCount 1 [] " Expected multi-assets"
890
+ assertBackoff
891
+ dbSync
892
+ (queryTxOutMultiAssets txOutVariant txHash txIndex)
893
+ []
894
+ ((== expectedMultiAssets) . parseMultiAsset)
895
+ (const " Unexpected multi-assets" )
896
+ where
897
+ testLabel = " conwayMultiAssetsTxOut"
898
+ parseMultiAsset = join . fmap (Aeson. decode . fromStrict . encodeUtf8)
0 commit comments