-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |