Skip to content

Commit a73b6a6

Browse files
committed
alonzo min-utxo tests pass
1 parent af2eb95 commit a73b6a6

File tree

7 files changed

+96
-64
lines changed

7 files changed

+96
-64
lines changed

alonzo/impl/cardano-ledger-alonzo.cabal

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ library test
9393
QuickCheck,
9494
shelley-spec-ledger-test,
9595
shelley-spec-ledger,
96+
cardano-ledger-shelley-ma-test
9697
hs-source-dirs:
9798
test/lib
9899

@@ -120,4 +121,12 @@ test-suite cardano-ledger-alonzo-test
120121
shelley-spec-ledger-test,
121122
tasty-quickcheck,
122123
tasty,
123-
test
124+
text,
125+
test,
126+
shelley-spec-ledger-test,
127+
cardano-ledger-core,
128+
cardano-ledger-shelley-ma,
129+
strict-containers,
130+
containers,
131+
tasty-hunit,
132+
plutus-tx

alonzo/impl/test/test/Test/Cardano/Ledger/Alonzo/Golden.hs

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,65 @@ where
1111

1212
import Cardano.Ledger.Coin (Coin (..))
1313
import Cardano.Ledger.Alonzo (AlonzoEra)
14-
import Cardano.Ledger.Mary.Value (AssetName (..), PolicyID (..), Value (..))
15-
import Cardano.Ledger.ShelleyMA.Timelocks (Timelock (..))
16-
import qualified Data.ByteString.Char8 as BS
14+
import Cardano.Ledger.Mary.Value (Value (..))
1715
import Data.Char (chr)
1816
import qualified Data.Map.Strict as Map
19-
import qualified Data.Sequence.Strict as StrictSeq
20-
import Shelley.Spec.Ledger.Slot (SlotNo (..))
21-
import Shelley.Spec.Ledger.Tx (hashScript)
2217
import Test.Cardano.Ledger.EraBuffet (StandardCrypto)
2318
import Test.Tasty (TestTree, testGroup)
2419
import Test.Tasty.HUnit (testCase, (@?=))
25-
import Test.Cardano.Ledger.Mary.Golden
2620
import Cardano.Ledger.Alonzo.Rules.Utxo (utxoEntrySize)
21+
import Test.Shelley.Spec.Ledger.Examples.Cast (aliceAddr, bobAddr, carlAddr)
22+
import Cardano.Ledger.Alonzo.Data (hashData, Data (..))
23+
import Language.PlutusTx (Data (..))
24+
import Cardano.Ledger.Alonzo.TxBody (TxOut (..))
25+
import Test.Cardano.Ledger.Mary.Golden
26+
( pid1,
27+
pid2,
28+
pid3,
29+
smallName,
30+
smallestName,
31+
minUTxO,
32+
largestName )
33+
import Shelley.Spec.Ledger.BaseTypes (StrictMaybe (..))
2734

2835
-- | ada cost of storing a word8 of data as a UTxO entry, assuming no change to minUTxOValue
29-
adaPerUTxOWordLocal :: Coin
30-
adaPerUTxOWordLocal = Coin $ quot minUTxOValueShelleyMA utxoEntrySizeWithoutValLocal
36+
adaPerUTxOWordLocal :: Integer
37+
adaPerUTxOWordLocal = quot minUTxOValueShelleyMA utxoEntrySizeWithoutValLocal
3138
where
3239
utxoEntrySizeWithoutValLocal = 29
33-
minUTxOValueShelleyMA = 1000000
40+
Coin minUTxOValueShelleyMA = minUTxO
3441

35-
calcMinUTxO :: TxOut era -> Coin
42+
calcMinUTxO :: TxOut (AlonzoEra StandardCrypto) -> Coin
3643
calcMinUTxO tout = Coin (utxoEntrySize tout * adaPerUTxOWordLocal)
3744

45+
-- | (heapWords of a DataHash) * adaPerUTxOWordLocal is 344820
3846
goldenUTxOEntryMinAda :: TestTree
3947
goldenUTxOEntryMinAda =
4048
testGroup
4149
"golden tests - UTxOEntryMinAda"
42-
[ testCase "one policy, one (smallest) name, no datum hash" $
43-
scaledMinDeposit
44-
( Value 1407406 $
50+
[ testCase "one policy, one (smallest) name, yes datum hash" $
51+
calcMinUTxO
52+
(TxOut carlAddr ( Value 1407406 $
4553
Map.singleton pid1 (Map.fromList [(smallestName, 1)])
46-
)
47-
minUTxO
48-
@?= Coin 1407406,
49-
testCase "one policy, one (smallest) name, yes datum hash" $
50-
scaledMinDeposit
51-
( Value 1407406 $
54+
) (SJust $ hashData @(AlonzoEra StandardCrypto) (Data (List []))) )
55+
@?= Coin 1655136,
56+
testCase "one policy, one (smallest) name, no datum hash" $
57+
calcMinUTxO
58+
(TxOut bobAddr ( Value 1407406 $
5259
Map.singleton pid1 (Map.fromList [(smallestName, 1)])
53-
)
54-
minUTxO
55-
@?= Coin 1407406,
60+
) SNothing )
61+
@?= Coin 1310316,
5662
testCase "one policy, one (small) name" $
57-
scaledMinDeposit
58-
( Value 1444443 $
63+
calcMinUTxO
64+
(TxOut aliceAddr ( Value 1444443 $
5965
Map.singleton
6066
pid1
6167
(Map.fromList [(smallName '1', 1)])
62-
)
63-
minUTxO
64-
@?= Coin 1444443,
65-
testCase "one policy, three (small) name" $
66-
scaledMinDeposit
67-
( Value 1555554 $
68+
) SNothing )
69+
@?= Coin 1344798,
70+
testCase "one policy, three (small) names" $
71+
calcMinUTxO
72+
(TxOut aliceAddr ( Value 1555554 $
6873
Map.singleton
6974
pid1
7075
( Map.fromList
@@ -73,21 +78,19 @@ goldenUTxOEntryMinAda =
7378
(smallName '3', 1)
7479
]
7580
)
76-
)
77-
minUTxO
78-
@?= Coin 1555554,
81+
) SNothing )
82+
@?= Coin 1448244,
7983
testCase "one policy, one (largest) name" $
80-
scaledMinDeposit
81-
( Value 1555554 $
84+
calcMinUTxO
85+
(TxOut carlAddr ( Value 1555554 $
8286
Map.singleton
8387
pid1
8488
(Map.fromList [(largestName 'a', 1)])
85-
)
86-
minUTxO
87-
@?= Coin 1555554,
88-
testCase "one policy, three (largest) name" $
89-
scaledMinDeposit
90-
( Value 1962961 $
89+
) SNothing )
90+
@?= Coin 1448244,
91+
testCase "one policy, three (largest) name, with hash" $
92+
calcMinUTxO
93+
(TxOut carlAddr ( Value 1962961 $
9194
Map.singleton
9295
pid1
9396
( Map.fromList
@@ -96,12 +99,24 @@ goldenUTxOEntryMinAda =
9699
(largestName 'c', 1)
97100
]
98101
)
99-
)
100-
minUTxO
101-
@?= Coin 1962961,
102+
) (SJust $ hashData @(AlonzoEra StandardCrypto) (Data (Constr 0 [(Constr 0 [])]))) )
103+
@?= Coin 2172366,
102104
testCase "two policies, one (smallest) name" $
103-
scaledMinDeposit
104-
( Value 1592591 $
105+
calcMinUTxO
106+
(TxOut aliceAddr ( Value 1592591 $
107+
Map.fromList
108+
[ ( pid1,
109+
(Map.fromList [(smallestName, 1)])
110+
),
111+
( pid2,
112+
(Map.fromList [(smallestName, 1)])
113+
)
114+
]
115+
) SNothing )
116+
@?= Coin 1482726,
117+
testCase "two policies, one (smallest) name, with hash" $
118+
calcMinUTxO
119+
(TxOut aliceAddr ( Value 1592591 $
105120
Map.fromList
106121
[ ( pid1,
107122
(Map.fromList [(smallestName, 1)])
@@ -110,12 +125,11 @@ goldenUTxOEntryMinAda =
110125
(Map.fromList [(smallestName, 1)])
111126
)
112127
]
113-
)
114-
minUTxO
115-
@?= Coin 1592591,
128+
) (SJust $ hashData @(AlonzoEra StandardCrypto) (Data (Constr 0 []))) )
129+
@?= Coin 1827546,
116130
testCase "two policies, two (small) names" $
117-
scaledMinDeposit
118-
( Value 1629628 $
131+
calcMinUTxO
132+
(TxOut bobAddr ( Value 1629628 $
119133
Map.fromList
120134
[ ( pid1,
121135
(Map.fromList [(smallName '1', 1)])
@@ -124,12 +138,11 @@ goldenUTxOEntryMinAda =
124138
(Map.fromList [(smallName '2', 1)])
125139
)
126140
]
127-
)
128-
minUTxO
129-
@?= Coin 1629628,
141+
) SNothing )
142+
@?= Coin 1517208,
130143
testCase "three policies, ninety-six (small) names" $
131-
scaledMinDeposit
132-
( Value 7407400 $
144+
calcMinUTxO
145+
(TxOut aliceAddr ( Value 7407400 $
133146
Map.fromList
134147
[ ( pid1,
135148
(Map.fromList $ map ((,1) . smallName . chr) [32 .. 63])
@@ -141,7 +154,6 @@ goldenUTxOEntryMinAda =
141154
(Map.fromList $ map ((,1) . smallName . chr) [96 .. 127])
142155
)
143156
]
144-
)
145-
minUTxO
146-
@?= Coin 7407400
157+
) SNothing)
158+
@?= Coin 6896400
147159
]

alonzo/impl/test/test/Tests.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ module Main where
22

33
import qualified Test.Cardano.Ledger.Alonzo.Serialisation.CDDL as CDDL
44
import qualified Test.Cardano.Ledger.Alonzo.Serialisation.Tripping as Tripping
5+
import Test.Cardano.Ledger.Alonzo.Golden as Golden
56
import Test.Tasty
67

78
tests :: TestTree
89
tests =
910
testGroup
1011
"Alonzo tests"
1112
[ Tripping.tests,
12-
CDDL.tests 5
13+
CDDL.tests 5,
14+
Golden.goldenUTxOEntryMinAda
1315
]
1416

1517
main :: IO ()

doc/explanations/min-utxo.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Eg. ``(CryptoDoggiesPolicy, poodle, 1)`` contained in O can be consolidated with
145145
+---------------------+----------------+-----------------+------------------+------------------+------------------+
146146
| ``minUTxO`` | 1,407,406 | 1,444,443 | 1,555,554 | 23,777,754 | 21,222,201 |
147147
+---------------------+----------------+-----------------+------------------+------------------+------------------+
148-
| ``minUTxO`` (in ada)| 1.222221 | 1.444443 | 1.555554 | 23.777754 | 21.222201 |
148+
| ``minUTxO`` (in ada)| 1.407406 | 1.444443 | 1.555554 | 23.777754 | 21.222201 |
149149
+---------------------+----------------+-----------------+------------------+------------------+------------------+
150150

151151
* (i) : ``6 + FLOOR (((1 * 12) + 0 + (1 * 28) + 7) / 8) = 11``

shelley-ma/shelley-ma-test/cardano-ledger-shelley-ma-test.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ library
5050
Test.Cardano.Ledger.ShelleyMA.Serialisation.Coders
5151
Test.Cardano.Ledger.ShelleyMA.Serialisation.Generators
5252
Test.Cardano.Ledger.ShelleyMA.Serialisation.Roundtrip
53+
Test.Cardano.Ledger.Mary.Golden
5354
-- other-extensions:
5455
build-depends:
5556
array,
@@ -88,7 +89,6 @@ test-suite cardano-ledger-shelley-ma-test
8889
Test.Cardano.Ledger.Mary.Examples
8990
Test.Cardano.Ledger.Mary.Examples.Cast
9091
Test.Cardano.Ledger.Mary.Examples.MultiAssets
91-
Test.Cardano.Ledger.Mary.Golden
9292
Test.Cardano.Ledger.Mary.Translation
9393
Test.Cardano.Ledger.Mary.Value
9494
Test.Cardano.Ledger.Allegra.Translation

shelley-ma/shelley-ma-test/test/Test/Cardano/Ledger/Mary/Golden.hs renamed to shelley-ma/shelley-ma-test/src/Test/Cardano/Ledger/Mary/Golden.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
-- Description : Golden Tests for the Mary era
77
module Test.Cardano.Ledger.Mary.Golden
88
( goldenScaledMinDeposit,
9+
pid1,
10+
pid2,
11+
pid3,
12+
smallName,
13+
smallestName,
14+
realName,
15+
minUTxO,
16+
largestName
917
)
1018
where
1119

shelley/chain-and-ledger/shelley-spec-ledger-test/shelley-spec-ledger-test.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ library
4343
hs-source-dirs: src
4444
test
4545
exposed-modules:
46+
Test.Shelley.Spec.Ledger.Examples.Cast
4647
Test.Cardano.Crypto.VRF.Fake
4748
Test.Shelley.Spec.Ledger.BenchmarkFunctions
4849
Test.Shelley.Spec.Ledger.ConcreteCryptoTypes

0 commit comments

Comments
 (0)