-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ledger types testing #6618
Ledger types testing #6618
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,11 @@ test_split = testProperty "split" . scaleTestsBy 7 $ \value -> | |
let (valueL, valueR) = split value | ||
in Numeric.negate valueL <> valueR <=> value | ||
|
||
test_roundTripFaceValue :: TestTree | ||
test_roundTripFaceValue = testProperty "unFaceValue followed by FaceValue returns the original" $ | ||
\(faceValue :: FaceValue) -> | ||
unFaceValue (FaceValue $ unFaceValue faceValue) === unFaceValue faceValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a completely useless test unfortunately, this property is guaranteed by GHC. |
||
|
||
test_Value :: TestTree | ||
test_Value = testGroup "Value" | ||
[ test_laws | ||
|
@@ -130,3 +135,8 @@ test_Value = testGroup "Value" | |
, test_shuffle | ||
, test_split | ||
] | ||
|
||
test_FaceValue :: TestTree | ||
test_FaceValue = testGroup "FaceValue" | ||
[ test_roundTripFaceValue | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Spec.V2.OutputDatum where | ||
|
||
import PlutusLedgerApi.Test.V2.OutputDatum () | ||
import Test.Tasty | ||
import Test.Tasty.QuickCheck | ||
|
||
-- Define a test case for Arbitrary instance | ||
arbitraryTest :: TestTree | ||
arbitraryTest = testProperty "Arbitrary instance exists" $ \(_) -> | ||
let _ = arbitrary :: Gen OutputDatum | ||
in True | ||
|
||
-- Define the main test suite | ||
testOutputDatum :: TestTree | ||
testOutputDatum = testGroup "OutputDatum" | ||
[arbitraryTest | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,9 @@ instance Arbitrary FaceValue where | |
, (1, FaceValue . fromIntegral <$> arbitrary @Int) | ||
] | ||
|
||
instance Show FaceValue where | ||
show (FaceValue value) = show value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just derive it, but OK. |
||
|
||
-- | A wrapper for satisfying an @Arbitrary a@ constraint without implementing an 'Arbitrary' | ||
-- instance for @a@. | ||
newtype NoArbitrary a = NoArbitrary | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module PlutusLedgerApi.Test.V2.OutputDatum where | ||
|
||
import PlutusLedgerApi.V2 | ||
import Test.QuickCheck | ||
|
||
instance Arbitrary OutputDatum where | ||
{-# INLINEABLE arbitrary #-} | ||
arbitrary = | ||
oneof | ||
[ pure NoOutputDatum | ||
, OutputDatumHash <$> arbitrary | ||
, OutputDatum <$> arbitrary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that relies on a whole lot other |
||
] | ||
{-# INLINEABLE shrink #-} | ||
-- We only shrink the OutputDatum case, since the others wouldn't shrink | ||
-- anyway. | ||
shrink = \case | ||
OutputDatum d -> OutputDatum <$> shrink d | ||
_ -> [] | ||
|
||
instance CoArbitrary OutputDatum where | ||
{-# INLINEABLE coarbitrary #-} | ||
coarbitrary = \case | ||
NoOutputDatum -> variant (0 :: Int) | ||
OutputDatumHash dh -> variant (1 :: Int) . coarbitrary dh | ||
OutputDatum d -> variant (2 :: Int) . coarbitrary d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get errors:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not here though, in
OutputDatum
.