From fb5540aee8bba4c8df4f4ccf75f5c4be2555d8f3 Mon Sep 17 00:00:00 2001 From: nikhils9 Date: Thu, 8 Feb 2024 14:46:37 +0530 Subject: [PATCH 1/5] test: add property based test --- single-asset-staking.cabal | 11 ++--------- test/Spec.hs | 5 +++-- test/Spec/StakingSpec.hs | 33 ++++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/single-asset-staking.cabal b/single-asset-staking.cabal index aa3dae7..645b94b 100644 --- a/single-asset-staking.cabal +++ b/single-asset-staking.cabal @@ -104,6 +104,7 @@ common dependencies build-depends: , aeson , aeson-pretty + , ansi-terminal , base , base16-bytestring , bytestring @@ -112,7 +113,6 @@ common dependencies , data-default , directory , liqwid-plutarch-extra - , liqwid-script-export , plutarch , plutarch-extra , plutus-core @@ -125,22 +125,15 @@ common dependencies common test-dependencies build-depends: - , base - , bytestring , hedgehog , hedgehog-quickcheck - , liqwid-plutarch-extra - , plutarch , plutarch-context-builder - , plutarch-extra , plutarch-quickcheck , plutarch-unit - , plutus-core - , plutus-ledger-api - , plutus-tx , tasty , tasty-hedgehog , tasty-hunit + , tasty-quickcheck , text library diff --git a/test/Spec.hs b/test/Spec.hs index 2b53fd2..e869328 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,12 +1,13 @@ module Main (main) where -import Spec.StakingSpec (unitTest) +import Spec.StakingSpec (unitTest, propertyTest) import Test.Tasty (defaultMain, testGroup) main :: IO () main = do defaultMain $ testGroup - "Unit Test Group" + "Single Asset Staking Tests" [ unitTest + , propertyTest ] diff --git a/test/Spec/StakingSpec.hs b/test/Spec/StakingSpec.hs index 0919e30..33132ea 100644 --- a/test/Spec/StakingSpec.hs +++ b/test/Spec/StakingSpec.hs @@ -1,4 +1,5 @@ -module Spec.StakingSpec (unitTest) where +{-# OPTIONS_GHC -Wno-unused-imports #-} +module Spec.StakingSpec (unitTest, propertyTest) where import Plutarch.Context ( UTXO, @@ -17,7 +18,7 @@ import Plutarch.Context ( withValue, ) import Plutarch.Test.Precompiled (Expectation (Success), testEvalCase, tryFromPTerm) -import PlutusLedgerApi.V1 (POSIXTimeRange, Value) +import PlutusLedgerApi.V1 (POSIXTimeRange, Value, toBuiltin) import PlutusLedgerApi.V1.Interval qualified as Interval import PlutusLedgerApi.V2 ( Address (..), @@ -35,7 +36,7 @@ import PlutusLedgerApi.V2 ( ) import PlutusTx qualified -import Test.Tasty (TestTree) +import Test.Tasty (TestTree, testGroup) import Mint.Standard (mkStakingNodeMP) import Plutarch.Prelude @@ -44,7 +45,9 @@ import Types.StakingSet (PStakingConfig (..), StakingConfig (..), StakingNodeAct import Conversions (pconvert) import Plutarch.Api.V2 (PMintingPolicy) -import Types.StakingSet (PStakingNodeAction (..)) +import Types.StakingSet (PStakingNodeAction (..), validNode) +import Test.Tasty.QuickCheck (Gen, Property, chooseInteger, forAll, suchThat, testProperty, listOf, elements, (===), tabulate, QC (QC), QuickCheckVerbose (QuickCheckVerbose), vectorOf) +import Data.ByteString.Char8 (pack) mkStakingNodeMPW :: ClosedTerm @@ -380,7 +383,7 @@ claimScriptContext = ] unitTest :: TestTree -unitTest = tryFromPTerm "Staking Unit Test" (mkStakingNodeMPW # stakingConfig) $ do +unitTest = tryFromPTerm "Unit Tests" (mkStakingNodeMPW # stakingConfig) $ do testEvalCase "Pass - Init Staking" Success @@ -417,3 +420,23 @@ unitTest = tryFromPTerm "Staking Unit Test" (mkStakingNodeMPW # stakingConfig) $ [ PlutusTx.toData claimAction , PlutusTx.toData claimScriptContext ] + +genBuiltinByteString :: Gen BuiltinByteString +genBuiltinByteString = do + member <- vectorOf 56 $ elements (['a' .. 'f'] ++ ['0' .. '9']) + return $ toBuiltin . pack $ member + +prop_validNode :: Property +prop_validNode = forAll genBuiltinByteString $ \hash1 -> + let key = Key hash1 + in forAll genBuiltinByteString $ \hash2 -> + let next = Key hash2 + node = MkSetNode key next + in plift (validNode # pconstantData node) === (hash1 < hash2) + +propertyTest :: TestTree +propertyTest = + testGroup + "Property Based Tests" + [ testProperty "Valid Node Check" prop_validNode + ] \ No newline at end of file From 4508c684c0d36609a6c5ac6409f4e0b22ed02e4c Mon Sep 17 00:00:00 2001 From: nikhils9 Date: Thu, 8 Feb 2024 14:47:23 +0530 Subject: [PATCH 2/5] docs: update primary and test readme s --- README.md | 5 + assets/datasets/valid-node.txt | 503 +++++++++++++++++++++++++++++++++ test/README.md | 49 ++-- 3 files changed, 541 insertions(+), 16 deletions(-) create mode 100644 assets/datasets/valid-node.txt diff --git a/README.md b/README.md index 2fcd915..a62908c 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [Getting Started](#getting-started) - [Prerequisites](#prerequisites) - [Building and Developing](#building-and-developing) + - [Tests](#tests) - [License](#license) @@ -116,6 +117,10 @@ make export ![single-asset-staking](/assets/gifs/single-asset-staking.gif) +### Tests + +For comprehensive information on the test suite for Single Asset Staking implementation, including unit tests and property-based tests, please refer to our [test documentation](/test/README.md). + ## License © 2023 Anastasia Labs. diff --git a/assets/datasets/valid-node.txt b/assets/datasets/valid-node.txt new file mode 100644 index 0000000..33f5967 --- /dev/null +++ b/assets/datasets/valid-node.txt @@ -0,0 +1,503 @@ +Property Based Tests + Valid Node Check: OK (0.05s) + Passed: + "32329d0e3c0ce425e75d1e72c6af38049187ab8d5f7ab64839c0977a" + "e81186aa55cb4c2effd2174e0a6e665cb24269dfaed6f155bf753d72" + True == True + + Passed: + "653987bf4625f168b40410f1b538b99dd9ca1465c71bd3b0d89d22e7" + "44c41006dd3bbce79df7f0596eca65d9c5cfd41781085057713e556f" + False == False + + Passed: + "aeb46f95e744c41401e794c4bee54727dc7b33486b16d875b0983f6b" + "2cd9148162a37a9231a5c7758cabf30c5aa00be014974f1f850f4d0e" + False == False + + Passed: + "38358f67a1e0ec2d5ccf17989a0bed16be18be7e87c539e6a0c35d90" + "6d1921be4772900020924272adf6beadbe6ec209222c71e85cb2174a" + True == True + + Passed: + "616fb91887d49201861dd4e32aca58e3d75ce46db185154ce9bfaa8d" + "eeff0d0b6da47325ae83b4fa92cc45d23767c6b3c79f27f6168a9cd6" + True == True + + Passed: + "767bcb605e0635ff4d1ba13fd95ca8056a7265aed64d3a0695e00f96" + "c5efdbc3d32fb4361d79e00866ccf4147861ba77482444f5212c0644" + True == True + + Passed: + "820c8e96cb5d051d3bd0f72c4a77121d8990f661c5703bb5397c348c" + "784722c7aa4ea2b333535304b608c7e7d22ba61e9285480c2b074bd5" + False == False + + Passed: + "cf4ebffaf7dcb1ac7b8051a8e020e35aeabf6069992dc9d9c3053730" + "324cc2382614edca04664c6203dd2f0c3639f35229374408235983af" + False == False + + Passed: + "d3d454da85be41adbbc75698f42c0e47e5bac80822ce019c074033f9" + "c51342a0d96ed7a7be8d34ef4d1a9e61130b5ddb42604c5607917a1c" + False == False + + Passed: + "55696cc242f4851241d8c746af74a98f16c24868eee371486de96552" + "64177f8db05a35a11ab5c96821a89ffad1f970f39f67114b087e0475" + True == True + + Passed: + "32b4164b5eef78b00acca121fc864acb2fd9d8a535c23ae0a3ab0705" + "046d6c573668f0838c5aa91715ff1f911defb1bdf655ed1ac1811a27" + False == False + + Passed: + "f5a0c32445853d5371e4cd865c012689af4c0c70640a0041d1a72556" + "ae6e27af79b115fa250cb5318de45dea990c5b4e840bd8c786e9f165" + False == False + + Passed: + "4e8ee9814196aa465bf9b2e0c715e646595202320c71a96bf8e794c6" + "f64a15a688c4f40e8010f4a42c98cae4ea1a070646fad36d81e0ad15" + True == True + + Passed: + "71230ef21dc128aa4b3d7003fcc8110fa142350051759f161254608b" + "ac41f4b32cb02297b9f84f9bc5398b78ed50f80e13f12c85ffd31a87" + True == True + + Passed: + "a17fe42ca17274b93424129b88521bdea2be1ad50569ea51a57343d4" + "dff87131c5b0552653f78bc18414409396345aa47634e8de770b5f61" + True == True + + Passed: + "83dbab802894827fa1e826072c99c2c74350c466ca445fb598fc25e8" + "61fa3276c2912df9e8ecf1916ce3e0e1bb22d58ce1ce668c4bdbdd02" + False == False + + Passed: + "4be12213988cd3e094b60990971d7758416a9d454fdff8dc7f545e95" + "42bce222910b6b1ff056e6a7f4f8492dc1cfa1243d64482870846a3e" + False == False + + Passed: + "14de74b39de669679dc6e45ef838783cf838aaef549a666dbb4b4f20" + "9d38399e2308fc08def1f47af283a28757bdff4b2d54190b8ba4e803" + True == True + + Passed: + "587bd54d01533db682ee212447bc833f00ee4010c90f16069fd53af9" + "ad44260e4e40dec9d5e0a762ea1abd776c36bd67254c66407cdf1c27" + True == True + + Passed: + "e75159ea91d634268687f20684fd3c57f9d6a7be5f529d643bad350b" + "9cf824ae712bae936fa32cb2c64155418840e7eed68fb5a3d758e074" + False == False + + Passed: + "be99f7484c0703841152b3b8554b6743e837ba0a86b1be35d8d6f125" + "d2194c121dc13ee6e7c62d7f48c4b629c1fc7dca91f51511121a0025" + True == True + + Passed: + "6c96b002dfa04f7e66dd4a3f5148981787765f0dfaef26955ce7dea5" + "57ccc5751184feb03a73f449d04062958f9ce8ef421d00bfe8033a2d" + False == False + + Passed: + "f05fb289efe6443652b6e32ffc3a10c6082cb34b8876ad43d8ee922c" + "fe6d95b6a167fc344abb5f54cb8f62da6d7605f55e5141966352d604" + True == True + + Passed: + "c8469f73fdaa26c4e5af7a5a108adf62e528a1d7c71b7d4bdc7d8987" + "0c31ec6a1adc1c25ee33298f0bf7dea96047630d7035f9088fadf0e9" + False == False + + Passed: + "848de7b4127873088aac80fe42df2e2ee1a2297fed662c01f1d855e9" + "fd61dfb56435e58be2a02c0bff279ebb86429b6721daaf8a9523ddde" + True == True + + Passed: + "f3ddcfcaca94ca9542d237df225024894378686c94085bca58da6325" + "c2ab284de5fa684b57b59b8c283bd0ac87e15527c7254b60f9150003" + False == False + + Passed: + "e1aa30b13fc72055be0f9cecf05efe99732306cdf2862b2638131788" + "373b33a9a14621acf9f7fd2ce5ca3618dc7d9641567ae55690d0fb1e" + False == False + + Passed: + "9c8a4c30796d3eab8e68d3f4d9625990b72d29228a7d0f403133c3c7" + "8122cd7cfce585fbd4076a5c5d9119d51f8e2033d3c6b78529eac37b" + False == False + + Passed: + "111c9a07c3c801a5f53324e77c6991bbb62551924fe5f99f6545d6bf" + "c9d070a5c11fff92d5aef39561e10cec3c94effadb816e41c5b9345d" + True == True + + Passed: + "eba84e4aa9b70675b9364a716c869e7b0b0306e05d6d7d5e1c99e646" + "848675eb09350d3c3e065d270c7304b6afffc963c3a1a87d4c440bd2" + False == False + + Passed: + "10f79a0cdc7bfed78b682049d0124c524813f60f1c8bdb9960fdf45d" + "4f36c7ec884df1d3084e665451129603e7f966c58cbd26fbfda788f9" + True == True + + Passed: + "4923c127c7fa45cbb8a4ac092b8d0b5aef7ef899ac8ac0e770623f91" + "17c29ee834edb9c34ce79ec6069f1cacfe2b850fe756d2719c877f36" + False == False + + Passed: + "c94dcf83eb2ca3ab9c6ecd0db2b7b2b8cc2c540d302f5fcdbe4217ab" + "c0f05b2fe16dca5929687566b2a0e2231f957f996aaa146e54db89b4" + False == False + + Passed: + "afa7a8953758123c922615c6cd24a3fca463017faef43ffc1f954acf" + "32ce771430937aae5b97ce96b88ac08696f86b2dd1906b3494fec27c" + False == False + + Passed: + "823712fde052da2af86567d0bfa52bfe50f2196192b169a2a4476226" + "2ad438603dced43f10657cfa46895df73fbc9683990fb8666da56366" + False == False + + Passed: + "ea92ea5e15b6ce07a9f5fecc92f057afc40cbb5f79e1a7d70e045d48" + "cb9363dc6f19fab41a93954c784242664222fb2491e729a946599f37" + False == False + + Passed: + "86f2676f7a91beff83eb58e323b66a69b2a4f2b8b9b710c47fda5438" + "e4e975866e9904457fa6c67aa44e3a07c6c8466e46532e1ba290507b" + True == True + + Passed: + "62fddf0f3239484dbfa29599a51fc3ad1863ce5a63d993568fe6d27d" + "e48d58d358a7917e1b988d7f2d92a1a28eefd66547590ed438de72f6" + True == True + + Passed: + "23eb308e3e44008d8d7f094382ce02abd7ce7e3aa3657d147157814e" + "5d933355dda198e9100b8be196af147fe2ef0210bc23450526671959" + True == True + + Passed: + "de5fc0a2ab11a72dcdaa22987fe6fd530bdff88b68ade17c88247cd7" + "94819fcd598a52776d0561164a0a5df7b870f952b1787f1ec6c74c69" + False == False + + Passed: + "bd0f6dfa739ad5bc9729dbfecd4ddfe2c539f518f0c795b4036d8df3" + "0f1601c2935304219f32f2a671a63304790129bfd83d4c5cc1dd77b4" + False == False + + Passed: + "c7dbf6106b5ec62725dd4aed518ae51c7ccf7d449d9fadc9d6cc4b05" + "4b30e3c391faa9040f6eb03962b34f18d5ac821b100785fb1d65582b" + False == False + + Passed: + "814b17116629d76e78a8f34e43a511b20c29730b998caa4b93abb360" + "d848f995a2367e903b03596e79caacfdc70bbd289cb8679736120d06" + True == True + + Passed: + "64663be3b6d3e58ed8c313dad3d49c3e9bdd9beb4f06f30cb6b83613" + "6ac79f898e463d22c9d183c045d7002cef163ea207fa1d70b4294657" + True == True + + Passed: + "05250c81b47b335aa2761243fc65e8bfe92a5605bb62b2e018e033da" + "6b9c713ad498017e3e19274efa6202295fbefe343f8b96f4983edc67" + True == True + + Passed: + "3f2587eb7f4d24f4020e16b3b347301bcc6ec85df67f6ca86379735f" + "d1f40ded88e76471b19b336a73f140f37632a69ffbbfce080a8b25e7" + True == True + + Passed: + "ee888d5d50ded8ef7dfc907c1ee33ca26168573fe2110abbb429d583" + "a4bb8293fe969595437047b33eed20af12812825885458936c8ad340" + False == False + + Passed: + "8ccf2cf702983ce96e60ff5b103d17dae162c4780c0a5655ffbf330d" + "677aebb1a363ff53e0efd047d94d5ecb157ffeb7b9df54bf65d87f10" + False == False + + Passed: + "8253e673dece68f76c15e7c754fe8f788f095418593ea1fab99c17e1" + "baf1671e8f6b9e746a5ce226f35407365d62cd9e2858da273196cedc" + True == True + + Passed: + "cb2eae472cbe101b5ce22a58ad12221ddc1e186562d1b162bde00b6f" + "3bb39773dffe175b2e27a22db1ff9f83d5a191446b9c1b5ff0d3842c" + False == False + + Passed: + "bd5a78239e4961c8601e40badc5cf3898c8498d8494839999943aac2" + "711d4e651f12ab9f4d5a59231f454e37649335b8a67056ee1c1bd761" + False == False + + Passed: + "c9af80adaa76f2cd90483f77aabc5fba01d6eb4479441d8d3c92060e" + "73c4ebd1da10113b97fd66cb1100c092d387fb1e5e120da5e73d2aaf" + False == False + + Passed: + "717527d383ed049efb01bd6adc26560e41e229ec98d5bc71f5ac900f" + "6d7f95892098601f7b65c46675fda29c7d7eb7ea7c66f96a1bb5d28a" + False == False + + Passed: + "9f2eaba32ff4ec3b8882ae32ff66df0c5c46eaea56642af92a51c53e" + "45cc81537e52637f5d2923079555c2c832e9b8fd0491fd8146830ae9" + False == False + + Passed: + "227b6e080b09ab902f2faee5a09cba2022579cc39b50323f3954ca11" + "af9eb58d6f35190147b6a203443e12b310d356327098ecaab248c9d8" + True == True + + Passed: + "140521086b450b53aed2564252ed4d84fa4ace24708a47175f24772b" + "14689652f9067965118daa66f381668f6996e9e1e66420d929a4e3e6" + True == True + + Passed: + "90a9957508141cb651ab7ca25c37e50500fbc140171dffbe686ad041" + "25bee51014b117cc2232a6182b6f2a76196cb47f628c4ce73efba3cd" + False == False + + Passed: + "cd87ac7c2bd0a92b7cb34bf285c5225f7fd600506c38656fcee17c87" + "efa52bb5f79a1be7b0c83bcb495522650f485b04f54b8daa562df1b5" + True == True + + Passed: + "1869b3716304ff6a883619865873c5a8499b4b21abf516147e19e692" + "b0d84ff67f21dc56d8081a9e2d0a16ab3a1a8da8d4e310b9b921d105" + True == True + + Passed: + "8c476427bd46fa5f23f7d39847a55f4cb7bfc8789505373f9f06b194" + "f6a08be73924364e20a9557efa52193f5095a4534f3e38c2f1cc237c" + True == True + + Passed: + "f68cdf31860af46898b18800b8d0d0091c28a25907e8500dcbfccd35" + "d0483bc5a86fbf9ba36e5882ca1584e227f9158176c29e189ecddba3" + False == False + + Passed: + "b8e1e40ee8feb6af8e543c8daf350b12b17255faa1b27b1152f35d6c" + "6dc766c2abf99294e6a439d01423e263d470c2dbde4fb7ede41b911c" + False == False + + Passed: + "355abd6ed096ccf55fd52146cb8be28093c0b5998e5f921999cd6add" + "7e735b5bd8c082030172b9f5ce3c5f6602d2f4287a3a36f0f9f5da3f" + True == True + + Passed: + "bf7f91664d4bd4707a750cb34be72a2d59c68aea35e924c535e5c527" + "0e7f472cd35b049eda09d112e2df8728c22d54d5219467e11ed2225b" + False == False + + Passed: + "ba9a3b8f577d4c84e1bac0666f08af432b56f735835fff299c71bbea" + "546e574f608abe95d185563f3a6ad68b4552875fd2be39f04cb943d2" + False == False + + Passed: + "abfee3f65141c1d6715a89e4a13440197e345dc52d0fc4befd432aa5" + "68ba0a6f88b1e8d0946d60f5971313d195ccffbd735717bad2028d92" + False == False + + Passed: + "c4fce415a7e9355c0be8737e119b79c875b0d394cb03db576e7391bd" + "4bcaa07734815c60e7d2a3de4105286f86c56a406b92518ae17291df" + False == False + + Passed: + "6646a709a03fcf974adcac44d839d412f407085bda76b7e4e991c856" + "06c50ae980016697eba9acb6ab204b3c8cb9c1a6cd605a99a5d2632e" + False == False + + Passed: + "29b256a33648638e7d44adc27ce807eb5008042a344893cb5bd1d68f" + "2c191a2e8e77a97d247b45edaa07edf305bdc54bba8deeadbfe6db19" + True == True + + Passed: + "da4abdd9132b3b325c893118b841c8849b90eb4a45fbc1ae238b7deb" + "dd3b16f6948d4b2e4edea5193f014dc2e4e051987a4c2b03e8e84cf7" + True == True + + Passed: + "18ed68248fd4f8582e29de14dcdeeafe16b2077b0aa8c9ba77a10645" + "33da4d947bd96b1ed296fc0fc3e2e140516c11ab9909e90eed3ee6ac" + True == True + + Passed: + "a0491f731437b75a3cb5327944c36a757dee650c07e025c639ed3437" + "9e4a6757dd5152be593e1ff9b873748cc92b5b299f81075230212e3f" + False == False + + Passed: + "00272a79b41a88522759e7efbc4661f678c3387dda0fe07ee68813a3" + "7a23e260238fb974c23cca0b925901e0da19645f478894ca3aaafbb4" + True == True + + Passed: + "0014e21a7342fc5fb56422805d225d5786a56e32cce7f73ad3566b9f" + "f3d10dc4eee71ff661a5ecae531a8cd5af4193e02cc8b3188293f0ed" + True == True + + Passed: + "b800e49e71c305ce385936b3b41d1594f108221756335572d9099dd3" + "a92b69139b1115373f3aae75930e3c9c66f7a6c28f9ddc59b883ff93" + False == False + + Passed: + "0f96a7b57a9c6bf83fd92e005bd48ec69f1c9049d9de46a7e1097e79" + "6b303121ee5a497e47ed1e01ffd5f1a1982b51f70c570c6a407fed3f" + True == True + + Passed: + "dd21e2be49cb352f9bbecc9de20dc191927fb354d14abceee5f93ece" + "ae72f97a9d7295cb2ec7b53121f85e2bf541921a49c50eadbd692ea3" + False == False + + Passed: + "ae4fb451c8df3cfc1d923e441ab7bdc71c51b3421f77b538686ee3b9" + "8d09303bfb757e52bacade14e7926590ebd33c63bf24f4ceae41a64d" + False == False + + Passed: + "a9744c8c25dfd1d6e890643bc0f35941cb88f9a8b124d1bf6358dd0a" + "39aa0a853f6e709c0a2440b1efc3ad20268875bd05f396b29a2695a0" + False == False + + Passed: + "31f91ca61b8abbf9797a416ed673a0c2d2aa757debf7cdd13bff6f14" + "6c64db282158e2e3ea7cc622d389666a5dda091d2469090937db5602" + True == True + + Passed: + "3923890406eca901147f73602e3e602efa659965a5f66f5e7d957937" + "ad1edaead23b0c266e19619f8b60a16631a494f96c900bea1aff74bd" + True == True + + Passed: + "6615f6c780166fb0a59b1ae9817ef799e9fd44c259bb186fcd5c0fa2" + "06280138aeb0790dd05d1e1651b385451533eb196b78b1f939fbcce1" + False == False + + Passed: + "2f5be7665dbfceffac835917d5df1eea8f6b8d1e68fb086f8357fc91" + "fda1a58f94febaa46271950269340cd7c8a21f777c803ecc63925455" + True == True + + Passed: + "ab3d3d70ccbae8406bfa87d77022387f62b28bb0d338125f01acb2ec" + "105fb0f8a8913981cd109b9b2a80dba8ed9c6a591409526ce42128c3" + False == False + + Passed: + "f90e496ee7039eafb8e7b6a9e4baf0ac086415a101a307d6f1d5a9ba" + "3de0a66766f93e241b12e1a20d3d79e73e03f7fda68f687ed45e9b95" + False == False + + Passed: + "6c57b107429f047da4e15f90222d4cc4203c1eb019419db3fc62a8d0" + "5b79d440564d7d8a208017dd4db675f9adc8b6c1e65d49c88395fd6b" + False == False + + Passed: + "ef9e18e5db0727a4f631bb57ed5e8cc2404915f68c0cbd7947da2119" + "84f9c7406e7a64637ff5d94054377b3a93b3b9a280fad1fbfa41bb41" + False == False + + Passed: + "2b326d8a7fa8ad7f34f0ac24049ca5bde7df0fba025331658fc6f522" + "a3208d1372765c9c99d0ff7124f0521213bdd8fd43ba49b87c60671d" + True == True + + Passed: + "246a1e6eeaf84578ba9c5827ff961793a45c4a92764e95b6b294d14f" + "fa034f69994d9d0dab6ad00f2221a39d792c4cdaa59c2169ef5791b2" + True == True + + Passed: + "225f4768419bc6a2c580251aa48e6b4939e735d92fb10004760ab102" + "702a3f1ac2690e9f8005bd385875d5732f8d31e6722d18cae9f9ab9d" + True == True + + Passed: + "80de198d7b25ba9a1a6ce41850ddd780237810f152594b9201c821aa" + "38c77127f521d08d384eb6f9f4701a2b88c4e53fe5203e1c051ad612" + False == False + + Passed: + "d0bc71c7c09015a1b3510022dc81bdec21a48a5630fb50f7141fe4bb" + "cd26cb4df4d6daa7d6a2c3515c357ed136923fce93f8f6859243b4e6" + False == False + + Passed: + "cd6327d5e32f1c6710cd7ae9fcf13fb5cd43b505e270f5b23b66bc4d" + "ff09322549d737ee587eb7d79562ad1d841c4540cef48ee9b91f0fd6" + True == True + + Passed: + "cdc258163a3470279b13ec96018c3ec35725ae941e3c651fc5a21d12" + "b489e7999693f6756e409abe9df662d142191aade43be4f10e7d7106" + False == False + + Passed: + "f50fa9c093e3475d4e9870664a0d6dcf0dc4235cdfe591ce221fb4f0" + "2364ce06596cacbb03a45f571b70484551f7f2d327a8fd578b9a5725" + False == False + + Passed: + "28d9b389917e163160b9f3100452d2b03a199ddde69c58a60229a38c" + "4653f79423ffa34b05ae71fc9b0c3b02c6adc18456fe654385839d81" + True == True + + Passed: + "b0628a64b3b61ed83db91ee4b10f304259f9d9811e2f2d03aa050b26" + "3ee005124d7b5e49171196dd9c1d207cd489f5342b42c2d083eaf672" + False == False + + Passed: + "261e6abc95a0f89eff935190cc2cab66957c455c05b1200d1afbab08" + "7fbfa70ee708c29e492afda2df84c58cc2825eeb19694167089ffcac" + True == True + + Passed: + "540e4d5bfafb06c231f2e8327bc22f63b026bf7fdd7891a20f16b780" + "3dc8449e486aa1532d4031b5c73462ee0870cb82e00cf6f58f214c04" + False == False + + Passed: + "9c8fb748864dfb8d6286ab903b2f1344528e6ce021d43bc7c92b4c54" + "81a942fa05cfad851366ee8da2e55ce4fdcfb93464c1d8ab7d58237d" + False == False + + +++ OK, passed 100 tests. \ No newline at end of file diff --git a/test/README.md b/test/README.md index d330dda..7018070 100644 --- a/test/README.md +++ b/test/README.md @@ -1,56 +1,73 @@ -# Single Asset Staking Unit Tests Documentation +# Single Asset Staking Tests Documentation -This page offers a comprehensive guide to the Single Asset Staking unit tests within the project. The tests are meticulously designed to assess the accuracy and efficiency of the Single Asset Staking implementation, particularly focusing on the validation of actions involved during the staking process. +This page offers a comprehensive guide to the Single Asset Staking Tests within the project in (`./Spec/StakingSpec.hs`). The tests are meticulously designed to assess the accuracy and efficiency of the Single Asset Staking implementation, particularly focusing on the validation of actions involved during the staking process. ## Overview -The unit tests for the Single Asset Staking are organized into a suite titled "Staking Unit Test." This suite is dedicated to verifying the validation process for the various actions involved in orchestrating and participating in staking. +The unit tests and property based tests for the Single Asset Staking are organized into a suite titled "Single Asset Staking Tests" This suite is dedicated to verifying the validation process for the various actions involved in orchestrating and participating in staking. ## Test Suite Details -### Tests Included +### Unit Tests Included --**Pass - Init Staking**: This test confirms the proper initialization of Staking by creating of a head node for the linked list which will contain all the staking requests and stake amount. --**Pass - Deinit Staking**: This confirms correct working validation of deinitization of head node once the staking rewards have been processed correctly. --**Pass - Insert Staking**: Aims to validate a new user's request to participate in Staking, confirming its correct positioning and validation. --**Pass - Remove Staking**: Aims to validate an existing user's request to discontinue participation (before stake is frozen) in Staking and reclaim their stake. It also checks that the removal happens without compromising the integrity of the linked list. --**Pass - Late Remove Staking**: Aims to validate an existing user's request to discontinue participation in Staking (after stake is frozen and before staking ends) and reclaim their stake. It checks that a penalty fee is paid for withdrawing late from Staking but is still allowed. Additionally ensuring that removal happens without compromising the integrity of the linked list. --**Pass - Claim Stake & Reward**: This test confirms that a user is able to successfully claim their stake and respective reward after the end of the staking period. +- **Pass - Init Staking**: This test confirms the proper initialization of Staking by creating of a head node for the linked list which will contain all the staking requests and stake amount. +- **Pass - Deinit Staking**: This confirms correct working validation of deinitization of head node once the staking rewards have been processed correctly. +- **Pass - Insert Staking**: Aims to validate a new user's request to participate in Staking, confirming its correct positioning and validation. +- **Pass - Remove Staking**: Aims to validate an existing user's request to discontinue participation (before stake is frozen) in Staking and reclaim their stake. It also checks that the removal happens without compromising the integrity of the linked list. +- **Pass - Late Remove Staking**: Aims to validate an existing user's request to discontinue participation in Staking (after stake is frozen and before staking ends) and reclaim their stake. It checks that a penalty fee is paid for withdrawing late from Staking but is still allowed. Additionally ensuring that removal happens without compromising the integrity of the linked list. +- **Pass - Claim Stake & Reward**: This test confirms that a user is able to successfully claim their stake and respective reward after the end of the staking period. + +### Property Based Tests Included + +- **Valid Node Check**: This property based test confirms that only valid nodes are added to the linked list maintaing all the active stake. It does so by programmatically generating **100** test scenarios with different node values and checking they are indeed valid ones. Since the whole test suit is ran automatically with each commit, this means that thousands (if not millions) of test cases are tried during the whole lifetime of the project. ## Running the Tests -To execute the Staking unit tests for the project, you should follow the standard testing procedures outlined in the project documentation. Typically, this involves executing a command such as: +To execute the tests for the project, you should follow the standard testing procedures outlined in the project documentation. Typically, this involves executing a command such as: ```sh cabal new-test --test-show-details=streaming ``` +or (which prints out the dataset generated for property based tests) + +```sh +cabal new-test --test-show-details=streaming --test-option=--quickcheck-verbose +``` + This command will compile and execute all the test suites defined in the project. The output will show the status of each test case. ### Test Outcome Summary In the most recent execution: -The tests for validating Staking actions such as Init, Deinit, Insert, Remove, Late Remove & Claim all passed. Ensuring the system appropriately handles these actions as a part of conducting a flawless Staking Event. +The tests for validating Staking actions such as Init, Deinit, Insert, Remove, Late Remove & Claim all passed. It also guaranteed that nodes are valid using Valid Node Check. Ensuring the system appropriately handles these actions as a part of conducting a flawless Staking Event. ```markdown -Unit Test Group - Staking Unit Test +Running 1 test suites... +Test suite single-asset-staking-test: RUNNING... +Single Asset Staking Tests + Unit Tests Pass - Init Staking: OK (0.08s) Pass - Deinit Staking: OK Pass - Insert Staking: OK Pass - Remove Staking: OK Pass - Late Remove Staking: OK Pass - Claim Stake & Reward: OK + Property Based Tests + Valid Node Check: OK (0.05s) + +++ OK, passed 100 tests. -All 6 tests passed (0.09s) +All 7 tests passed (0.13s) ``` +Note: The datasets are generated randomly for each of the 100 tests, every time the tests are run. Dataset belonging to this test outcome summary can be found [here](../assets/datasets/valid-node.txt) + A history of test execution results can be found on Github at [Single Asset Staking Tests](https://github.com/Anastasia-Labs/single-asset-staking/actions) ### Execution Time -The entire suite was executed in roughly 0.09 seconds, showcasing the Staking validation process's speed and efficiency. +The entire suite was executed in roughly 0.13 seconds, showcasing the Staking validation process's speed and efficiency. ## Conclusion From af51afa72fee7bd92a65e5f0c9b316db4fbd9d35 Mon Sep 17 00:00:00 2001 From: nikhils9 Date: Thu, 8 Feb 2024 14:47:58 +0530 Subject: [PATCH 3/5] style: add formatting changes --- test/Spec.hs | 2 +- test/Spec/StakingSpec.hs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/Spec.hs b/test/Spec.hs index e869328..7694d57 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,6 +1,6 @@ module Main (main) where -import Spec.StakingSpec (unitTest, propertyTest) +import Spec.StakingSpec (propertyTest, unitTest) import Test.Tasty (defaultMain, testGroup) main :: IO () diff --git a/test/Spec/StakingSpec.hs b/test/Spec/StakingSpec.hs index 33132ea..59cff79 100644 --- a/test/Spec/StakingSpec.hs +++ b/test/Spec/StakingSpec.hs @@ -1,4 +1,5 @@ {-# OPTIONS_GHC -Wno-unused-imports #-} + module Spec.StakingSpec (unitTest, propertyTest) where import Plutarch.Context ( @@ -44,10 +45,10 @@ import Types.Constants (minAda, nodeAda, poriginNodeTN) import Types.StakingSet (PStakingConfig (..), StakingConfig (..), StakingNodeAction (..), StakingNodeKey (..), StakingSetNode (..)) import Conversions (pconvert) +import Data.ByteString.Char8 (pack) import Plutarch.Api.V2 (PMintingPolicy) +import Test.Tasty.QuickCheck (Gen, Property, QC (QC), QuickCheckVerbose (QuickCheckVerbose), chooseInteger, elements, forAll, listOf, suchThat, tabulate, testProperty, vectorOf, (===)) import Types.StakingSet (PStakingNodeAction (..), validNode) -import Test.Tasty.QuickCheck (Gen, Property, chooseInteger, forAll, suchThat, testProperty, listOf, elements, (===), tabulate, QC (QC), QuickCheckVerbose (QuickCheckVerbose), vectorOf) -import Data.ByteString.Char8 (pack) mkStakingNodeMPW :: ClosedTerm @@ -429,14 +430,14 @@ genBuiltinByteString = do prop_validNode :: Property prop_validNode = forAll genBuiltinByteString $ \hash1 -> let key = Key hash1 - in forAll genBuiltinByteString $ \hash2 -> - let next = Key hash2 - node = MkSetNode key next - in plift (validNode # pconstantData node) === (hash1 < hash2) + in forAll genBuiltinByteString $ \hash2 -> + let next = Key hash2 + node = MkSetNode key next + in plift (validNode # pconstantData node) === (hash1 < hash2) propertyTest :: TestTree -propertyTest = +propertyTest = testGroup "Property Based Tests" [ testProperty "Valid Node Check" prop_validNode - ] \ No newline at end of file + ] From 74f920ef732a9806687e23135becb7ea61fc4423 Mon Sep 17 00:00:00 2001 From: nikhils9 Date: Thu, 8 Feb 2024 17:25:29 +0530 Subject: [PATCH 4/5] refactor: remove ghc option --- test/Spec/StakingSpec.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/Spec/StakingSpec.hs b/test/Spec/StakingSpec.hs index 59cff79..f2bafdd 100644 --- a/test/Spec/StakingSpec.hs +++ b/test/Spec/StakingSpec.hs @@ -1,5 +1,3 @@ -{-# OPTIONS_GHC -Wno-unused-imports #-} - module Spec.StakingSpec (unitTest, propertyTest) where import Plutarch.Context ( @@ -47,7 +45,7 @@ import Types.StakingSet (PStakingConfig (..), StakingConfig (..), StakingNodeAct import Conversions (pconvert) import Data.ByteString.Char8 (pack) import Plutarch.Api.V2 (PMintingPolicy) -import Test.Tasty.QuickCheck (Gen, Property, QC (QC), QuickCheckVerbose (QuickCheckVerbose), chooseInteger, elements, forAll, listOf, suchThat, tabulate, testProperty, vectorOf, (===)) +import Test.Tasty.QuickCheck (Gen, Property, elements, forAll, testProperty, vectorOf, (===)) import Types.StakingSet (PStakingNodeAction (..), validNode) mkStakingNodeMPW :: From 7372629ce7f2197d85d4c51a4ea70555f709d417 Mon Sep 17 00:00:00 2001 From: nikhils9 Date: Thu, 8 Feb 2024 17:26:31 +0530 Subject: [PATCH 5/5] docs: rename folder datasets to test-reports --- assets/{datasets => test-reports}/valid-node.txt | 0 test/README.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename assets/{datasets => test-reports}/valid-node.txt (100%) diff --git a/assets/datasets/valid-node.txt b/assets/test-reports/valid-node.txt similarity index 100% rename from assets/datasets/valid-node.txt rename to assets/test-reports/valid-node.txt diff --git a/test/README.md b/test/README.md index 7018070..20edd2e 100644 --- a/test/README.md +++ b/test/README.md @@ -61,7 +61,7 @@ Single Asset Staking Tests All 7 tests passed (0.13s) ``` -Note: The datasets are generated randomly for each of the 100 tests, every time the tests are run. Dataset belonging to this test outcome summary can be found [here](../assets/datasets/valid-node.txt) +Note: The datasets are generated randomly for each of the 100 tests, every time the tests are run. Dataset belonging to this test outcome summary can be found [here](../assets/test-reports/valid-node.txt) A history of test execution results can be found on Github at [Single Asset Staking Tests](https://github.com/Anastasia-Labs/single-asset-staking/actions)