@@ -8,6 +8,7 @@ use aiken/transaction/value.{Value}
|
||||
pub fn count(self: List<a>, predicate: fn(a) -> Bool) -> Int {
|
||||
list.foldl(
|
||||
self,
|
||||
0,
|
||||
fn(item, total) {
|
||||
if predicate(item) {
|
||||
total + 1
|
||||
@@ -15,7 +16,6 @@ pub fn count(self: List<a>, predicate: fn(a) -> Bool) -> Int {
|
||||
total
|
||||
}
|
||||
},
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ test foldl_value_test1() {
|
||||
let foo =
|
||||
fn(i: Value, acc: (Value, Int)) {
|
||||
let (v, int) = acc
|
||||
(value.add(i, v), int + 1)
|
||||
(value.merge(i, v), int + 1)
|
||||
}
|
||||
list.foldl([val1, val2], foo, (value.zero(), 0)) == (
|
||||
list.foldl([val1, val2], (value.zero(), 0), foo) == (
|
||||
value.from_lovelace(3000000),
|
||||
2,
|
||||
)
|
||||
@@ -39,9 +39,9 @@ test foldl_value_test2() {
|
||||
let foo =
|
||||
fn(i: Value, acc: (Value, Int)) {
|
||||
let (v, int) = acc
|
||||
(value.add(i, v), int + 1)
|
||||
(value.merge(i, v), int + 1)
|
||||
}
|
||||
list.foldl([val1, val2], foo, (value.from_lovelace(0), 0)) == (
|
||||
list.foldl([val1, val2], (value.from_lovelace(0), 0), foo) == (
|
||||
value.from_lovelace(3000000),
|
||||
2,
|
||||
)
|
||||
|
||||
@@ -28,8 +28,7 @@ fn assert_purpose(purpose) {
|
||||
ref.transaction_id == TransactionId(
|
||||
#"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
) && ref.output_index == 0
|
||||
_ ->
|
||||
error @"script purpose isn't 'Spend'"
|
||||
_ -> error @"script purpose isn't 'Spend'"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +49,6 @@ fn assert_outputs(transaction) {
|
||||
output.reference_script == None,
|
||||
]
|
||||
|> list.and
|
||||
_ ->
|
||||
error @"unexpected number of outputs"
|
||||
_ -> error @"unexpected number of outputs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ validator {
|
||||
}
|
||||
|
||||
fn assert_datum(datum) {
|
||||
let my_datum: Data =
|
||||
Void
|
||||
let my_datum: Data = Void
|
||||
datum == my_datum
|
||||
}
|
||||
|
||||
@@ -27,14 +26,12 @@ type MyDatum {
|
||||
}
|
||||
|
||||
fn assert_datums(datums) {
|
||||
let my_datum =
|
||||
MyDatum(42)
|
||||
let my_datum = MyDatum(42)
|
||||
|
||||
expect Some(datum) =
|
||||
dict.get(datums, blake2b_256(builtin.serialise_data(my_datum)))
|
||||
|
||||
expect datum: MyDatum =
|
||||
datum
|
||||
expect datum: MyDatum = datum
|
||||
|
||||
my_datum == datum && dict.size(datums) == 2
|
||||
}
|
||||
@@ -43,8 +40,7 @@ fn assert_outputs(outputs) {
|
||||
when outputs is {
|
||||
[output_1, output_2, ..] ->
|
||||
assert_first_output(output_1) && assert_second_output(output_2)
|
||||
_ ->
|
||||
error @"expected transaction to have (at least) 2 outputs"
|
||||
_ -> error @"expected transaction to have (at least) 2 outputs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,10 +66,8 @@ fn assert_second_output(output) {
|
||||
),
|
||||
),
|
||||
when output.datum is {
|
||||
InlineDatum(_) ->
|
||||
True
|
||||
_ ->
|
||||
error @"expected inline datum"
|
||||
InlineDatum(_) -> True
|
||||
_ -> error @"expected inline datum"
|
||||
},
|
||||
]
|
||||
|> list.and
|
||||
|
||||
@@ -19,28 +19,22 @@ fn assert_purpose(ctx) {
|
||||
ctx.transaction.mint
|
||||
|> value.without_lovelace
|
||||
|> value.policies
|
||||
expect Mint(policy_id) =
|
||||
ctx.purpose
|
||||
expect Mint(policy_id) = ctx.purpose
|
||||
|
||||
my_policy_id == policy_id
|
||||
}
|
||||
|
||||
fn assert_mint(purpose, transaction) {
|
||||
expect Mint(policy_id) =
|
||||
purpose
|
||||
let tokens =
|
||||
value.tokens(transaction.mint, policy_id)
|
||||
expect Mint(policy_id) = purpose
|
||||
let tokens = value.tokens(transaction.mint, policy_id)
|
||||
|
||||
when dict.get(tokens, #"666f6f") is {
|
||||
None ->
|
||||
error @"token not found"
|
||||
Some(quantity) ->
|
||||
quantity == 1337
|
||||
None -> error @"token not found"
|
||||
Some(quantity) -> quantity == 1337
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_redeemers(ctx, my_redeemer) {
|
||||
expect Some(redeemer) =
|
||||
dict.get(ctx.transaction.redeemers, ctx.purpose)
|
||||
expect Some(redeemer) = dict.get(ctx.transaction.redeemers, ctx.purpose)
|
||||
my_redeemer == redeemer && dict.size(ctx.transaction.redeemers) == 1
|
||||
}
|
||||
|
||||
@@ -23,16 +23,12 @@ validator {
|
||||
|
||||
[
|
||||
when dict.get(ctx.transaction.withdrawals, alice) is {
|
||||
None ->
|
||||
error @"alice's withdrawal not found"
|
||||
Some(value) ->
|
||||
value == 42
|
||||
None -> error @"alice's withdrawal not found"
|
||||
Some(value) -> value == 42
|
||||
},
|
||||
when dict.get(ctx.transaction.withdrawals, bob) is {
|
||||
None ->
|
||||
error @"bob's withdrawal not found"
|
||||
Some(value) ->
|
||||
value == 14
|
||||
None -> error @"bob's withdrawal not found"
|
||||
Some(value) -> value == 14
|
||||
},
|
||||
dict.keys(ctx.transaction.withdrawals) == [alice, bob],
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user