1. 27 Oct, 2021 2 commits
    • Sandeep.C.R's avatar
      Merge branch 'sras/#668-pure-init-env-tests' into 'master' · 84c31518
      Sandeep.C.R authored
      [#668] Add callback to modify 'PureState' in `clevelandTestProp` tests.
      
      See merge request !963
      84c31518
    • Sandeep.C.R's avatar
      [#668] Add functions to set some initial states · acf66d11
      Sandeep.C.R authored
      Problem: We have to add a way to configure the initial environment when
      running property tests using `clevelandTestProp`.
      
      Solution: Add two function `withInitialNow` and `withInitialLevel` that
      allows setting corresponding fields in the initial state. These
      functions operate via a new typeclass `withModifiedInitialState` so that
      these can be used with different types of tests. For the timebeing we
      have artificially restricted the use of these functions to restrict
      their use to the begining of a scenario.
      acf66d11
  2. 26 Oct, 2021 12 commits
    • Alyona Antonova's avatar
      Merge branch 'alyoanton9/#423-make-fromIntegral-safe' into 'master' · 2f08ad3b
      Alyona Antonova authored
      [#423] Make `fromIntegral` safe
      
      Closes #423
      
      See merge request !936
      2f08ad3b
    • Alyona Antonova's avatar
      [#423] Add overflow check to `fromInteger` · 3584852e
      Alyona Antonova authored
      Problem: `fromInteger` has the same issues
      with safety as `fromIntegral` does. However,
      we don't want to duplicate all the converters
      since `fromInteger` is `Integral` after all.
      We also don't want to export new `fromInteger`
      from `Unsafe` as it leads to importing `Unsafe`
      or defining `fromInteger` in every module
      at the dependent project `indigo`, because
      `RebindableSyntax` is used here.
      
      Solution: Define `fromInteger = Unsafe.fromIntegral @integer`,
      which fails on overflow/underflow, in `Prelude`.
      Add `{-# LANGUAGE NoImplicitPrelude #-}` to avoid
      cyclic imports. Import qualified `GHC.Num` to define
      `instance Num`, which requires the original `fromInteger`
      where it's needed.
      3584852e
    • Alyona Antonova's avatar
      [Chore] Add `dqoutes` to `Morley.Util.Text` · a8d56964
      Alyona Antonova authored
      Problem: We have several use-cases where
      we surround string-like expression with
      double quotes, but we don't have a single
      utility for this and usually create new
      functions, visible in local scope only.
      
      Solution: Add utility `dquotes` to
      `Morley.Util.Text` and use it where
      possible.
      a8d56964
    • Alyona Antonova's avatar
      [#423] Add overflow check to `fromIntegral` · a5635c30
      Alyona Antonova authored
      Problem: Unsafe `fromIntegral` doesn't check
      for overflow/underflow and may, for example,
      silently narrow `Integer` down to `Int` without
      testing argument for max bound of `Int`. We
      want to get rid of these unsafe usages and
      be sure our usages are runtime-safe.
      
      Solution: Firstly, add `Unsafe.fromIntegralNoOverflow`
      function to wrap the conversion result in `Either`.
      Then make `Unsafe.fromIntegral` to use the former
      and fail if overflow/underflow happens. Make
      `Unsafe.fromIntegral` require `Integral` instance
      as we want this function to convert between
      `Integral` types only (we have `fromIntegralToRealFrac`
      for fractional ones). Add related changes.
      a5635c30
    • Alyona Antonova's avatar
      [#423] Add `fromIntegralOverflowing` to morley-prelude · 57ccb860
      Alyona Antonova authored
      Problem: Sometimes convertion between `Integral`
      types intend overflow. We need to semantically
      distinguish it from those usages which have to
      fail on overflow.
      
      Solution: Add `fromIntegralOverflowing` function
      to `Prelude` module. Replace related usages of
      `Unsafe.fromIntegral` with `fromIntegralOverflowing`.
      57ccb860
    • Alyona Antonova's avatar
      [#423] Add `fromIntegralToRealFrac` to morley-prelude · d38e7b67
      Alyona Antonova authored
      Problem: Sometimes we cast integral number
      to fractional one. Basically, it is a safe
      conversion, but we are using `Unsafe.fromIntegral`
      currently as safe `fromIntegral` requires
      `Integral` types.
      
      Solution: Add safe `fromIntegralToRealFrac`
      function, that casts `Integral` type to
      `RealFrac`, to `Prelude` module. Replace
      some "integral-to-fractional" convertions
      with it.
      d38e7b67
    • Alyona Antonova's avatar
      [#423] Replace `unsafeMkMutez` with `toMutez` where possible · 5c3b411d
      Alyona Antonova authored
      Problem: There are a lot of `unsafeMkMutez` use-cases
      which are not necessary, mostly creating `Mutez` from
      the constant value. They have to be replaced with
      statically-safe `toMutez` which was intended to use
      for creating `Mutez` from numeric literals.
      
      Solution: Replace `unsafeMkMutez` with `toMutez`
      where it's possible.
      5c3b411d
    • Alyona Antonova's avatar
      [#423] Replace `fromIntegralChecked` with `fromIntegralMaybe` · 290a9d9a
      Alyona Antonova authored
      Problem: `fromIntegralChecked` might be unsafe as it
      uses `Unsafe.fromIntegral`. For example,
      `fromIntegralChecked @integer @natural -1`.
      
      Solution: Replace it with statically safe
      `fromIntegralMaybe` everywhere.
      290a9d9a
    • Alyona Antonova's avatar
      [#423] Merge `mkMutez` and `mkMutez'` in a single function · 34158414
      Alyona Antonova authored
      Problem: We have two similar functions for creating
      `Mutez` safely - `mkMutez` and `mkMutez'`. In fact,
      their difference is the type of returning data type.
      
      Solution: Merge them in a single function - `mkMutez`
      that does all the needed checks and report a proper
      error.
      34158414
    • Alyona Antonova's avatar
      [#423] Distinguish statically safe and unsafe `fromIntegral` usages · c184698c
      Alyona Antonova authored
      Problem: `fromIntegral` function is dangerous and
      may produce hard-to-find bugs. We can't get rid of it,
      but can prevent unsafe usages to some extent. In general,
      all usages could be divided into three groups:
      1. Statically safe: `fromIntegral @Int64 @integer minBound`
      2. Safe at runtime: `fromIntegral @natural @Word8) $ x `divMod` 0x100`
      3. May be safe or unsafe at runtime: `fromIntegral @Word64 @Int64 . unMutez`
      
      Solution: Firstly, hide `fromIntegral` from the import
      of `Universum` in `morley-prelude`'s `Prelude` module.
      Secondly, add a re-export of this `fromIntegral` from
      `Universum.Base`, into `morley-prelude`'s `Unsafe` module.
      Then add `int-cast` as a dependency of `morley-prelude`
      and re-export `intCast` as `fromIntegral`
      from `morley-prelude`'s `Prelude` module. Finally, re-export
      `intCastMaybe` from that same package as `fromIntegralMaybe`
      from `Prelude` as well. Thus, unqualified `fromIntegral`
      is always statically safe (see p.1. at `Problem` paragraph);
      `Unsafe.fromIntegral` is commonly used for safe at runtime
      cases (p.2.) or for making another unsafe function (p.3.);
      `fromIntegralMaybe` is used when it's needed to handle
      conversion explicitly (p.3.). Additionally, add type
      annotations to `Unsafe.fromIntegral` use-cases.
      c184698c
    • Nikolay Yakimov's avatar
      Merge branch 'lierdakil/#673-clarify-errors' into 'master' · 18f27e9f
      Nikolay Yakimov authored
      [#673] Add a way to clarify custom cleveland errors
      
      Closes #673
      
      See merge request !979
      18f27e9f
    • Nikolay Yakimov's avatar
      [#673] Add a way to clarify custom cleveland errors · 8e290e85
      Nikolay Yakimov authored
      Problem: A function adding some prefix to 'CustomTestError' text can
      be very useful for clarifying where the test fails.
      
      Solution: add 'cmiThrow' to rethrow arbitrary exceptions from
      'MonadCleveland'. Add 'clarifyErrors' helper that wraps
      some action and adds a given prefix to 'CustomTestError's that are
      generated by said action.
      8e290e85
  3. 25 Oct, 2021 9 commits
  4. 23 Oct, 2021 3 commits
    • Konstantin Ivanov's avatar
      Merge branch 'martoon/#650-no-timed-based-level-test' into 'master' · f2c9ec70
      Konstantin Ivanov authored
      [#650] Weaken time-based tests
      
      Closes #650
      
      See merge request !920
      f2c9ec70
    • Konstantin Ivanov's avatar
      [#650] Make tests on `getLevel` more flexible · 44c1108b
      Konstantin Ivanov authored
      Problem: currently CI sometimes fail, this happens because tests assume
      no block baking to occur exactly according to the schedule. However, in
      real life, the test suite may arbitrarily linger and skip many published
      block, so we have to weaken these tests.
      
      Solution: in case of run against network, allow the second `getLevel`
      call to return some larger value than expected.
      44c1108b
    • Konstantin Ivanov's avatar
      [#650] Add `getRunMode` to nettest · 2f1a705d
      Konstantin Ivanov authored
      Problem: we want to run some test scenarios both on chain and in
      emulation and have a way to check within the scenario, which exactly
      framework is currently used.
      
      This affects the test logic, e.g. whether do we want to use `getStorage`
      or `getFullStorage`.
      
      Solution: add `getRunMode` function that provides access to this
      information. Thanks to the implementation of `caps`, we can even enable
      emulation-only actions when appear to be executed in Morley emulation.
      2f1a705d
  5. 22 Oct, 2021 3 commits
    • Nikolay Yakimov's avatar
      Merge branch 'lierdakil/#542-exponential-backtracking' into 'master' · a5dbf38b
      Nikolay Yakimov authored
      [#542] Fix exponential backtracking when parsing tuples
      
      Closes #542
      
      See merge request !971
      a5dbf38b
    • Nikolay Yakimov's avatar
      [Chore] Update changelog · af45bbb2
      Nikolay Yakimov authored
      af45bbb2
    • Nikolay Yakimov's avatar
      [#542] Exponential backtracking when parsing tuples · e672fef9
      Nikolay Yakimov authored
      Problem: Consider the following input string:
      (Pair 1 (Pair 2 (Pair 3 (Pair 4 5))))
      until we've parsed it completely, we can't decide whether the first
      opening parenthesis is starting a tuple, or a simple expression.
      The same applies to all subsequent parentheses. The current parser
      first tries to parse the whole expression as a tuple, then backtracks,
      then tries to parse the same expression as a value (which includes
      a tuple). Hence the exponential backtracking.
      Additionally, when parsing 'Pair', a similar (but different)
      backtracking issue manifests in 'tupleInner'.
      
      Solution: First try to parse anything that starts with '(', i.e.
      a comma-separated tuple, or a plain value in parentheses. The choice
      between the two is trivial: if there's one value it's just value, if
      there are multiple, it's a tuple.
      
      If we don't find '(' we then try to parse anything that /doesn't/ start
      with a parenthesis, i.e. everything else.
      e672fef9
  6. 21 Oct, 2021 1 commit
  7. 20 Oct, 2021 1 commit
    • Nikolay Yakimov's avatar
      [#644] Sort out Alias/AliasHint confusion · f6465b91
      Nikolay Yakimov authored
      Problem: in 'Test.Cleveland.Internal.Client.runNetworkScenario' we're
      implicitly coercing 'Alias' to 'AliasHint', which is generally is an
      invalid operation.
      
      Solution: Hide 'Alias' and 'AliasHint' data constructors. Export instead
      a number of utility functions, most of which are marked as 'unsafe':
      'unsafeCoerceAliasHintToAlias', 'unsafeCoerceAliasToAliasHint',
      'unsafeGetAliasText', 'unsafeGetAliasHintText', 'mkAlias',
      'mkAliasHint'.
      
      This at least makes it harder to do this again. Only export 'mkAlias'
      and 'mkAliasHint' from "Morley.Client", the rest need to be imported
      explicitly from "Morley.Client.TezosClient.Types"
      
      Furthermore, add a type 'AliasOrAliasHint' = 'Alias' | 'AliasHint', and
      use that for tezos-client API instead of plain 'AliasHint'. This lets us
      safely use plain 'Alias' with tezos-client when we need to. The rest of
      the morley-client API, e.g. 'OriginationData', continue using
      'AliasHint'.
      
      Finally, fix 'runNetworkScenario' to pass 'Alias' to tezos-client.
      f6465b91
  8. 19 Oct, 2021 2 commits
  9. 18 Oct, 2021 2 commits
    • Nikolay Yakimov's avatar
      Merge branch 'lierdakil/#674-fixup-stylish' into 'master' · 475e59c4
      Nikolay Yakimov authored
      [#674] Add automatic stylish fixup
      
      Closes #674
      
      See merge request !976
      475e59c4
    • Nikolay Yakimov's avatar
      [#674] Add automatic stylish fixup · 4d9b1d44
      Nikolay Yakimov authored
      Problem: It's often the case that some commits get pushed which
      accidentally don't respect our style guide, most often regarding the
      ordering of imports. A good portion of these accidents could be
      prevented by running stylish haskell (e.g. via make stylish)
      
      Solution: Add a step to CI that runs `make stylish` on merge requests,
      checks if any files changed and pushes a fixup commit on the source
      branch.
      4d9b1d44
  10. 14 Oct, 2021 2 commits
  11. 13 Oct, 2021 3 commits