Skip to content

Commit

Permalink
Simply compare the plutus.json after regeneration
Browse files Browse the repository at this point in the history
This does not require us to be in a git repository and hence makes the
test more flexible and isolated.
  • Loading branch information
locallycompact authored and ch1bo committed Oct 4, 2024
1 parent 38e1743 commit 7bafe31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
8 changes: 4 additions & 4 deletions hydra-plutus/plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
"$ref": "#/definitions/commit~1Redeemer"
}
},
"compiledCode": "5902ae010100323232323232323232322533300332323232325332330093001300b37540042646464a66666602800c2646464a66601e60060022a66602660246ea80245400803854ccc03cc01c00454ccc04cc048dd50048a80100700718081baa0081533300d3001300f37540042646464646464a6660266016602a6ea80344cc00cc01130103d87980003370e6660026eacc064c068c068c068c068c058dd50079bae30053016375400c91010b487964726148656164563100480044c94ccc050c020c058dd50008998021802a6103d87a8000300c333002375660346036602e6ea8c068c05cdd50009bae30063017375400e9110b4879647261486561645631001533015491054c35333b39001632533301800114c103d87a80001300333019301a0014bd701bac30053016375401e44464a66602c601c60306ea8004520001375a603860326ea8004c94ccc058c038c060dd50008a6103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301c337220100042a66603866e3c0200084c02ccc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301b337220100042a66603666e3c0200084c028cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c074004dd2a400044a666024002294454cc04c00852812999808180218091baa001149103433031001491034330320023015301630160013013301037540042a6601c9201054c34333b350016370e900000580580580598089809001180800098061baa002370e90010b1806980700118060009806001180500098031baa00114984d95854cc0092401064c34323b333100165734ae7155ceaab9e5573eae815d0aba257481",
"hash": "ea444d37d226e71eef73ac78d149750da977feb588900135bf9e8221"
"compiledCode": "5902ae010100323232323232323232322533300332323232325332330093001300b37540042646464a66666602800c2646464a66601e60060022a66602660246ea80245400803854ccc03cc01c00454ccc04cc048dd50048a80100700718081baa0081533300d3001300f37540042646464646464a6660266016602a6ea80344cc00cc01130103d87980003370e6660026eacc064c068c068c068c068c058dd50079bae30053016375400c91010b487964726148656164563100480044c94ccc050c020c058dd50008998021802a6103d87a8000300c333002375660346036602e6ea8c068c05cdd50009bae30063017375400e9110b4879647261486561645631001533015491054c35333b39001632533301800114c103d87a80001300333019301a0014bd701bac30053016375401e44464a66602c601c60306ea8004520001375a603860326ea8004c94ccc058c038c060dd50008a6103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301c337220100042a66603866e3c0200084c02ccc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301b337220100042a66603666e3c0200084c028cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c074004dd2a400044a666024002294454cc04c00852812999808180218091baa001149103433031001491034330330023015301630160013013301037540042a6601c9201054c34333b350016370e900000580580580598089809001180800098061baa002370e90010b1806980700118060009806001180500098031baa00114984d95854cc0092401064c34323b333100165734ae7155ceaab9e5573eae815d0aba257481",
"hash": "46a423187ec877f332c644bb361937bc1d50d6aa11f877a0c32fab2d"
},
{
"title": "commit.commit.else",
"redeemer": {
"schema": {}
},
"compiledCode": "5902ae010100323232323232323232322533300332323232325332330093001300b37540042646464a66666602800c2646464a66601e60060022a66602660246ea80245400803854ccc03cc01c00454ccc04cc048dd50048a80100700718081baa0081533300d3001300f37540042646464646464a6660266016602a6ea80344cc00cc01130103d87980003370e6660026eacc064c068c068c068c068c058dd50079bae30053016375400c91010b487964726148656164563100480044c94ccc050c020c058dd50008998021802a6103d87a8000300c333002375660346036602e6ea8c068c05cdd50009bae30063017375400e9110b4879647261486561645631001533015491054c35333b39001632533301800114c103d87a80001300333019301a0014bd701bac30053016375401e44464a66602c601c60306ea8004520001375a603860326ea8004c94ccc058c038c060dd50008a6103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301c337220100042a66603866e3c0200084c02ccc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301b337220100042a66603666e3c0200084c028cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c074004dd2a400044a666024002294454cc04c00852812999808180218091baa001149103433031001491034330320023015301630160013013301037540042a6601c9201054c34333b350016370e900000580580580598089809001180800098061baa002370e90010b1806980700118060009806001180500098031baa00114984d95854cc0092401064c34323b333100165734ae7155ceaab9e5573eae815d0aba257481",
"hash": "ea444d37d226e71eef73ac78d149750da977feb588900135bf9e8221"
"compiledCode": "5902ae010100323232323232323232322533300332323232325332330093001300b37540042646464a66666602800c2646464a66601e60060022a66602660246ea80245400803854ccc03cc01c00454ccc04cc048dd50048a80100700718081baa0081533300d3001300f37540042646464646464a6660266016602a6ea80344cc00cc01130103d87980003370e6660026eacc064c068c068c068c068c058dd50079bae30053016375400c91010b487964726148656164563100480044c94ccc050c020c058dd50008998021802a6103d87a8000300c333002375660346036602e6ea8c068c05cdd50009bae30063017375400e9110b4879647261486561645631001533015491054c35333b39001632533301800114c103d87a80001300333019301a0014bd701bac30053016375401e44464a66602c601c60306ea8004520001375a603860326ea8004c94ccc058c038c060dd50008a6103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301c337220100042a66603866e3c0200084c02ccc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301b337220100042a66603666e3c0200084c028cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c074004dd2a400044a666024002294454cc04c00852812999808180218091baa001149103433031001491034330330023015301630160013013301037540042a6601c9201054c34333b350016370e900000580580580598089809001180800098061baa002370e90010b1806980700118060009806001180500098031baa00114984d95854cc0092401064c34323b333100165734ae7155ceaab9e5573eae815d0aba257481",
"hash": "46a423187ec877f332c644bb361937bc1d50d6aa11f877a0c32fab2d"
}
],
"definitions": {
Expand Down
33 changes: 6 additions & 27 deletions hydra-plutus/test/Hydra/Plutus/GoldenSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,17 @@ import Hydra.Contract.Initial qualified as Initial
import Hydra.Version (gitDescribe)
import PlutusLedgerApi.V2 (serialiseCompiledCode)
import PlutusLedgerApi.V2 qualified as Plutus
import System.FilePath ((</>))
import System.Process (
CreateProcess (..),
StdStream (UseHandle),
createProcess,
proc,
waitForProcess,
)
import System.Process (readProcess)
import Test.Hspec.Golden (Golden (..))

spec :: Spec
spec = do
it "checks plutus blueprint remains the same" $ do
withTempDir "hydra-plutus-golden" $ \tmpDir -> do
-- FIXME: This requires a git working copy, do it differently.
-- Run 'aiken build' to re-generate plutus.json file
_ <- do
let aikenExec = proc "aiken" ["build", "-t", "compact"]
aikenProcess = aikenExec
(_, _, _, aikenProcessHandle) <- createProcess aikenProcess
waitForProcess aikenProcessHandle
-- Run 'git status' to see if plutus.json file has changed
let gitLogFilePath = tmpDir </> "logs" </> "git-processes.log"
_ <- withLogFile gitLogFilePath $ \out -> do
hSetBuffering out NoBuffering
let gitStatusExec = proc "git" ["status", "--porcelain"]
gitStatusProcess = gitStatusExec{std_out = UseHandle out, std_err = UseHandle out}
(_, _, _, gitStatusProcessHandle) <- createProcess gitStatusProcess
waitForProcess gitStatusProcessHandle
-- Read git log file and verify plutus.json did not change
gitLogContents <- decodeUtf8 <$> readFileBS gitLogFilePath
gitLogContents `shouldNotContain` "plutus.json"
original <- readFileBS "plutus.json"
-- This re-generate plutus.json
void $ readProcess "aiken" ["build", "-t", "compact"] ""
regenerated <- readFileBS "plutus.json"
regenerated `shouldBe` original

it "Commit validator script" $ do
-- FIXME: Actually test the value of commitValidatorScript
Expand Down

0 comments on commit 7bafe31

Please sign in to comment.