diff --git a/cabal.project b/cabal.project index 1bce8a10a2..b2e77af45e 100644 --- a/cabal.project +++ b/cabal.project @@ -8,6 +8,7 @@ packages: doc plutus-chain-index-core plutus-contract plutus-example + plutus-contract-certification plutus-ledger plutus-ledger-constraints plutus-pab diff --git a/flake.nix b/flake.nix index 1b035bbc1c..21f9d29e5e 100644 --- a/flake.nix +++ b/flake.nix @@ -89,5 +89,6 @@ in { packages = topLevel.bitte-packages; + legacyPackages = topLevel; })); } diff --git a/nix/pkgs/haskell/haskell.nix b/nix/pkgs/haskell/haskell.nix index f05e66e521..34b0899a69 100644 --- a/nix/pkgs/haskell/haskell.nix +++ b/nix/pkgs/haskell/haskell.nix @@ -61,6 +61,7 @@ let plutus-chain-index.package.buildable = false; plutus-chain-index-core.package.buildable = false; plutus-contract.package.buildable = false; + plutus-contract-certification.package.buildable = false; plutus-errors.package.buildable = false; plutus-ledger.package.buildable = false; plutus-ledger-constraints.package.buildable = false; diff --git a/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-contract-certification.nix b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-contract-certification.nix new file mode 100644 index 0000000000..b25b54f46f --- /dev/null +++ b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-contract-certification.nix @@ -0,0 +1,60 @@ +{ system + , compiler + , flags + , pkgs + , hsPkgs + , pkgconfPkgs + , errorHandler + , config + , ... }: + { + flags = {}; + package = { + specVersion = "3.0"; + identifier = { + name = "plutus-contract-certification"; + version = "0.1.0.0"; + }; + license = "Apache-2.0"; + copyright = ""; + maintainer = ""; + author = ""; + homepage = "https://github.com/iohk/plutus-apps#readme"; + url = ""; + synopsis = ""; + description = "Please see the README on GitHub at "; + buildType = "Simple"; + isLocal = true; + detailLevel = "FullDetails"; + licenseFiles = [ "LICENSE" "NOTICE" ]; + dataDir = "."; + dataFiles = []; + extraSrcFiles = []; + extraTmpFiles = []; + extraDocFiles = []; + }; + components = { + "library" = { + depends = [ + (hsPkgs."base" or (errorHandler.buildDepError "base")) + (hsPkgs."containers" or (errorHandler.buildDepError "containers")) + (hsPkgs."lens" or (errorHandler.buildDepError "lens")) + (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-tx" or (errorHandler.buildDepError "plutus-tx")) + (hsPkgs."QuickCheck" or (errorHandler.buildDepError "QuickCheck")) + (hsPkgs."stm" or (errorHandler.buildDepError "stm")) + (hsPkgs."tasty" or (errorHandler.buildDepError "tasty")) + (hsPkgs."aeson" or (errorHandler.buildDepError "aeson")) + (hsPkgs."splitmix" or (errorHandler.buildDepError "splitmix")) + (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring")) + (hsPkgs."mtl" or (errorHandler.buildDepError "mtl")) + ]; + buildable = true; + modules = [ + "Plutus/Contract/Test/Certification" + "Plutus/Contract/Test/Certification/Run" + ]; + hsSourceDirs = [ "src" ]; + }; + }; + } // rec { src = (pkgs.lib).mkDefault ../plutus-contract-certification; } \ No newline at end of file diff --git a/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-use-cases.nix b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-use-cases.nix index 1d41d27fff..b5cd38a6bc 100644 --- a/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-use-cases.nix +++ b/nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-use-cases.nix @@ -119,6 +119,7 @@ (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) (hsPkgs."plutus-use-cases" or (errorHandler.buildDepError "plutus-use-cases")) + (hsPkgs."plutus-contract-certification" or (errorHandler.buildDepError "plutus-contract-certification")) (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative")) (hsPkgs."cardano-api" or (errorHandler.buildDepError "cardano-api")) ] ++ (pkgs.lib).optional (!(compiler.isGhcjs && true || system.isGhcjs)) (hsPkgs."plutus-tx-plugin" or (errorHandler.buildDepError "plutus-tx-plugin")); @@ -156,6 +157,7 @@ depends = [ (hsPkgs."plutus-tx" or (errorHandler.buildDepError "plutus-tx")) (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-contract-certification" or (errorHandler.buildDepError "plutus-contract-certification")) (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) (hsPkgs."plutus-use-cases" or (errorHandler.buildDepError "plutus-use-cases")) diff --git a/nix/pkgs/haskell/materialized-darwin/default.nix b/nix/pkgs/haskell/materialized-darwin/default.nix index 9d738c694a..cc6085cce3 100644 --- a/nix/pkgs/haskell/materialized-darwin/default.nix +++ b/nix/pkgs/haskell/materialized-darwin/default.nix @@ -862,6 +862,7 @@ small-steps = ./.plan.nix/small-steps.nix; cardano-crypto-wrapper = ./.plan.nix/cardano-crypto-wrapper.nix; network-mux = ./.plan.nix/network-mux.nix; + plutus-contract-certification = ./.plan.nix/plutus-contract-certification.nix; plutus-ghc-stub = ./.plan.nix/plutus-ghc-stub.nix; compact-map = ./.plan.nix/compact-map.nix; ouroboros-network-framework = ./.plan.nix/ouroboros-network-framework.nix; @@ -1077,6 +1078,7 @@ "asserts" = lib.mkOverride 900 false; }; }; + "plutus-contract-certification" = { flags = {}; }; "plutus-ghc-stub" = { flags = {}; }; "compact-map" = { flags = {}; }; "ouroboros-network-framework" = { flags = {}; }; @@ -1448,6 +1450,7 @@ "quickcheck-classes".components.library.planned = lib.mkOverride 900 true; "srcloc".components.library.planned = lib.mkOverride 900 true; "atomic-primops".components.library.planned = lib.mkOverride 900 true; + "plutus-contract-certification".components.library.planned = lib.mkOverride 900 true; "command".components.library.planned = lib.mkOverride 900 true; "array".components.library.planned = lib.mkOverride 900 true; "th-compat".components.library.planned = lib.mkOverride 900 true; diff --git a/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-contract-certification.nix b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-contract-certification.nix new file mode 100644 index 0000000000..b25b54f46f --- /dev/null +++ b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-contract-certification.nix @@ -0,0 +1,60 @@ +{ system + , compiler + , flags + , pkgs + , hsPkgs + , pkgconfPkgs + , errorHandler + , config + , ... }: + { + flags = {}; + package = { + specVersion = "3.0"; + identifier = { + name = "plutus-contract-certification"; + version = "0.1.0.0"; + }; + license = "Apache-2.0"; + copyright = ""; + maintainer = ""; + author = ""; + homepage = "https://github.com/iohk/plutus-apps#readme"; + url = ""; + synopsis = ""; + description = "Please see the README on GitHub at "; + buildType = "Simple"; + isLocal = true; + detailLevel = "FullDetails"; + licenseFiles = [ "LICENSE" "NOTICE" ]; + dataDir = "."; + dataFiles = []; + extraSrcFiles = []; + extraTmpFiles = []; + extraDocFiles = []; + }; + components = { + "library" = { + depends = [ + (hsPkgs."base" or (errorHandler.buildDepError "base")) + (hsPkgs."containers" or (errorHandler.buildDepError "containers")) + (hsPkgs."lens" or (errorHandler.buildDepError "lens")) + (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-tx" or (errorHandler.buildDepError "plutus-tx")) + (hsPkgs."QuickCheck" or (errorHandler.buildDepError "QuickCheck")) + (hsPkgs."stm" or (errorHandler.buildDepError "stm")) + (hsPkgs."tasty" or (errorHandler.buildDepError "tasty")) + (hsPkgs."aeson" or (errorHandler.buildDepError "aeson")) + (hsPkgs."splitmix" or (errorHandler.buildDepError "splitmix")) + (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring")) + (hsPkgs."mtl" or (errorHandler.buildDepError "mtl")) + ]; + buildable = true; + modules = [ + "Plutus/Contract/Test/Certification" + "Plutus/Contract/Test/Certification/Run" + ]; + hsSourceDirs = [ "src" ]; + }; + }; + } // rec { src = (pkgs.lib).mkDefault ../plutus-contract-certification; } \ No newline at end of file diff --git a/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-use-cases.nix b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-use-cases.nix index 1d41d27fff..b5cd38a6bc 100644 --- a/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-use-cases.nix +++ b/nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-use-cases.nix @@ -119,6 +119,7 @@ (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) (hsPkgs."plutus-use-cases" or (errorHandler.buildDepError "plutus-use-cases")) + (hsPkgs."plutus-contract-certification" or (errorHandler.buildDepError "plutus-contract-certification")) (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative")) (hsPkgs."cardano-api" or (errorHandler.buildDepError "cardano-api")) ] ++ (pkgs.lib).optional (!(compiler.isGhcjs && true || system.isGhcjs)) (hsPkgs."plutus-tx-plugin" or (errorHandler.buildDepError "plutus-tx-plugin")); @@ -156,6 +157,7 @@ depends = [ (hsPkgs."plutus-tx" or (errorHandler.buildDepError "plutus-tx")) (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-contract-certification" or (errorHandler.buildDepError "plutus-contract-certification")) (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) (hsPkgs."plutus-use-cases" or (errorHandler.buildDepError "plutus-use-cases")) diff --git a/nix/pkgs/haskell/materialized-linux/default.nix b/nix/pkgs/haskell/materialized-linux/default.nix index e612537edb..e18b1f0b9f 100644 --- a/nix/pkgs/haskell/materialized-linux/default.nix +++ b/nix/pkgs/haskell/materialized-linux/default.nix @@ -862,6 +862,7 @@ small-steps = ./.plan.nix/small-steps.nix; cardano-crypto-wrapper = ./.plan.nix/cardano-crypto-wrapper.nix; network-mux = ./.plan.nix/network-mux.nix; + plutus-contract-certification = ./.plan.nix/plutus-contract-certification.nix; plutus-ghc-stub = ./.plan.nix/plutus-ghc-stub.nix; compact-map = ./.plan.nix/compact-map.nix; ouroboros-network-framework = ./.plan.nix/ouroboros-network-framework.nix; @@ -1077,6 +1078,7 @@ "asserts" = lib.mkOverride 900 false; }; }; + "plutus-contract-certification" = { flags = {}; }; "plutus-ghc-stub" = { flags = {}; }; "compact-map" = { flags = {}; }; "ouroboros-network-framework" = { flags = {}; }; @@ -1448,6 +1450,7 @@ "quickcheck-classes".components.library.planned = lib.mkOverride 900 true; "srcloc".components.library.planned = lib.mkOverride 900 true; "atomic-primops".components.library.planned = lib.mkOverride 900 true; + "plutus-contract-certification".components.library.planned = lib.mkOverride 900 true; "command".components.library.planned = lib.mkOverride 900 true; "array".components.library.planned = lib.mkOverride 900 true; "th-compat".components.library.planned = lib.mkOverride 900 true; diff --git a/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-contract-certification.nix b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-contract-certification.nix new file mode 100644 index 0000000000..b25b54f46f --- /dev/null +++ b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-contract-certification.nix @@ -0,0 +1,60 @@ +{ system + , compiler + , flags + , pkgs + , hsPkgs + , pkgconfPkgs + , errorHandler + , config + , ... }: + { + flags = {}; + package = { + specVersion = "3.0"; + identifier = { + name = "plutus-contract-certification"; + version = "0.1.0.0"; + }; + license = "Apache-2.0"; + copyright = ""; + maintainer = ""; + author = ""; + homepage = "https://github.com/iohk/plutus-apps#readme"; + url = ""; + synopsis = ""; + description = "Please see the README on GitHub at "; + buildType = "Simple"; + isLocal = true; + detailLevel = "FullDetails"; + licenseFiles = [ "LICENSE" "NOTICE" ]; + dataDir = "."; + dataFiles = []; + extraSrcFiles = []; + extraTmpFiles = []; + extraDocFiles = []; + }; + components = { + "library" = { + depends = [ + (hsPkgs."base" or (errorHandler.buildDepError "base")) + (hsPkgs."containers" or (errorHandler.buildDepError "containers")) + (hsPkgs."lens" or (errorHandler.buildDepError "lens")) + (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-tx" or (errorHandler.buildDepError "plutus-tx")) + (hsPkgs."QuickCheck" or (errorHandler.buildDepError "QuickCheck")) + (hsPkgs."stm" or (errorHandler.buildDepError "stm")) + (hsPkgs."tasty" or (errorHandler.buildDepError "tasty")) + (hsPkgs."aeson" or (errorHandler.buildDepError "aeson")) + (hsPkgs."splitmix" or (errorHandler.buildDepError "splitmix")) + (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring")) + (hsPkgs."mtl" or (errorHandler.buildDepError "mtl")) + ]; + buildable = true; + modules = [ + "Plutus/Contract/Test/Certification" + "Plutus/Contract/Test/Certification/Run" + ]; + hsSourceDirs = [ "src" ]; + }; + }; + } // rec { src = (pkgs.lib).mkDefault ../plutus-contract-certification; } \ No newline at end of file diff --git a/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-use-cases.nix b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-use-cases.nix index 1d41d27fff..b5cd38a6bc 100644 --- a/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-use-cases.nix +++ b/nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-use-cases.nix @@ -119,6 +119,7 @@ (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) (hsPkgs."plutus-use-cases" or (errorHandler.buildDepError "plutus-use-cases")) + (hsPkgs."plutus-contract-certification" or (errorHandler.buildDepError "plutus-contract-certification")) (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative")) (hsPkgs."cardano-api" or (errorHandler.buildDepError "cardano-api")) ] ++ (pkgs.lib).optional (!(compiler.isGhcjs && true || system.isGhcjs)) (hsPkgs."plutus-tx-plugin" or (errorHandler.buildDepError "plutus-tx-plugin")); @@ -156,6 +157,7 @@ depends = [ (hsPkgs."plutus-tx" or (errorHandler.buildDepError "plutus-tx")) (hsPkgs."plutus-contract" or (errorHandler.buildDepError "plutus-contract")) + (hsPkgs."plutus-contract-certification" or (errorHandler.buildDepError "plutus-contract-certification")) (hsPkgs."plutus-ledger" or (errorHandler.buildDepError "plutus-ledger")) (hsPkgs."plutus-ledger-constraints" or (errorHandler.buildDepError "plutus-ledger-constraints")) (hsPkgs."plutus-use-cases" or (errorHandler.buildDepError "plutus-use-cases")) diff --git a/nix/pkgs/haskell/materialized-windows/default.nix b/nix/pkgs/haskell/materialized-windows/default.nix index 9995a18a91..edc89f093b 100644 --- a/nix/pkgs/haskell/materialized-windows/default.nix +++ b/nix/pkgs/haskell/materialized-windows/default.nix @@ -850,6 +850,7 @@ small-steps = ./.plan.nix/small-steps.nix; cardano-crypto-wrapper = ./.plan.nix/cardano-crypto-wrapper.nix; network-mux = ./.plan.nix/network-mux.nix; + plutus-contract-certification = ./.plan.nix/plutus-contract-certification.nix; plutus-ghc-stub = ./.plan.nix/plutus-ghc-stub.nix; compact-map = ./.plan.nix/compact-map.nix; ouroboros-network-framework = ./.plan.nix/ouroboros-network-framework.nix; @@ -1065,6 +1066,7 @@ "asserts" = lib.mkOverride 900 false; }; }; + "plutus-contract-certification" = { flags = {}; }; "plutus-ghc-stub" = { flags = {}; }; "compact-map" = { flags = {}; }; "ouroboros-network-framework" = { flags = {}; }; @@ -1434,6 +1436,7 @@ "quickcheck-classes".components.library.planned = lib.mkOverride 900 true; "srcloc".components.library.planned = lib.mkOverride 900 true; "atomic-primops".components.library.planned = lib.mkOverride 900 true; + "plutus-contract-certification".components.library.planned = lib.mkOverride 900 true; "command".components.library.planned = lib.mkOverride 900 true; "array".components.library.planned = lib.mkOverride 900 true; "th-compat".components.library.planned = lib.mkOverride 900 true; diff --git a/plutus-contract-certification/ARCHITECTURE.adoc b/plutus-contract-certification/ARCHITECTURE.adoc new file mode 100644 index 0000000000..83e9398394 --- /dev/null +++ b/plutus-contract-certification/ARCHITECTURE.adoc @@ -0,0 +1,8 @@ +=== `plutus-contract-certification` + +This package defines interfaces for and implementation of contract certification. + +Noteworty modules: + +* `Contract.Test.Certification`: Has the core interfaces for certification +* `Contract.Test.Certification.Run`: Functions for running the certification test diff --git a/plutus-contract-certification/LICENSE b/plutus-contract-certification/LICENSE new file mode 100644 index 0000000000..0c8a80022e --- /dev/null +++ b/plutus-contract-certification/LICENSE @@ -0,0 +1,53 @@ +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of this License; and +You must cause any modified files to carry prominent notices stating that You changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/plutus-contract-certification/NOTICE b/plutus-contract-certification/NOTICE new file mode 100644 index 0000000000..f3a42c2dcd --- /dev/null +++ b/plutus-contract-certification/NOTICE @@ -0,0 +1,14 @@ +Copyright 2022 Input Output (Hong Kong) Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/plutus-contract-certification/README.md b/plutus-contract-certification/README.md new file mode 100644 index 0000000000..382e5a5afd --- /dev/null +++ b/plutus-contract-certification/README.md @@ -0,0 +1,3 @@ +# plutus-contract-certification + +A library for certifying Plutus contracts. diff --git a/plutus-contract-certification/plutus-contract-certification.cabal b/plutus-contract-certification/plutus-contract-certification.cabal new file mode 100644 index 0000000000..2e1fe67e68 --- /dev/null +++ b/plutus-contract-certification/plutus-contract-certification.cabal @@ -0,0 +1,48 @@ +cabal-version: 3.0 +name: plutus-contract-certification +version: 0.1.0.0 +license: Apache-2.0 +license-files: + LICENSE + NOTICE +homepage: https://github.com/iohk/plutus-apps#readme +bug-reports: https://github.com/iohk/plutus-apps/issues +description: + Please see the README on GitHub at +build-type: Simple + +source-repository head + type: git + location: https://github.com/input-output-hk/plutus-apps + +common lang + default-language: Haskell2010 + default-extensions: ExplicitForAll ScopedTypeVariables MultiParamTypeClasses + DeriveGeneric StandaloneDeriving DeriveLift FlexibleContexts + GeneralizedNewtypeDeriving DeriveFunctor DeriveFoldable + DeriveTraversable ImportQualifiedPost + ghc-options: -Wall -Wnoncanonical-monad-instances -Wunused-packages + -Wincomplete-uni-patterns -Wincomplete-record-updates + -Wredundant-constraints -Widentities + -- See Plutus Tx readme + -fobject-code -fno-ignore-interface-pragmas -fno-omit-interface-pragmas + +library + import: lang + exposed-modules: + Plutus.Contract.Test.Certification + Plutus.Contract.Test.Certification.Run + hs-source-dirs: src + build-depends: + base >=4.7 && <5, + containers -any, + lens -any, + plutus-contract -any, + plutus-tx -any, + QuickCheck -any, + stm -any, + tasty -any, + aeson -any, + splitmix -any, + bytestring -any, + mtl -any diff --git a/plutus-contract-certification/src/Plutus/Contract/Test/Certification.hs b/plutus-contract-certification/src/Plutus/Contract/Test/Certification.hs new file mode 100644 index 0000000000..44b7ecabce --- /dev/null +++ b/plutus-contract-certification/src/Plutus/Contract/Test/Certification.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE GADTs #-} +module Plutus.Contract.Test.Certification where + +import Plutus.Contract.Test.ContractModel +import Plutus.Contract.Test.ContractModel.CrashTolerance +import PlutusTx.Coverage +import Test.Tasty as Tasty + +data Instance c m where + Instance :: c m => Instance c m + +-- | A certification object specifies what tests should be run by the +-- 'Plutus.Contract.Test.Certification.Run.certify' function. +data Certification m = Certification { + certCoverageIndex :: CoverageIndex, -- ^ Coverage locations for on-chain test coverage. + certNoLockedFunds :: Maybe (NoLockedFundsProof m), + certNoLockedFundsLight :: Maybe (NoLockedFundsProofLight m), + certUnitTests :: Maybe (CoverageRef -> TestTree), -- ^ Unit tests using "Test.Tasty". See e.g. 'Plutus.Contract.Test.checkPredicateCoverage'. + certCrashTolerance :: Maybe (Instance CrashTolerance m), -- ^ Contract model for testing robustness against off-chain code crashes. + certWhitelist :: Maybe Whitelist, -- ^ List of allowed exceptions from on-chain code. Usually `Just 'defaultWhiteList'`. + certDLTests :: [(String, DL m ())] -- ^ Unit tests using 'Plutus.Contract.Test.ContractModel.DL'. + } + +defaultCertification :: Certification m +defaultCertification = Certification { certCoverageIndex = mempty + , certNoLockedFunds = Nothing + , certNoLockedFundsLight = Nothing + , certUnitTests = Nothing + , certCrashTolerance = Nothing + , certWhitelist = Just defaultWhitelist + , certDLTests = [] } diff --git a/plutus-contract-certification/src/Plutus/Contract/Test/Certification/Run.hs b/plutus-contract-certification/src/Plutus/Contract/Test/Certification/Run.hs new file mode 100644 index 0000000000..b1847d81b1 --- /dev/null +++ b/plutus-contract-certification/src/Plutus/Contract/Test/Certification/Run.hs @@ -0,0 +1,228 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE DerivingVia #-} +{-# LANGUAGE QuantifiedConstraints #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Plutus.Contract.Test.Certification.Run + ( -- * A certification report holds all the necessary information + -- to make sense of certification results + CertificationReport + , certResJSON + -- * There are a tonne of lenses + , certRes_standardPropertyResult + , certRes_noLockedFundsResult + , certRes_noLockedFundsLightResult + , certRes_standardCrashToleranceResult + , certRes_unitTestResults + , certRes_coverageReport + , certRes_coverageIndexReport + , certRes_whitelistOk + , certRes_whitelistResult + , certRes_DLTests + -- * and we have a function for running certification + , CertificationOptions(..) + , defaultCertificationOptions + , certify + , certifyWithOptions + ) where + +import Control.Concurrent.STM +import Control.Exception +import Control.Lens +import Control.Monad.Writer +import Data.Aeson (FromJSON (..), ToJSON (..), encode) +import Data.ByteString.Lazy.Char8 +import Data.IntMap qualified as IntMap +import Data.Maybe +import GHC.Generics +import Plutus.Contract.Test.Certification +import Plutus.Contract.Test.ContractModel +import Plutus.Contract.Test.ContractModel.CrashTolerance +import Plutus.Contract.Test.Coverage +import PlutusTx.Coverage +import System.Random.SplitMix +import Test.QuickCheck as QC +import Test.QuickCheck.Random as QC +import Test.Tasty as Tasty +import Test.Tasty.Runners as Tasty +import Text.Read hiding (lift) + +newtype JSONShowRead a = JSONShowRead a + +instance Show a => ToJSON (JSONShowRead a) where + toJSON (JSONShowRead a) = toJSON (show a) + +instance Read a => FromJSON (JSONShowRead a) where + parseJSON v = do + str <- parseJSON v + case readMaybe str of + Nothing -> fail "JSONShowRead: readMaybe Nothing" + Just a -> return $ JSONShowRead a + +deriving via (JSONShowRead SMGen) instance FromJSON SMGen +deriving via (JSONShowRead SMGen) instance ToJSON SMGen + +deriving via SMGen instance FromJSON QCGen +deriving via SMGen instance ToJSON QCGen +deriving instance Generic QC.Result +deriving instance ToJSON QC.Result +deriving instance FromJSON QC.Result + +instance ToJSON SomeException where + toJSON (SomeException e) = toJSON (show e) +instance FromJSON SomeException where + parseJSON v = do + str <- parseJSON v + return $ SomeException (ErrorCall str) + +deriving via (JSONShowRead Tasty.Result) instance ToJSON Tasty.Result + +data CertificationReport m = CertificationReport { + _certRes_standardPropertyResult :: QC.Result, + _certRes_noLockedFundsResult :: Maybe QC.Result, + _certRes_noLockedFundsLightResult :: Maybe QC.Result, + _certRes_standardCrashToleranceResult :: Maybe QC.Result, + _certRes_unitTestResults :: [Tasty.Result], + _certRes_coverageReport :: CoverageReport, + _certRes_coverageIndexReport :: CoverageIndex, + _certRes_whitelistOk :: Maybe Bool, + _certRes_whitelistResult :: Maybe QC.Result, + _certRes_DLTests :: [(String, QC.Result)] + } deriving (Show, Generic, ToJSON) +makeLenses ''CertificationReport + +certResJSON :: CertificationReport m -> String +certResJSON = unpack . encode + +data CertificationOptions = CertificationOptions { certOptNumTests :: Int + , certOptOutput :: Bool } + +defaultCertificationOptions :: CertificationOptions +defaultCertificationOptions = CertificationOptions { certOptOutput = True , certOptNumTests = 100 } + +type CertMonad = WriterT CoverageReport IO + +liftIORep :: IO (CoverageReport, a) -> CertMonad a +liftIORep io = do + (rep, a) <- lift io + tell rep + return a + +runCertMonad :: CertMonad (CertificationReport m) -> IO (CertificationReport m) +runCertMonad m = do + (rep, cov) <- runWriterT m + return $ rep { _certRes_coverageReport = cov } + +runStandardProperty :: forall m. ContractModel m => CertificationOptions -> CoverageIndex -> CertMonad QC.Result +runStandardProperty opts covIdx = liftIORep $ quickCheckWithCoverageAndResult + (mkQCArgs opts) + (set coverageIndex covIdx defaultCoverageOptions) + $ \ covopts -> propRunActionsWithOptions + @m + defaultCheckOptionsContractModel + covopts + $ const (pure True) + +checkNoLockedFunds :: ContractModel m => CertificationOptions -> NoLockedFundsProof m -> CertMonad QC.Result +checkNoLockedFunds opts prf = lift $ quickCheckWithResult + (mkQCArgs opts) + $ checkNoLockedFundsProof defaultCheckOptionsContractModel prf + +checkNoLockedFundsLight :: ContractModel m => CertificationOptions -> NoLockedFundsProofLight m -> CertMonad QC.Result +checkNoLockedFundsLight opts prf = + lift $ quickCheckWithResult + (mkQCArgs opts) + (checkNoLockedFundsProofLight prf) + +mkQCArgs :: CertificationOptions -> Args +mkQCArgs CertificationOptions{..} = stdArgs { chatty = certOptOutput , maxSuccess = certOptNumTests } + +runUnitTests :: (CoverageRef -> TestTree) -> CertMonad [Tasty.Result] +runUnitTests t = liftIORep $ do + ref <- newCoverageRef + res <- launchTestTree mempty (t ref) $ \ status -> do + rs <- atomically $ mapM waitForDone (IntMap.elems status) + return $ \ _ -> return rs + cov <- readCoverageRef ref + return (cov, res) + where + waitForDone tv = do + s <- readTVar tv + case s of + Done r -> return r + _ -> retry + +checkDerived :: forall d m c. (c m => ContractModel (d m)) + => Maybe (Instance c m) + -> CertificationOptions + -> CoverageIndex + -> CertMonad (Maybe QC.Result) +checkDerived Nothing _ _ = return Nothing +checkDerived (Just Instance) opts covIdx = Just <$> runStandardProperty @(d m) opts covIdx + +checkWhitelist :: forall m. ContractModel m + => Maybe Whitelist + -> CertificationOptions + -> CoverageIndex + -> CertMonad (Maybe QC.Result) +checkWhitelist Nothing _ _ = return Nothing +checkWhitelist (Just wl) opts covIdx = do + a <- liftIORep $ quickCheckWithCoverageAndResult + (mkQCArgs opts) + (set coverageIndex covIdx defaultCoverageOptions) + $ \ covopts -> checkErrorWhitelistWithOptions @m + defaultCheckOptionsContractModel + covopts wl + return (Just a) + +checkDLTests :: forall m. ContractModel m + => [(String, DL m ())] + -> CertificationOptions + -> CoverageIndex + -> CertMonad [(String, QC.Result)] +checkDLTests tests opts covIdx = + sequence [(s,) <$> liftIORep (quickCheckWithCoverageAndResult + (mkQCArgs opts) + (set coverageIndex covIdx defaultCoverageOptions) + $ \ covopts -> forAllDL dl (propRunActionsWithOptions @m defaultCheckOptionsContractModel covopts (const $ pure True))) + | (s, dl) <- tests ] + +certify :: forall m. ContractModel m => Certification m -> IO (CertificationReport m) +certify = certifyWithOptions defaultCertificationOptions + +certifyWithOptions :: forall m. ContractModel m => CertificationOptions -> Certification m -> IO (CertificationReport m) +certifyWithOptions opts Certification{..} = runCertMonad $ do + -- Unit tests + unitTests <- fromMaybe [] <$> traverse runUnitTests certUnitTests + -- Standard property + qcRes <- runStandardProperty @m opts certCoverageIndex + -- No locked funds + noLock <- traverse (checkNoLockedFunds opts) certNoLockedFunds + -- No locked funds light + noLockLight <- traverse (checkNoLockedFundsLight opts) certNoLockedFundsLight + -- Crash tolerance + ctRes <- checkDerived @WithCrashTolerance certCrashTolerance opts certCoverageIndex + -- Whitelist + wlRes <- checkWhitelist @m certWhitelist opts certCoverageIndex + -- DL tests + dlRes <- checkDLTests @m certDLTests opts certCoverageIndex + -- Final results + return $ CertificationReport { _certRes_standardPropertyResult = qcRes, + _certRes_standardCrashToleranceResult = ctRes, + _certRes_noLockedFundsResult = noLock, + _certRes_noLockedFundsLightResult = noLockLight, + _certRes_unitTestResults = unitTests, + _certRes_coverageReport = mempty, + _certRes_coverageIndexReport = certCoverageIndex, + _certRes_whitelistOk = whitelistOk <$> certWhitelist, + _certRes_whitelistResult = wlRes, + _certRes_DLTests = dlRes } diff --git a/plutus-contract/src/Plutus/Contract/Test/ContractModel.hs b/plutus-contract/src/Plutus/Contract/Test/ContractModel.hs index 3ecc2ef8b6..f84029a113 100644 --- a/plutus-contract/src/Plutus/Contract/Test/ContractModel.hs +++ b/plutus-contract/src/Plutus/Contract/Test/ContractModel.hs @@ -110,6 +110,7 @@ module Plutus.Contract.Test.ContractModel , checkCoverage , coverageIndex , quickCheckWithCoverage + , quickCheckWithCoverageAndResult -- ** Emulator properties , propRunActions_ , propRunActions @@ -132,6 +133,8 @@ module Plutus.Contract.Test.ContractModel , defaultNLFP , checkNoLockedFundsProof , checkNoLockedFundsProofFast + , NoLockedFundsProofLight(..) + , checkNoLockedFundsProofLight -- $checkNoPartiality , Whitelist , whitelistOk diff --git a/plutus-contract/src/Plutus/Contract/Test/ContractModel/Internal.hs b/plutus-contract/src/Plutus/Contract/Test/ContractModel/Internal.hs index 66f06f12c0..daaa04f485 100644 --- a/plutus-contract/src/Plutus/Contract/Test/ContractModel/Internal.hs +++ b/plutus-contract/src/Plutus/Contract/Test/ContractModel/Internal.hs @@ -121,6 +121,7 @@ module Plutus.Contract.Test.ContractModel.Internal , checkCoverage , coverageIndex , quickCheckWithCoverage + , quickCheckWithCoverageAndResult -- ** Emulator properties , propRunActions_ , propRunActions @@ -144,6 +145,8 @@ module Plutus.Contract.Test.ContractModel.Internal , defaultNLFP , checkNoLockedFundsProof , checkNoLockedFundsProofFast + , NoLockedFundsProofLight(..) + , checkNoLockedFundsProofLight -- $checkNoPartiality , Whitelist , whitelistOk @@ -1357,25 +1360,28 @@ makeLenses ''CoverageOptions -- * not to cover any source locations in the validator scripts. defaultCoverageOptions :: CoverageOptions defaultCoverageOptions = CoverageOptions { _checkCoverage = False - , _endpointCoverageReq = \ _ _ -> 20 + , _endpointCoverageReq = \ _ _ -> 0 , _coverageIndex = mempty , _coverageIORef = Nothing } -- | Run QuickCheck on a property that tracks coverage and print its coverage report. -quickCheckWithCoverage :: QC.Testable prop => CoverageOptions -> (CoverageOptions -> prop) -> IO CoverageReport -quickCheckWithCoverage copts prop = do +quickCheckWithCoverage :: QC.Testable prop => QC.Args -> CoverageOptions -> (CoverageOptions -> prop) -> IO CoverageReport +quickCheckWithCoverage qcargs opts prop = fst <$> quickCheckWithCoverageAndResult qcargs opts prop + +quickCheckWithCoverageAndResult :: QC.Testable prop => QC.Args -> CoverageOptions -> (CoverageOptions -> prop) -> IO (CoverageReport, Result) +quickCheckWithCoverageAndResult qcargs copts prop = do copts <- case copts ^. coverageIORef of Nothing -> do ref <- newIORef mempty return $ copts { _coverageIORef = Just ref } _ -> return copts - QC.quickCheck $ prop $ copts { _checkCoverage = True } + res <- QC.quickCheckWithResult qcargs $ prop $ copts { _checkCoverage = True } case copts ^. coverageIORef of Nothing -> fail "Unreachable case in quickCheckWithCoverage" Just ref -> do report <- readIORef ref - putStrLn . show $ pprCoverageReport (copts ^. coverageIndex) report - return report + when (chatty qcargs) $ putStrLn . show $ pprCoverageReport (copts ^. coverageIndex) report + return (report, res) finalChecks :: ContractModel state => CheckOptions @@ -1681,6 +1687,8 @@ data NoLockedFundsProof model = NoLockedFundsProof -- to the MainStrategy. This is useful if your contract contains rounding code that makes the order -- of operations have a small but predictable effect on the value collected by different wallets. } +data NoLockedFundsProofLight model = NoLockedFundsProofLight + { nlfplMainStrategy :: DL model () } -- | The default skeleton of a NoLockedFundsProof - doesn't permit any overhead or error margin. defaultNLFP :: NoLockedFundsProof model @@ -1753,6 +1761,19 @@ checkNoLockedFundsProof' run NoLockedFundsProof{nlfpMainStrategy = mainStrat, in counterexample err (symLeq bal (bal' <> wig)) QC..&&. counterexample err' (run smacts) +checkNoLockedFundsProofLight + :: ContractModel model + => NoLockedFundsProofLight model + -> Property +checkNoLockedFundsProofLight NoLockedFundsProofLight{nlfplMainStrategy = mainStrat} = + forAllDL anyActions_ $ \ (Actions as) -> + forAllUniqueDL (nextVarIdx as) (stateAfter $ Actions as) mainStrat $ \ (Actions as') -> + counterexample "Main run prop" (run (toStateModelActions $ Actions $ as ++ as')) + where + nextVarIdx as = 1 + maximum ([0] ++ [ i | Var i <- varOf <$> as ]) + run = propRunActionsWithOptions' defaultCheckOptionsContractModel + defaultCoverageOptions (\ _ -> TracePredicate $ pure True) + -- | A whitelist entry tells you what final log entry prefixes -- are acceptable for a given error data Whitelist = Whitelist { errorPrefixes :: Set Text.Text } @@ -1831,5 +1852,4 @@ checkErrorWhitelistWithOptions opts copts whitelist acts = property $ go check a go :: TracePredicate -> Actions m -> Property go check actions = monadic (flip State.evalState mempty) $ finalChecks opts copts (\ _ _ -> check) $ do QC.run initiateWallets - snd <$> runActionsInState StateModel.initialState (toStateModelActions actions) diff --git a/plutus-contract/src/Plutus/Contract/Test/Coverage.hs b/plutus-contract/src/Plutus/Contract/Test/Coverage.hs index 827de32a4a..d4d8f158e4 100644 --- a/plutus-contract/src/Plutus/Contract/Test/Coverage.hs +++ b/plutus-contract/src/Plutus/Contract/Test/Coverage.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DerivingStrategies #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Plutus.Contract.Test.Coverage @@ -8,11 +10,13 @@ module Plutus.Contract.Test.Coverage , readCoverageRef ) where +import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey) import Data.Foldable import Data.Map (Map) import Data.Map qualified as Map import Data.Set (Set) import Data.Set qualified as Set +import GHC.Generics import Data.Text qualified as Text @@ -79,4 +83,24 @@ instance NFData CovLoc where instance NFData CoverageAnnotation where rnf (CoverLocation loc) = rnf loc rnf (CoverBool loc b) = rnf b `seq` rnf loc -deriving instance NFData CoverageReport +deriving anyclass instance NFData CoverageReport +deriving instance Generic CoverageReport +deriving anyclass instance ToJSON CoverageReport +deriving anyclass instance FromJSON CoverageReport + +deriving anyclass instance ToJSON CoverageIndex +deriving anyclass instance FromJSON CoverageIndex + +deriving anyclass instance ToJSON CoverageAnnotation +deriving anyclass instance FromJSON CoverageAnnotation +deriving anyclass instance ToJSONKey CoverageAnnotation +deriving anyclass instance FromJSONKey CoverageAnnotation + +deriving anyclass instance ToJSON CovLoc +deriving anyclass instance FromJSON CovLoc + +deriving anyclass instance ToJSON CoverageMetadata +deriving anyclass instance FromJSON CoverageMetadata + +deriving anyclass instance ToJSON Metadata +deriving anyclass instance FromJSON Metadata diff --git a/plutus-use-cases/plutus-use-cases.cabal b/plutus-use-cases/plutus-use-cases.cabal index 123b831345..eba8502bc8 100644 --- a/plutus-use-cases/plutus-use-cases.cabal +++ b/plutus-use-cases/plutus-use-cases.cabal @@ -134,6 +134,7 @@ test-suite plutus-use-cases-test build-depends: plutus-tx -any, plutus-contract -any, + plutus-contract-certification -any, plutus-ledger -any, plutus-ledger-constraints -any, plutus-use-cases -any @@ -221,6 +222,7 @@ executable plutus-use-cases-scripts plutus-ledger -any, plutus-ledger-constraints -any, plutus-use-cases -any, + plutus-contract-certification -any, optparse-applicative -any, cardano-api -any diff --git a/plutus-use-cases/test/Spec/GameStateMachine.hs b/plutus-use-cases/test/Spec/GameStateMachine.hs index 3a1da35ce7..929465c660 100644 --- a/plutus-use-cases/test/Spec/GameStateMachine.hs +++ b/plutus-use-cases/test/Spec/GameStateMachine.hs @@ -26,6 +26,7 @@ module Spec.GameStateMachine , prop_SanityCheckModel , prop_SanityCheckAssertions , prop_GameCrashTolerance + , certification ) where import Control.Exception hiding (handle) @@ -47,6 +48,7 @@ import Ledger.Typed.Scripts qualified as Scripts import Ledger.Value (Value) import Plutus.Contract.Secrets import Plutus.Contract.Test hiding (not) +import Plutus.Contract.Test.Certification import Plutus.Contract.Test.ContractModel import Plutus.Contract.Test.ContractModel.CrashTolerance import Plutus.Contract.Test.Coverage @@ -208,7 +210,7 @@ prop_SanityCheckAssertions = propSanityCheckAssertions check_prop_Game_with_coverage :: IO CoverageReport check_prop_Game_with_coverage = - quickCheckWithCoverage (set coverageIndex (covIdx gameParam) defaultCoverageOptions) $ \covopts -> + quickCheckWithCoverage stdArgs (set coverageIndex (covIdx gameParam) defaultCoverageOptions) $ \covopts -> propRunActionsWithOptions @GameModel defaultCheckOptionsContractModel covopts (const (pure True)) @@ -240,10 +242,10 @@ genValue = choose (Ada.getLovelace Ledger.minAdaTxOut, 100_000_000) -- Dynamic Logic ---------------------------------------------------------- prop_UnitTest :: Property -prop_UnitTest = withMaxSuccess 1 $ forAllDL unitTest prop_Game +prop_UnitTest = withMaxSuccess 1 $ forAllDL unitTest1 prop_Game -unitTest :: DL GameModel () -unitTest = do +unitTest1 :: DL GameModel () +unitTest1 = do val <- forAllQ $ chooseQ (5_000_000, 20_000_000) action $ Lock w1 "hello" val action $ GiveToken w2 @@ -251,7 +253,7 @@ unitTest = do unitTest2 :: DL GameModel () unitTest2 = do - unitTest + unitTest1 action $ GiveToken w3 action $ Guess w3 "new secret" "hello" 4_000_000 @@ -449,3 +451,20 @@ guessTokenVal :: Value guessTokenVal = let sym = Scripts.forwardingMintingPolicyHash $ G.typedValidator gameParam in G.token sym "guess" + +-- | Certification. +certification :: Certification GameModel +certification = defaultCertification { + certNoLockedFunds = Just noLockProof, + certUnitTests = Just unitTest, + certCoverageIndex = covIdx gameParam, + certCrashTolerance = Just Instance, + certWhitelist = Just defaultWhitelist + } + where + unitTest ref = + checkPredicateCoverage "run a successful game trace" ref + (walletFundsChange w2 (Ada.toValue Ledger.minAdaTxOut <> Ada.adaValueOf 3 <> guessTokenVal) + .&&. valueAtAddress (Scripts.validatorAddress $ G.typedValidator gameParam) (Ada.adaValueOf 5 ==) + .&&. walletFundsChange w1 (Ada.toValue (-Ledger.minAdaTxOut) <> Ada.adaValueOf (-8))) + successTrace diff --git a/plutus-use-cases/test/Spec/Uniswap.hs b/plutus-use-cases/test/Spec/Uniswap.hs index 6d76ecda55..c6fcbd6fce 100644 --- a/plutus-use-cases/test/Spec/Uniswap.hs +++ b/plutus-use-cases/test/Spec/Uniswap.hs @@ -20,6 +20,7 @@ import Control.Monad import Plutus.Contract import Plutus.Contract as Contract hiding (throwError) import Plutus.Contract.Test hiding (not) +import Plutus.Contract.Test.Certification import Plutus.Contract.Test.ContractModel import Plutus.Contract.Test.ContractModel.Symbolics import Plutus.Contract.Test.Coverage @@ -507,6 +508,9 @@ noLockProof = defaultNLFP { then action $ ClosePool w t1 t2 else action $ RemoveLiquidity w t1 t2 (unAmount . sum $ Map.lookup w liqs) +noLockProofLight :: NoLockedFundsProofLight UniswapModel +noLockProofLight = NoLockedFundsProofLight{nlfplMainStrategy = nlfpMainStrategy noLockProof} + prop_CheckNoLockedFundsProof :: Property prop_CheckNoLockedFundsProof = checkNoLockedFundsProof defaultCheckOptionsContractModel noLockProof @@ -515,8 +519,12 @@ prop_CheckNoLockedFundsProofFast = checkNoLockedFundsProofFast defaultCheckOptio check_propUniswapWithCoverage :: IO () check_propUniswapWithCoverage = void $ - quickCheckWithCoverage (set endpointCoverageReq epReqs $ set coverageIndex covIdx $ defaultCoverageOptions) $ \covopts -> - withMaxSuccess 1000 $ propRunActionsWithOptions @UniswapModel defaultCheckOptionsContractModel covopts (const (pure True)) + quickCheckWithCoverage (stdArgs { maxSuccess = 1000 }) + (set endpointCoverageReq epReqs $ set coverageIndex covIdx $ defaultCoverageOptions) + $ \covopts -> propRunActionsWithOptions @UniswapModel + defaultCheckOptionsContractModel + covopts + (const (pure True)) where epReqs t ep | t == Trace.walletInstanceTag w1 = 0 @@ -562,3 +570,10 @@ runTestsWithCoverage = do .&&. assertNoFailedTransactions) Uniswap.uniswapTrace ] + +-- | Certification. +certification :: Certification UniswapModel +certification = defaultCertification { + certNoLockedFundsLight = Just noLockProofLight, + certCoverageIndex = covIdx + }