Merge pull request #2620 from input-output-hk/lehins/unspecialize-test-hashes
Unspecialize test hash sizes
Unspecialize test hash sizes
extra-source-files:
cddl-files/alonzo.cddl
cddl-files/mock/crypto.cddl
cddl-files/real/crypto.cddl
cddl-files/mock/extras.cddl
golden/*.cbor
$hash28 /= bytes .size 8
$hash32 /= bytes .size 10
$hash28 /= bytes .size 28
$hash32 /= bytes .size 32
$vkey /= bytes .size 8
; fractional positive_interval is: #6.30([uint, uint])
; but this can produce a zero in the denominator
address = h'0001020304010203040102030401020304' /
h'1005060708010203040506070801020304' /
h'2001020304050607080102030405060708' /
h'3005060708050607080607050404050607' /
h'40010203040506070887680203' /
h'50050607080102030487680203' /
h'600102030405060708' /
h'700506070805060403'
address =
h'001000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000' /
h'102000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000' /
h'203000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000' /
h'304000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000' /
h'405000000000000000000000000000000000000000000000000000000087680203' /
h'506000000000000000000000000000000000000000000000000000000087680203' /
h'6070000000000000000000000000000000000000000000000000000000' /
h'7080000000000000000000000000000000000000000000000000000000'
reward_account =
h'E00102030405060708' /
h'F00506070806050403'
h'E090000000000000000000000000000000000000000000000000000000' /
h'F0A0000000000000000000000000000000000000000000000000000000'
bounded_bytes = bytes .size (0..64)
; the real bounded_bytes does not have this limit. it instead has a different
$hash28 /= bytes .size 28
$hash32 /= bytes .size 32
$vkey /= bytes .size 32
$vrf_vkey /= bytes .size 32
$vrf_cert /= [bytes, bytes .size 80]
$kes_vkey /= bytes .size 32
$kes_signature /= bytes .size 448
signkeyKES = bytes .size 64
$signature /= bytes .size 64
finite_set<a> = [* a ]
unit_interval = #6.30([uint, uint])
rational = #6.30([uint, uint])
import Cardano.Ledger.Alonzo.TxBody (TxOut)
import Cardano.Ledger.Alonzo.TxWitness (Redeemers, TxWitness)
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Crypto (StandardCrypto)
import qualified Cardano.Ledger.ShelleyMA.Timelocks as MA
import qualified Data.ByteString.Lazy as BSL
import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (C_Crypto)
import Test.Cardano.Ledger.Shelley.Serialisation.CDDLUtils
( cddlTest,
cddlTest',
( cddlAnnotatorTest,
cddlTest,
)
import Test.Tasty (TestTree, testGroup, withResource)
type A = AlonzoEra C_Crypto
type A = AlonzoEra StandardCrypto
tests :: Int -> TestTree
tests n = withResource combinedCDDL (const (pure ())) $ \cddl ->
testGroup "CDDL roundtrip tests" $
[ cddlTest @(Core.Value A) n "coin",
cddlTest' @(Core.TxBody A) n "transaction_body",
cddlTest' @(Core.AuxiliaryData A) n "auxiliary_data",
cddlTest' @(MA.Timelock C_Crypto) n "native_script",
cddlTest' @(Data A) n "plutus_data",
cddlAnnotatorTest @(Core.TxBody A) n "transaction_body",
cddlAnnotatorTest @(Core.AuxiliaryData A) n "auxiliary_data",
cddlAnnotatorTest @(MA.Timelock StandardCrypto) n "native_script",
cddlAnnotatorTest @(Data A) n "plutus_data",
cddlTest @(TxOut A) n "transaction_output",
cddlTest' @(TxWitness A) n "transaction_witness_set",
cddlAnnotatorTest @(TxWitness A) n "transaction_witness_set",
cddlTest @(PParamsUpdate A) n "protocol_param_update",
cddlTest' @(Redeemers A) n "[* redeemer]",
cddlTest' @(ValidatedTx A) n "transaction"
cddlAnnotatorTest @(Redeemers A) n "[* redeemer]",
cddlAnnotatorTest @(ValidatedTx A) n "transaction"
]
<*> pure cddl
combinedCDDL :: IO BSL.ByteString
combinedCDDL = do
base <- BSL.readFile "cddl-files/alonzo.cddl"
crypto <- BSL.readFile "cddl-files/mock/crypto.cddl"
crypto <- BSL.readFile "cddl-files/real/crypto.cddl"
extras <- BSL.readFile "cddl-files/mock/extras.cddl"
pure $ base <> crypto <> extras
extra-source-files:
cddl-files/shelley-ma.cddl
cddl-files/mock/crypto.cddl
cddl-files/real/crypto.cddl
cddl-files/mock/extras.cddl
source-repository head
$hash28 /= bytes .size 8
$hash32 /= bytes .size 10
$hash28 /= bytes .size 28
$hash32 /= bytes .size 32
$vkey /= bytes .size 8
; but this produces numbers outside the unit interval
; and can also produce a zero in the denominator
address = h'0001020304010203040102030401020304' /
h'1005060708010203040506070801020304' /
h'2001020304050607080102030405060708' /
h'3005060708050607080607050404050607' /
h'40010203040506070887680203' /
h'50050607080102030487680203' /
h'600102030405060708' /
h'700506070805060403'
address =
h'001000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000' /
h'102000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000' /
h'203000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000' /
h'304000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000' /
h'405000000000000000000000000000000000000000000000000000000087680203' /
h'506000000000000000000000000000000000000000000000000000000087680203' /
h'6070000000000000000000000000000000000000000000000000000000' /
h'7080000000000000000000000000000000000000000000000000000000'
reward_account =
h'E00102030405060708' /
h'F00506070806050403'
h'E090000000000000000000000000000000000000000000000000000000' /
h'F0A0000000000000000000000000000000000000000000000000000000'
$hash28 /= bytes .size 28
$hash32 /= bytes .size 32
$vkey /= bytes .size 32
$hash28 /= bytes .size 28
$hash32 /= bytes .size 32
$vkey /= bytes .size 32
$vrf_vkey /= bytes .size 32
$vrf_cert /= [bytes, bytes .size 80]
$kes_vkey /= bytes .size 32
$kes_signature /= bytes .size 448
signkeyKES = bytes .size 64
$signature /= bytes .size 64
testGroup
"TxBody"
[ fieldTests,
testCase "length" (assertEqual "length" 36 (Short.length (bytes txM)))
testCase "length" (assertEqual "length" 57 (Short.length (bytes txM)))
]
import Control.State.Transition.Trace (checkTrace, (.-), (.->))
import Data.Default.Class (def)
import GHC.Records
import GHC.Stack
import Test.Cardano.Ledger.EraBuffet (TestCrypto)
import Test.Cardano.Ledger.Shelley.Utils (applySTSTest, runShelleyBase)
import Test.Tasty.HUnit (Assertion, (@?=))
ignoreAllButUTxO = fmap (\(UTxOState utxo _ _ _ _, _) -> utxo)
testMaryNoDelegLEDGER ::
HasCallStack =>
UTxO MaryTest ->
Tx MaryTest ->
LedgerEnv MaryTest ->
----------------------------
minUtxoSimpleEx2 :: Coin
minUtxoSimpleEx2 = Coin 115
minUtxoSimpleEx2 = Coin 117
aliceCoinsSimpleEx2 :: Coin
aliceCoinsSimpleEx2 = aliceCoinSimpleEx1 <-> (feeEx <+> minUtxoSimpleEx2)
import Cardano.Ledger.Allegra (AllegraEra)
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Mary (MaryEra)
import qualified Data.ByteString.Lazy as BSL
import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (C_Crypto)
import Test.Cardano.Ledger.Shelley.Serialisation.CDDLUtils
( cddlTest,
cddlTest',
( cddlAnnotatorTest,
cddlTest,
)
import Test.Tasty (TestTree, testGroup, withResource)
type A = AllegraEra C_Crypto
type A = AllegraEra StandardCrypto
type M = MaryEra C_Crypto
type M = MaryEra StandardCrypto
cddlTests :: Int -> TestTree
cddlTests n = withResource combinedCDDL (const (pure ())) $ \cddl ->
testGroup "CDDL roundtrip tests" $
[ cddlTest @(Core.Value A) n "coin",
cddlTest @(Core.Value M) n "value",
cddlTest' @(Core.TxBody M) n "transaction_body",
cddlTest' @(Core.TxBody A) n "transaction_body_allegra",
cddlTest' @(Core.Script M) n "native_script",
cddlTest' @(Core.Script A) n "native_script",
cddlTest' @(Core.AuxiliaryData M) n "auxiliary_data",
cddlTest' @(Core.AuxiliaryData A) n "auxiliary_data"
cddlAnnotatorTest @(Core.TxBody M) n "transaction_body",
cddlAnnotatorTest @(Core.TxBody A) n "transaction_body_allegra",
cddlAnnotatorTest @(Core.Script M) n "native_script",
cddlAnnotatorTest @(Core.Script A) n "native_script",
cddlAnnotatorTest @(Core.AuxiliaryData M) n "auxiliary_data",
cddlAnnotatorTest @(Core.AuxiliaryData A) n "auxiliary_data"
]
<*> pure cddl
combinedCDDL :: IO BSL.ByteString
combinedCDDL = do
base <- BSL.readFile "cddl-files/shelley-ma.cddl"
crypto <- BSL.readFile "cddl-files/mock/crypto.cddl"
crypto <- BSL.readFile "cddl-files/real/crypto.cddl"
extras <- BSL.readFile "cddl-files/mock/extras.cddl"
pure $ base <> crypto <> extras
. TkInteger 2
. TkMapLen 2
)
<> S policyID2
<> T
( TkMapLen 1
. TkBytes assetName3
. TkInteger 19
)
<> S policyID1
<> T
( TkMapLen 2
. TkBytes assetName2
. TkInteger 17
)
<> S policyID2
<> T
( TkMapLen 1
. TkBytes assetName3
. TkInteger 19
)
),
checkEncodingCBOR
"value_with_negative"
-- ===============================================================
-- | The result of reward calculation is a pair of aggregate Maps.
data RewardAns c
= RewardAns
!(Map (Credential 'Staking c) (Reward c))
newtype RewardAns c
= RewardAns (Map (Credential 'Staking c) (Reward c))
deriving (Show, Eq, Generic)
deriving (NFData)
import Data.Coders (Decode (..), Encode (..), decode, encode, (!>), (<!))
import qualified Data.Compact.VMap as VMap
import Data.Default.Class (Default, def)
import Data.Foldable (find, fold)
import Data.Foldable (find, fold, foldMap')
import Data.Function (on)
import Data.List (sortBy)
import Data.Map.Strict (Map)
Map (Credential 'Staking crypto) (Set (Reward crypto)) ->
Map (Credential 'Staking crypto) Coin
aggregateRewards pp rewards =
Map.map (Set.foldr addRewardToCoin mempty) $
filterRewards pp rewards
where
addRewardToCoin r = (<>) (rewardAmount r)
Map.map (foldMap' rewardAmount) $ filterRewards pp rewards
data LeaderOnlyReward crypto = LeaderOnlyReward
{ lRewardPool :: KeyHash 'StakePool crypto,
lRewardAmount :: Coin
{ lRewardPool :: !(KeyHash 'StakePool crypto),
lRewardAmount :: !Coin
}
deriving (Eq, Ord, Show, Generic)
compact-map,
data-default-class,
deepseq,
directory,
generic-random,
hashable,
hedgehog-quickcheck,
time,
transformers,
tree-diff,
unliftio,
vector,
test-suite cardano-ledger-shelley-test
cardano-binary,
cardano-data,
cardano-crypto-class,
cardano-crypto-praos,
cardano-ledger-byron,
cardano-ledger-core,
cardano-ledger-pretty,
$hash28 /= bytes .size 8
$hash32 /= bytes .size 10
$hash28 /= bytes .size 28
$hash32 /= bytes .size 32
$vkey /= bytes .size 8
Other small changes include: * Added a trace event `TDBInitialisingFromLMDBDone`. * Initialisation from an existing LMDB database does not rely on the default `LMDBLimits` anymore, and is passed a limits argument instead. TODO: We should decide whether we want to hardcode these limits to a a substantially large one, or possibly we could link these limits to a versioning number?
add cwbtc
attempt implementation
Other small changes include: * Added a trace event `TDBInitialisingFromLMDBDone`. * Initialisation from an existing LMDB database does not rely on the default `LMDBLimits` anymore, and is passed a limits argument instead. TODO: We should decide whether we want to hardcode these limits to a a substantially large one, or possibly we could link these limits to a versioning number?
Updated crypto exchange rates chapter. I tried my best to address @rdlrt concerns. I would like to add that English is just my 3rd language, so I hope it is not too bad.
Previously, the sequence number of the database is written to disk as part of the on-disk database settings on every flush/write. Conceptually however, the settings of a database should not change on every flush or write. Instead, we make a dinstinction between on-disk database "settings" and "state", where the state can be updated in every write/flush, but the settings should generally be left untouched after database initialisation or node start-up.
Fixes #217.
This works because (a) JavaScript is ultimately single-threaded, (b) there's no execution preemption happening between a 'send' and a 'wait'.
This was using the raw Show instance of queries, which looks real bad for constructors with arity > 1 like HasTx.