diff --git a/crates/aiken-lang/src/uplc.rs b/crates/aiken-lang/src/uplc.rs index 58e48442..08adc95d 100644 --- a/crates/aiken-lang/src/uplc.rs +++ b/crates/aiken-lang/src/uplc.rs @@ -1860,7 +1860,6 @@ impl<'a> CodeGenerator<'a> { ); } } - // TODO: Check constr for assert on all cases constr @ Pattern::Constructor { .. } => { if matches!(assignment_properties.kind, AssignmentKind::Expect) && assignment_properties.value_type.is_data() @@ -2095,6 +2094,9 @@ impl<'a> CodeGenerator<'a> { let constr_name = format!("__{}_{}", constr_name, self.id_gen.next()); + let mut scope = scope; + scope.push(self.id_gen.next()); + pattern_vec.push(Air::Let { scope: scope.clone(), name: constr_name.clone(), @@ -2102,9 +2104,6 @@ impl<'a> CodeGenerator<'a> { pattern_vec.append(values); - let mut scope = scope; - scope.push(self.id_gen.next()); - pattern_vec.push(Air::AssertConstr { scope: scope.clone(), constr_index: index, diff --git a/examples/acceptance_tests/077/aiken.lock b/examples/acceptance_tests/077/aiken.lock new file mode 100644 index 00000000..0423f31b --- /dev/null +++ b/examples/acceptance_tests/077/aiken.lock @@ -0,0 +1,13 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +[[requirements]] +name = "aiken-lang/stdlib" +version = "main" +source = "github" + +[[packages]] +name = "aiken-lang/stdlib" +version = "main" +requirements = [] +source = "github" diff --git a/examples/acceptance_tests/077/aiken.toml b/examples/acceptance_tests/077/aiken.toml new file mode 100644 index 00000000..2175d45e --- /dev/null +++ b/examples/acceptance_tests/077/aiken.toml @@ -0,0 +1,7 @@ +name = "aiken-lang/acceptance_test_077" +version = "0.0.0" + +[[dependencies]] +name = 'aiken-lang/stdlib' +version = 'main' +source = 'github' diff --git a/examples/acceptance_tests/077/plutus.json b/examples/acceptance_tests/077/plutus.json new file mode 100644 index 00000000..c2d47390 --- /dev/null +++ b/examples/acceptance_tests/077/plutus.json @@ -0,0 +1,40 @@ +{ + "preamble": { + "title": "aiken-lang/acceptance_test_077", + "version": "0.0.0", + "plutusVersion": "v2" + }, + "validators": [ + { + "title": "spend.staking", + "datum": { + "title": "Unit", + "description": "The nullary constructor.", + "schema": { + "anyOf": [ + { + "dataType": "constructor", + "index": 0, + "fields": [] + } + ] + } + }, + "redeemer": { + "title": "Unit", + "description": "The nullary constructor.", + "schema": { + "anyOf": [ + { + "dataType": "constructor", + "index": 0, + "fields": [] + } + ] + } + }, + "compiledCode": "5905ab010000323232323232323232323222253330063232323232323232323232323375e6e98004dd319191919191999111919000999991111999805002001801000a5eb7bdb18001000404ccccc8888cccc02c01000c0080052f5bded8c00040020249110048810000148202a35ae41cc004004888894ccc0780104cc07ccdd81ba9003374c00497adef6c60132323232533301d3375e6600a00e00266e9520004bd7009981199bb0375200e6e9801802054ccc074cdc780380089981199bb0375200e6e9801800c4cc08ccdd81ba9001374c0046666601201200600e00c00a6eb8c07c00cdd5980f80118110029810002180080091111299980e00209980e99bb037520066ea00092f5bded8c0264646464a66603666ebccc01401c004cdd2a400097ae0133021337606ea401cdd40030040a99980d99b8f007001133021337606ea401cdd400300189981099bb037520026ea0008ccccc02402400c01c018014dd7180e8019bad301d0023020005301e0043232333001375866018601a66018601a01c90002400044a66602a66ebccc038c03ccc038c03c0092002480000144c8c8c8c8c8c8c8c8cc88c8004cccc8888cccc02c01000c008004008004888c94ccc08cc94ccc0a40045288a5000113374a900125eb804cdd2a4000660526e980052f5c066664444666601400800600400200400244464a66604c66e1c005200013374a900125eb804cdd2a4000660586ea00052f5c066e0000800406805cdd59980b180b9980b180b8052400490010049800800911112999812802080189919191919999804804801999998050038008010030028030029bae3026003375a604c004605200a604e0086002002444444a66604800a26604a66ec0dd48021ba80034bd6f7b630099191919299981199baf330050080013374a900025eb804cc0a4cdd81ba9008375000e0122a66604666e3c0200044c8c94ccc094cdc3800a4000264646605a66ec0dd48061ba8001007375a605a002603e004200a604e6ea8004ccc01802001c0084cc0a4cdd81ba9001375000466666601401400601000e00c00a6eb8c09400cdd69812801181400318130029800800911112999810802080189919191919999804804801999998050038008010030028030029bae302200337566044004604a00a60460086002002444444a66604000a26604266ec0dd48021ba60034bd6f7b630099191919299980f99baf330050080013374a900025eb804cc094cdd81ba9008374c00e0122a66603e66e3c0200044c8c94ccc084cdc3800a4000264646605266ec0dd48061ba6001007375660520026036004200a60466ea8004ccc01802001c0084cc094cdd81ba9001374c00466666601401400601000e00c00a6eb8c08400cdd59810801181200318110028800a5eb7bdb180c00400488894ccc06800c40044c8c8cc010008cccc01801800401000cc078010c07000ccc024c02800520003016001301600130070013013001300532533300c3370e900018079baa0011001153300e4912a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e001632323300137586600c600e6600c600e010900024000466ebccc01cc02000520000043001001222533301300213374a900125eb804c8c94ccc040c00c0084cdd2a40006602c00497ae01333005005001003301700330150023011001300332533300a3370e900118069baa0011001153300c4912a4578706563746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e001633002300300448008894ccc028cdc8001000899ba5480012f5c02a66601466e3c0080044cdd2a400497ae013374a900225eb8088c8ccc0040052000003222333300c3370e008004026466600800866e0000d200230150010012300b37540022930b180080091129998048010a4c26600a600260160046660060066018004002ae695cdab9c5573aaae7955cfaba05742ae89", + "hash": "260e1cb890a9bc9dac6cb2d843cc8093b4f4ad81c11455ae6411dd8f" + } + ] +} \ No newline at end of file diff --git a/examples/acceptance_tests/077/validators/spend.ak b/examples/acceptance_tests/077/validators/spend.ak new file mode 100644 index 00000000..f0bad528 --- /dev/null +++ b/examples/acceptance_tests/077/validators/spend.ak @@ -0,0 +1,41 @@ +use aiken/list.{find, foldr} +use aiken/transaction.{Input, ScriptContext, Spend} +use aiken/transaction/value.{add, zero} + +validator staking { + fn(_datum: Void, _redeemer: Void, context: ScriptContext) -> Bool { + expect Spend(ref) = context.purpose + + expect Some(i) = + find(context.transaction.inputs, fn(x) { x.output_reference == ref }) + let Input { output, .. } = i + let staking_addr = output.address + + let v_in = + foldr( + context.transaction.inputs, + fn(x, y) { + if x.output.address == staking_addr { + add(x.output.value, y) + } else { + y + } + }, + zero(), + ) + + let v_out = + foldr( + context.transaction.outputs, + fn(x, y) { + if x.address == staking_addr { + add(x.value, y) + } else { + y + } + }, + zero(), + ) + v_in == v_out + } +}