Commit Graph

2227 Commits

Author SHA1 Message Date
KtorZ
cd0a9440e8 Allow any expression as constants
This is only a start. It compiles, but with a few TODOs left open. In particular, it doesn't currently handle constants depending on other constants or functions; nor does it hoist constants.
2024-08-29 16:24:12 +02:00
KtorZ
79cf0b8d97 Fix test_framework tests trying to implement function on foreign type. 2024-08-29 13:49:09 +02:00
KtorZ
c21466831c Bump versions to 1.1.0, in anticipation. 2024-08-29 09:12:37 +02:00
KtorZ
e31c6de04e Adjust module organization to facilitate resurrection of the playground.
The playground doesn't / cannot depend on aiken-project because that becomes a gigantic pain. So instead, we try to keep essential stuff inside aiken-lang when possible.
2024-08-29 09:12:37 +02:00
KtorZ
745f14ccb2 Adjust doc to support blockquote alerts. 2024-08-28 15:28:49 +02:00
rvcas
d337e601cb chore: add a test for by name with params 2024-08-27 18:10:46 -04:00
KtorZ
efeda9a998 Prevent non-default fallback on exhaustive validator
Technically, we always need a fallback just because the way the UPLC
  is going to work. The last case in the handler pattern matching is
  always going to be else ...

  We could optimize that away and when the validator is exhaustive, make
  the last handler the fallback. Yet, it's really a micro optimization
  that saves us one extra if/else. So the sake of getting things
  working, we always assume that there's a fallback but, with the extra
  condition that when the validator is exhaustive (i.e. there's a
  handler covering all purposes), the fallback HAS TO BE the default
  fallback (i.e. (_) => fail).

  This allows us to gracefully format it out, and also raise an error in
  case where there's an extraneous custom fallback.
2024-08-27 20:16:45 +02:00
KtorZ
d615b4f889 Fix incongruous panic when annotation is missing from Datum.
It's fine for the argument to not be annotated; in which case we
  simply default back to an `Option<Data>`.
2024-08-27 18:55:18 +02:00
KtorZ
4003343444 Fix default annotation for spend's optional datum and mint argument.
When there's no type annotation in a validator handler signature, we
  provide default annotation to help the type-checker. However, for
  spend's datum and mint policy_id, those annotations mustn't be `Data`,
  but rather Option<Data> and Bytearray.

  Without that, when no annotation are provided, the compiler infer
  invalid types and fails with incongruous errors.
2024-08-27 18:42:10 +02:00
KtorZ
0510ca58f7 Implement record access syntax for validator handlers.
This is a little trick which detects record access and replace them
  with a simple var. The var itself is the validator handler name,
  though since it contains dots, it cannot be referred to by users
  explicitly. Yet fundamentally, it is semantically equivalent to just
  calling the function by its name.

  Note that this commit also removes the weird backdoor for allowing
  importing validators in modules starting with `tests`. Allowing
  validators handler to be used in importable module requires more work
  and is arguably useful; so we will wait until someone complain and
  reconsider the proper way to do it.
2024-08-27 17:16:15 +02:00
KtorZ
ee8f608c0b Omit validator return annotation when formatting
Unless it is NOT bool as it deviates from the default and while wrong, we want to preserve it to provide a good error.
2024-08-27 14:53:07 +02:00
KtorZ
d74e36d0bc Introduce 'Never' type as a safe alternative to always None options
Unfortunately, as documented in:

  https://github.com/IntersectMBO/cardano-ledger/issues/4571

  Some Option fields in the script context certificates are going to
  remain set to None, at least until the next Hard fork. There's a risk
  that people permanently lock their funds if they expect deposits on
  registration credentials to ever be `Some`.

  So, we introduce a special type that emulate an `Option` that can only
  ever be `None`. We call it `Never` and it is the first type of this
  kind (i.e. with constructors indexes not starting at 0).
2024-08-27 14:40:39 +02:00
KtorZ
af9a785d65 Provide default annotation to validators (incl. fallback)
Without that, we may encounter weird error messages when writing
  validators without an explicit `else`. Since we automatically fill it
  with a `fail`; without annotation, it unifies to a generic parameter.

  The existing check that would look for the body being an error term is
  ill-advised as it doesn't work as soon as one adds tracing, or make
  the validator a parameterized validator. Plus, it may simply trigger
  the wrong behavior as one can now annotate a validator with _whatever_
  and get pass the type-checker by plucking a `fail` keyword as body.
2024-08-25 17:12:11 +02:00
KtorZ
0c9ea196be Format uplc crate 2024-08-25 16:20:45 +02:00
KtorZ
e9edd20c21 Fix gen_uplc tests revolving around validators.
Fucking hell.

  I got rid of the 'opaque_value_in_datum' test since it is no longer
  relevant (we now forbid the presence of opaque types in the ABI).
2024-08-25 16:20:09 +02:00
KtorZ
52a39629b7 Add UPLC test for always_true mint validator.
Mainly to have a trivial example with just the validator boilerplate code.
2024-08-25 16:20:08 +02:00
KtorZ
8c2fdf9ad4 Use dot to separate purpose from validator name in blueprint
The rationale is two folds:

  1. It's more consistent with how we already separate the validator
  name from its module.

  2. Because `_` may be present in Aiken's validator's name, it is hard
     to read and I am afraid it could potentially conflict later on. So
     it's better to use a separator that cannot appear in validator
     names.
2024-08-25 16:20:08 +02:00
KtorZ
ed55f03aa2 Fix remaining blueprint test.
Probably an oversight when we reworked them.
2024-08-25 16:20:08 +02:00
KtorZ
442010d056 Fix generation of fallback validator
This must only happen in case all other validator succeed; otherwise
  we might generate invalid validators.
2024-08-25 16:20:08 +02:00
rvcas
73522296aa chore: accept updated snapshot 2024-08-25 16:20:08 +02:00
rvcas
ff1464b462 feat: annotated data for option datum 2024-08-25 16:20:08 +02:00
rvcas
d8723c5497 feat: use __fallback in bluprint for the else 2024-08-25 16:20:07 +02:00
rvcas
4589c51cd3 feat: enforcement that spend first arg is option 2024-08-25 16:20:07 +02:00
rvcas
c57009bf99 chore: fix some tests that now correctly fail due to arity checks 2024-08-25 16:20:07 +02:00
KtorZ
c706d6072d Fix few blueprint generation tests
Some remains invalid, in particular:

  - We need to handle the annotated Data case, which we still parse
    correctly but do nothing about any longer.

  - There's also a strange behavior with opaque type turned public?
2024-08-25 16:20:07 +02:00
KtorZ
f9acbd3bcb DRY handlers generation from validator 2024-08-25 16:20:07 +02:00
KtorZ
6a6bf6f65f Handle (though discard) first script purpose argument of publish and propose. 2024-08-25 16:20:07 +02:00
KtorZ
5943d94c6c Finish re-working machine errors display. 2024-08-25 16:20:06 +02:00
KtorZ
fe205e360f Update remaining script context e2e tests. 2024-08-25 16:20:06 +02:00
KtorZ
7ec3f2e8df DRY builtins types creation to ensure proper consistency. 2024-08-25 16:20:06 +02:00
rvcas
5b61a75088 feat: handler withdraw purpose 2024-08-25 16:20:06 +02:00
microproofs
f86d550ca0 Fix type for mint scriptinfo 2024-08-25 16:20:06 +02:00
microproofs
953ee6b5d1 Fix ordering for ScriptInfo type 2024-08-25 16:20:05 +02:00
rvcas
b9456b5946 fix: wrap_validator_condition needs to happen earlier 2024-08-25 16:20:05 +02:00
rvcas
e174532bfd chore: add more redacted values to machine errors 2024-08-25 16:20:05 +02:00
rvcas
79099675d4 fix: free unique on purpose arg 2024-08-25 16:20:05 +02:00
rvcas
c2c4bddfb3 feat: new check for valid purpose names 2024-08-25 16:20:05 +02:00
KtorZ
5cf0a4d294 Fix validator arity check
For now, this panics, but ideally, we should return a "unknown
  purpose" error when we cannot map the name to an arity.
2024-08-25 16:20:04 +02:00
KtorZ
823492c27b Adjust v3 script context end-to-end tests to work with new syntax. 2024-08-25 16:20:04 +02:00
KtorZ
972e9bd763 Define ScriptPurpose & ScriptContext types in prelude, fix codegen new v3 wrapper. 2024-08-25 16:20:04 +02:00
rvcas
90d75d4a13 fix: redeemer could be missing 2024-08-25 16:20:04 +02:00
rvcas
00b8a39236 fix: private type leaks 2024-08-25 16:20:04 +02:00
rvcas
79840248c0 fix: more parse errors in some tests 2024-08-25 16:20:04 +02:00
rvcas
f94e40daf4 fix: more test and issues with scoping/names 2024-08-25 16:20:03 +02:00
rvcas
cf3180996a fix: map fallback name if present to else 2024-08-25 16:20:03 +02:00
rvcas
00907c2bcc fix: format snapshot tests 2024-08-25 16:20:03 +02:00
rvcas
7f26db401c feat: handler implicit some and none 2024-08-25 16:20:03 +02:00
rvcas
6b8be61b6e test: new snapshots for parsing v3 validators 2024-08-25 16:20:03 +02:00
rvcas
0d8d80e5a7 feat: transform TypedValidator in a function of handlers 2024-08-25 16:20:03 +02:00
rvcas
466a4f0b39 feat: adjust blueprint stuff to be aware of handlers 2024-08-25 16:20:02 +02:00