diff --git a/.github/workflows/build-plutus-examples.yml b/.github/workflows/build-plutus-examples.yml new file mode 100644 index 00000000000..2317e99ef85 --- /dev/null +++ b/.github/workflows/build-plutus-examples.yml @@ -0,0 +1,117 @@ +name: Plutus Examples + +on: [push] + +jobs: + build: + runs-on: ${{ matrix.os }} + + defaults: + run: + shell: bash + + strategy: + fail-fast: false + matrix: + ghc: ["8.10.4"] + os: [ubuntu-latest, macos-latest] + + steps: + + - uses: haskell/actions/setup@v1 + id: setup-haskell + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: 3.4.0.0 + + - name: Set cache version + run: echo "CACHE_VERSION=grFfw8r" >> $GITHUB_ENV + + - uses: actions/checkout@v2 + + - name: Add build script path + run: echo "$(pwd)/.github/bin" >> $GITHUB_PATH + + - name: Install pkgconfiglite + if: matrix.os == 'windows-latest' + run: retry 2 choco install -y pkgconfiglite + + - name: Install libsodium (Windows) + if: matrix.os == 'windows-latest' + run: | + curl -Ls \ + --connect-timeout 5 \ + --max-time 10 \ + --retry 5 \ + --retry-delay 0 \ + --retry-max-time 40 \ + https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-mingw.tar.gz -o libsodium-1.0.18-mingw.tar.gz + tar zxvf libsodium-1.0.18-mingw.tar.gz + + sed -i "s|/d/a/1/s/|D:/a/cardano-node/cardano-node/|g" libsodium-win64/lib/pkgconfig/libsodium.pc + + export PKG_CONFIG_PATH="$(readlink -f libsodium-win64/lib/pkgconfig)" + echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV + + export LIBSODIUM_PATH="$(readlink -f libsodium-win64/bin | sed 's|^/d|D:|g' | tr / '\\')" + echo "LIBSODIUM_PATH=$LIBSODIUM_PATH" + echo "$LIBSODIUM_PATH" >> $GITHUB_PATH + + - name: Install libsodium (MacOS) + if: matrix.os == 'macos-latest' + run: brew install libsodium + + - name: Setup Github Scripts + run: echo "$(pwd)/.github/bin" >> $GITHUB_PATH + + - name: Configure to use libsodium + run: | + cd plutus-example + cat >> cabal.project < dependencies.txt + date > date.txt + + - uses: actions/cache@v2 + name: Cache cabal store + with: + path: ${{ steps.setup-haskell.outputs.cabal-store }} + key: cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('plutus-example/dependencies.txt') }}-${{ hashFiles('date.txt') }} + restore-keys: | + cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('plutus-example/dependencies.txt') }}-${{ hashFiles('date.txt') }} + cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('plutus-example/dependencies.txt') }} + cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }} + + - name: Build + run: | + cd plutus-example + retry 2 cabal build plutus-example + + - name: Run tests + run: | + cd plutus-example + retry 2 cabal test plutus-example diff --git a/.gitignore b/.gitignore index 897422bed2e..390700316ca 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ /cabal.project.old configuration/defaults/simpleview/genesis/ configuration/defaults/liveview/genesis/ -/dist-newstyle/ +dist-newstyle dist/ *~ \#* diff --git a/plutus-example/cabal.project b/plutus-example/cabal.project index 396867fe6f4..d1a69819b0b 100644 --- a/plutus-example/cabal.project +++ b/plutus-example/cabal.project @@ -19,8 +19,8 @@ test-show-details: direct source-repository-package type: git location: https://github.com/input-output-hk/hedgehog-extras - tag: 8bcd3c9dc22cc44f9fcfe161f4638a384fc7a187 - --sha256: 12viwpahjdfvlqpnzdgjp40nw31rvyznnab1hml9afpaxd6ixh70 + tag: ccb5648ad3c93744f67e244706a7a3e36dcfbab0 + --sha256: 0p9jgpj9cjkg184y1rswz90sw0nq13rld80fa5s59xcyvsa31p7y source-repository-package type: git @@ -35,7 +35,6 @@ source-repository-package cardano-crypto-tests slotting strict-containers - source-repository-package type: git location: https://github.com/input-output-hk/cardano-crypto @@ -45,8 +44,8 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/cardano-ledger-specs - tag: d6b3d6b8ed16b2c69684fa44218f4e7060f166d3 - --sha256: 1afsvxv8a24rpd3inr4m323l1dx5xg6kmfnjkzb6jw72ykcgpsyz + tag: 0fa5a737aa5bed6f835402526f0b2d541ed83dab + --sha256: 0dd75944f1ww0bnr1l02igwkiwbwkvrlv6yldlgakdpqyfn1np9d subdir: alonzo/impl byron/chain/executable-spec @@ -97,17 +96,18 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/Win32-network - tag: 82f4afb8c240b8446a1db6c6b50901a42028ce0f - --sha256: 0ljxjzywk6xh9n4mfg21am65z65anlrq47z6zyzcav3h6iasvfq2 + tag: 5b3d08c454f425da5cf045fe7865950d7c806691 + --sha256: 0npyihbaqlih9abdbaj451lm1h0kl5braczy8vn41s3ivbbnvpcw source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 47b94669555fb3e4f5f3b985f5d804090cfb60c4 - --sha256: 1y20brl7scppf55037bq5rnq6vdab2f6x56nqsg8grj2gipihkdp + tag: b749bc878bb05478f924d6e2d4970d1bdaef94ef + --sha256: 1k1cc5sqq9h6jrr5psi4vzs1ay3wafj42gpfv8b67cpnxfivj4m6 subdir: io-sim io-sim-classes + monoidal-synchronisation network-mux ouroboros-consensus ouroboros-consensus-byron @@ -122,8 +122,8 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/plutus - tag: bd0dec6dbbf87a14b54384cc083be2bfaf8d5ca6 - --sha256: 09qhhiks1qj3x0h3vhr3j7p8kfnbrp2sqi2gc6d16s5zy2pyjbqh + tag: e11d59a181f558fb5d2e5b0a2a32afd496660bc1 + --sha256: 0hdck39i4yv656phxjy5ppqgzrq7x3q4b5rf8vj7hrzcs0aggl8r subdir: plutus-core plutus-ledger diff --git a/plutus-example/plutus-example/app/plutus-example.hs b/plutus-example/plutus-example/app/plutus-example.hs index 6f17a80c32e..4eb85702e12 100644 --- a/plutus-example/plutus-example/app/plutus-example.hs +++ b/plutus-example/plutus-example/app/plutus-example.hs @@ -5,8 +5,6 @@ import Cardano.Api import Cardano.Api.Shelley import qualified Cardano.Ledger.Alonzo.Data as Alonzo -import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo -import qualified Cardano.Ledger.Coin as Shelley import Data.Aeson (encode) import qualified Data.ByteString.Lazy as LBS import qualified Plutus.V1.Ledger.Api as Plutus diff --git a/plutus-example/plutus-example/src/Cardano/PlutusExample/MintingScript.hs b/plutus-example/plutus-example/src/Cardano/PlutusExample/MintingScript.hs index d0d65c655bb..da0d91aa165 100644 --- a/plutus-example/plutus-example/src/Cardano/PlutusExample/MintingScript.hs +++ b/plutus-example/plutus-example/src/Cardano/PlutusExample/MintingScript.hs @@ -37,8 +37,8 @@ import PlutusTx.Prelude hiding (Semigroup (..), unless) {- HLINT ignore "Avoid lambda" -} {-# INLINABLE mkPolicy #-} -mkPolicy :: PubKeyHash -> ScriptContext -> Bool -mkPolicy ownerPkh ctx = +mkPolicy :: PubKeyHash -> () -> ScriptContext -> Bool +mkPolicy ownerPkh () ctx = traceIfFalse "Only owner can mint" mustBeSignedBy' where info :: TxInfo @@ -47,20 +47,20 @@ mkPolicy ownerPkh ctx = mustBeSignedBy' :: Bool mustBeSignedBy' = txSignedBy info ownerPkh -policy :: PubKeyHash -> Scripts.MonetaryPolicy -policy ownerPkh = mkMonetaryPolicyScript $ - $$(PlutusTx.compile [|| \ownerPkh' -> Scripts.wrapMonetaryPolicy $ mkPolicy ownerPkh' ||]) +policy :: PubKeyHash -> Scripts.MintingPolicy +policy ownerPkh = mkMintingPolicyScript $ + $$(PlutusTx.compile [|| \ownerPkh' -> Scripts.wrapMintingPolicy (mkPolicy ownerPkh') ||]) `PlutusTx.applyCode` PlutusTx.liftCode ownerPkh plutusScript :: Script plutusScript = - unMonetaryPolicyScript + unMintingPolicyScript $ policy "e7dc13db93c1f56b3fd51752c14d5fdd20157334b9f0a0186d8dbd39" validator :: Validator validator = - Validator . unMonetaryPolicyScript + Validator . unMintingPolicyScript $ policy "e7dc13db93c1f56b3fd51752c14d5fdd20157334b9f0a0186d8dbd39" scriptAsCbor :: LB.ByteString diff --git a/plutus-example/plutus-example/src/Cardano/PlutusExample/Typed/DatumRedeemerGuess.hs b/plutus-example/plutus-example/src/Cardano/PlutusExample/Typed/DatumRedeemerGuess.hs index c7196f402be..ba316b347cf 100644 --- a/plutus-example/plutus-example/src/Cardano/PlutusExample/Typed/DatumRedeemerGuess.hs +++ b/plutus-example/plutus-example/src/Cardano/PlutusExample/Typed/DatumRedeemerGuess.hs @@ -25,7 +25,6 @@ import qualified Data.ByteString.Short as SBS import Ledger.Contexts (ScriptContext (..)) import qualified Ledger.Typed.Scripts as Scripts import qualified Plutus.V1.Ledger.Scripts as Plutus -import PlutusTx (Data (..)) import qualified PlutusTx import PlutusTx.Prelude hiding (Semigroup (..), unless) diff --git a/scripts/project.sh b/scripts/project.sh new file mode 100755 index 00000000000..ac9d73ea932 --- /dev/null +++ b/scripts/project.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +build() { + echo -e "${CYAN}[ Building project ]${NC}" + cabal build all --write-ghc-environment-files=ghc8.4.4+ --enable-tests + + echo -e "${CYAN}[ Building plutus-example] ${NC}" + cd plutus-example + cabal build all --write-ghc-environment-files=ghc8.4.4+ --enable-tests +} + +test() { + echo -e "${CYAN}[ Testing project ]${NC}" + cabal test all --write-ghc-environment-files=ghc8.4.4+ --enable-tests --test-show-details=direct + + echo -e "${CYAN}[ Testing plutus-example ]${NC}" + cd plutus-example + cabal test all --write-ghc-environment-files=ghc8.4.4+ --enable-tests --test-show-details=direct +} + +case "$1" in + build ) build ;; + test ) test ;; +esac