Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iostat committed Sep 8, 2023
1 parent 56f401b commit f227f0d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let conf = ./spago.dhall

in conf
// { sources = conf.sources # [ "test/**/*.purs" ]
, dependencies = conf.dependencies # [ "spec", "datetime" ]
}
80 changes: 80 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module Test.Main where

import Prelude

import Data.Time.Duration (Milliseconds(..))
import Data.Either (Either(..), isRight)
import Data.Maybe (Maybe(..), fromMaybe, isJust)
import Data.String (Pattern(..), stripPrefix)
import Data.Traversable (for_)
import Effect (Effect)
import Effect.Aff (error, launchAff_, throwError)
import Test.Spec (describe, it, parallel)
import Test.Spec.Assertions (shouldSatisfy)
import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (defaultConfig, runSpec')

import Language.Solidity.Compiler as Compiler
import Language.Solidity.Compiler.Releases as Releases

knownCompilers :: Array { version :: String, remote :: String }
knownCompilers =
[ { version: "0.4.26"
, remote: "v0.4.26+commit.4563c3fc"
}
, { version: "0.5.17"
, remote: "v0.5.17+commit.d19bba13"
}
, { version: "0.6.12"
, remote: "v0.6.12+commit.27d51765"
}
, { version: "0.7.6"
, remote: "v0.7.6+commit.7338295f"
}
, { version: "0.8.21"
, remote: "v0.8.21+commit.d9974bed"
}
]

compilerVersionMatches :: String -> String -> Boolean
compilerVersionMatches remote compiler = pred
where
cleanup s = fromMaybe s $ stripPrefix (Pattern "v") s
cleanedCompiler = cleanup compiler
cleanedRemote = cleanup remote
pred = isJust $ stripPrefix (Pattern cleanedRemote) cleanedCompiler

main :: Effect Unit
main = do
let cfg = defaultConfig { timeout = Just (Milliseconds $ 120.0 * 1000.0) }
launchAff_ $ runSpec' cfg [ consoleReporter ] do
parallel $ describe "Releases" do
it "can fetch the release list from the default repo" do
rl <- Releases.getReleaseList Releases.defaultReleaseRepo
rl `shouldSatisfy` isRight

it "can fetch the latest release from the default repo" do
source <- Releases.getReleaseSource Releases.defaultReleaseRepo "latest"
source `shouldSatisfy` isRight

parallel $ describe "Compiler" do
it ("can read the version of the default compiler: " <> Compiler.version Compiler.defaultCompiler) do
-- nb: this just shouldn't throw...
pure unit

parallel $ describe "Known versioned releases" do
for_ knownCompilers $ \{ version, remote } -> do
describe version do
it "can fetch the compiler" do
source <- Releases.getReleaseSource Releases.defaultReleaseRepo version
source `shouldSatisfy` isRight

it "can use loadRemoteVersion" do
void $ Compiler.loadRemoteVersion remote

it "can use the fetched compiler" do
Releases.getReleaseSource Releases.defaultReleaseRepo version >>= case _ of
Left err -> throwError $ error err
Right source -> do
compiler <- Compiler.useCompiler source
Compiler.version compiler `shouldSatisfy` (compilerVersionMatches remote)

0 comments on commit f227f0d

Please sign in to comment.