Re-format and re-run all acceptance tests.
This commit is contained in:
parent
9ee2d58ba3
commit
b50e4ab63a
|
@ -1,9 +1,7 @@
|
||||||
pub fn length(xs: List<a>) -> Int {
|
pub fn length(xs: List<a>) -> Int {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] -> 0
|
||||||
0
|
[_, ..rest] -> 1 + length(rest)
|
||||||
[_, ..rest] ->
|
|
||||||
1 + length(rest)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] -> zero
|
||||||
zero
|
[x, ..rest] -> f(x, foldr(rest, f, zero))
|
||||||
[x, ..rest] ->
|
|
||||||
f(x, foldr(rest, f, zero))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] -> zero
|
||||||
zero
|
[x, ..rest] -> f(x, foldr(rest, f, zero))
|
||||||
[x, ..rest] ->
|
|
||||||
f(x, foldr(rest, f, zero))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,4 +10,3 @@ test bar() {
|
||||||
False
|
False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ pub fn unzip(xs: List<(a, b)>) -> (List<a>, List<b>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
test unzip1() {
|
test unzip1() {
|
||||||
let x = [(3, #"55"), (4, #"7799")]
|
let x =
|
||||||
|
[(3, #"55"), (4, #"7799")]
|
||||||
|
|
||||||
unzip(x) == ([3, 4], [#"55", #"7799"])
|
unzip(x) == ([3, 4], [#"55", #"7799"])
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn map(opt: Option<a>, f: fn(a) -> b) -> Option<b> {
|
pub fn map(opt: Option<a>, f: fn(a) -> b) -> Option<b> {
|
||||||
when opt is {
|
when opt is {
|
||||||
None ->
|
None -> None
|
||||||
None
|
Some(a) -> Some(f(a))
|
||||||
Some(a) ->
|
|
||||||
Some(f(a))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
pub fn unzip(xs: List<(a, b)>) -> (List<a>, List<b>) {
|
pub fn unzip(xs: List<(a, b)>) -> (List<a>, List<b>) {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] -> ([], [])
|
||||||
([], [])
|
|
||||||
[(a, b), ..rest] -> {
|
[(a, b), ..rest] -> {
|
||||||
let (a_tail, b_tail) =
|
let (a_tail, b_tail) = unzip(rest)
|
||||||
unzip(rest)
|
|
||||||
([a, ..a_tail], [b, ..b_tail])
|
([a, ..a_tail], [b, ..b_tail])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ pub fn drop(bytes: ByteArray, n: Int) -> ByteArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
test drop_1() {
|
test drop_1() {
|
||||||
let x =
|
let x = #"01020304050607"
|
||||||
#"01020304050607"
|
|
||||||
drop(x, 2) == #"0304050607"
|
drop(x, 2) == #"0304050607"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn or_else(opt: Option<a>, default: a) -> a {
|
pub fn or_else(opt: Option<a>, default: a) -> a {
|
||||||
when opt is {
|
when opt is {
|
||||||
None ->
|
None -> default
|
||||||
default
|
Some(a) -> a
|
||||||
Some(a) ->
|
|
||||||
a
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn map(opt: Option<a>, f: fn(a) -> result) -> Option<result> {
|
pub fn map(opt: Option<a>, f: fn(a) -> result) -> Option<result> {
|
||||||
when opt is {
|
when opt is {
|
||||||
None ->
|
None -> None
|
||||||
None
|
Some(a) -> Some(f(a))
|
||||||
Some(a) ->
|
|
||||||
Some(f(a))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn map(opt: Option<a>, f: fn(a) -> result) -> Option<result> {
|
pub fn map(opt: Option<a>, f: fn(a) -> result) -> Option<result> {
|
||||||
when opt is {
|
when opt is {
|
||||||
None ->
|
None -> None
|
||||||
None
|
Some(a) -> Some(f(a))
|
||||||
Some(a) ->
|
|
||||||
Some(f(a))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] -> zero
|
||||||
zero
|
[x, ..rest] -> f(x, foldr(rest, f, zero))
|
||||||
[x, ..rest] ->
|
|
||||||
f(x, foldr(rest, f, zero))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +10,7 @@ pub fn filter_map(xs: List<a>, f: fn(a) -> Option<b>) -> List<b> {
|
||||||
xs,
|
xs,
|
||||||
fn(x, ys) {
|
fn(x, ys) {
|
||||||
when f(x) is {
|
when f(x) is {
|
||||||
None ->
|
None -> ys
|
||||||
ys
|
|
||||||
Some(y) ->
|
Some(y) ->
|
||||||
[y, ..ys]
|
[y, ..ys]
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,11 @@ pub fn map2(
|
||||||
f: fn(a, b) -> result,
|
f: fn(a, b) -> result,
|
||||||
) -> Option<result> {
|
) -> Option<result> {
|
||||||
when opt_a is {
|
when opt_a is {
|
||||||
None ->
|
None -> None
|
||||||
None
|
|
||||||
Some(a) ->
|
Some(a) ->
|
||||||
when opt_b is {
|
when opt_b is {
|
||||||
None ->
|
None -> None
|
||||||
None
|
Some(b) -> Some(f(a, b))
|
||||||
Some(b) ->
|
|
||||||
Some(f(a, b))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] -> zero
|
||||||
zero
|
[x, ..rest] -> f(x, foldr(rest, f, zero))
|
||||||
[x, ..rest] ->
|
|
||||||
f(x, foldr(rest, f, zero))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +13,7 @@ pub fn flat_map(xs: List<a>, f: fn(a) -> List<b>) -> List<b> {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] ->
|
||||||
[]
|
[]
|
||||||
[x, ..rest] ->
|
[x, ..rest] -> concat(f(x), flat_map(rest, f))
|
||||||
concat(f(x), flat_map(rest, f))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,7 @@ fn do_from_list(xs: List<(key, value)>) -> List<(key, value)> {
|
||||||
when xs is {
|
when xs is {
|
||||||
[] ->
|
[] ->
|
||||||
[]
|
[]
|
||||||
[(k, v), ..rest] ->
|
[(k, v), ..rest] -> do_insert(do_from_list(rest), k, v)
|
||||||
do_insert(do_from_list(rest), k, v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +51,8 @@ fn do_union(
|
||||||
right: List<(key, value)>,
|
right: List<(key, value)>,
|
||||||
) -> List<(key, value)> {
|
) -> List<(key, value)> {
|
||||||
when left is {
|
when left is {
|
||||||
[] ->
|
[] -> right
|
||||||
right
|
[(k, v), ..rest] -> do_union(rest, do_insert(right, k, v))
|
||||||
[(k, v), ..rest] ->
|
|
||||||
do_union(rest, do_insert(right, k, v))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
test tuple_1() {
|
test tuple_1() {
|
||||||
let coordinates =
|
let coordinates = (14, 42)
|
||||||
(14, 42)
|
|
||||||
coordinates.1st == 14 && coordinates.2nd == 42
|
coordinates.1st == 14 && coordinates.2nd == 42
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn foldr(self: List<a>, with: fn(a, b) -> b, zero: b) -> b {
|
pub fn foldr(self: List<a>, with: fn(a, b) -> b, zero: b) -> b {
|
||||||
when self is {
|
when self is {
|
||||||
[] ->
|
[] -> zero
|
||||||
zero
|
[x, ..xs] -> with(x, foldr(xs, with, zero))
|
||||||
[x, ..xs] ->
|
|
||||||
with(x, foldr(xs, with, zero))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,7 @@ fn do_union_with(
|
||||||
with: fn(ByteArray, value, value) -> Option<value>,
|
with: fn(ByteArray, value, value) -> Option<value>,
|
||||||
) -> List<(ByteArray, value)> {
|
) -> List<(ByteArray, value)> {
|
||||||
when left is {
|
when left is {
|
||||||
[] ->
|
[] -> right
|
||||||
right
|
|
||||||
[(k, v), ..rest] ->
|
[(k, v), ..rest] ->
|
||||||
do_union_with(rest, do_insert_with(right, k, v, with), with)
|
do_union_with(rest, do_insert_with(right, k, v, with), with)
|
||||||
}
|
}
|
||||||
|
@ -58,8 +57,7 @@ fn do_insert_with(
|
||||||
when with(k, v, v2) is {
|
when with(k, v, v2) is {
|
||||||
Some(combined) ->
|
Some(combined) ->
|
||||||
[(k, combined), ..rest]
|
[(k, combined), ..rest]
|
||||||
None ->
|
None -> rest
|
||||||
rest
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
[(k2, v2), ..do_insert_with(rest, k, v, with)]
|
[(k2, v2), ..do_insert_with(rest, k, v, with)]
|
||||||
|
|
|
@ -35,8 +35,7 @@ pub fn add(left v0: Value, right v1: Value) -> Value {
|
||||||
a0,
|
a0,
|
||||||
a1,
|
a1,
|
||||||
fn(_, q0, q1) {
|
fn(_, q0, q1) {
|
||||||
let q =
|
let q = q0 + q1
|
||||||
q0 + q1
|
|
||||||
if q == 0 {
|
if q == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,19 +45,15 @@ pub fn add(left v0: Value, right v1: Value) -> Value {
|
||||||
)
|
)
|
||||||
|
|
||||||
when dict.toList(asset) is {
|
when dict.toList(asset) is {
|
||||||
[] ->
|
[] -> None
|
||||||
None
|
_ -> Some(asset)
|
||||||
_ ->
|
|
||||||
Some(asset)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
test add_1() {
|
test add_1() {
|
||||||
let v1 =
|
let v1 = from_lovelace(1)
|
||||||
from_lovelace(1)
|
let v2 = from_lovelace(-1)
|
||||||
let v2 =
|
|
||||||
from_lovelace(-1)
|
|
||||||
add(v1, v2) == dict.new()
|
add(v1, v2) == dict.new()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181051, nanos_since_epoch = 270212000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743641, nanos_since_epoch = 8357000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"plutusVersion": "v2",
|
"plutusVersion": "v2",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"name": "Aiken",
|
"name": "Aiken",
|
||||||
"version": "v1.0.21-alpha+0161cf6"
|
"version": "v1.0.21-alpha+bf96c3a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|
|
@ -3,8 +3,7 @@ use aiken/list
|
||||||
use aiken/transaction.{Output, OutputReference, ScriptContext}
|
use aiken/transaction.{Output, OutputReference, ScriptContext}
|
||||||
use aiken/transaction/value.{PolicyId}
|
use aiken/transaction/value.{PolicyId}
|
||||||
|
|
||||||
const my_policy_id: PolicyId =
|
const my_policy_id: PolicyId = #"0000000000"
|
||||||
#"0000000000"
|
|
||||||
|
|
||||||
pub fn has_policy_id(self: Output, policy_id: PolicyId) -> Bool {
|
pub fn has_policy_id(self: Output, policy_id: PolicyId) -> Bool {
|
||||||
self.value
|
self.value
|
||||||
|
@ -28,10 +27,8 @@ validator(output_reference: OutputReference) {
|
||||||
fn(input) { input.output_reference == output_reference },
|
fn(input) { input.output_reference == output_reference },
|
||||||
)
|
)
|
||||||
is {
|
is {
|
||||||
Some(_) ->
|
Some(_) -> True
|
||||||
True
|
None -> False
|
||||||
None ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub fn and_f(self: List<Bool>) -> Bool {
|
pub fn and_f(self: List<Bool>) -> Bool {
|
||||||
when self is {
|
when self is {
|
||||||
[] ->
|
[] -> True
|
||||||
True
|
[x, ..xs] -> x && and_f(xs)
|
||||||
[x, ..xs] ->
|
|
||||||
x && and_f(xs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +11,8 @@ test and_f_1() {
|
||||||
|
|
||||||
pub fn or_f(self: List<Bool>) -> Bool {
|
pub fn or_f(self: List<Bool>) -> Bool {
|
||||||
when self is {
|
when self is {
|
||||||
[] ->
|
[] -> False
|
||||||
False
|
[x, ..xs] -> x || or_f(xs)
|
||||||
[x, ..xs] ->
|
|
||||||
x || or_f(xs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,17 @@
|
||||||
test foo_1() {
|
test foo_1() {
|
||||||
let a =
|
let a = False
|
||||||
False
|
|
||||||
when a is {
|
when a is {
|
||||||
True ->
|
True -> False
|
||||||
False
|
False -> True
|
||||||
False ->
|
|
||||||
True
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test foo_2() {
|
test foo_2() {
|
||||||
let a =
|
let a = False
|
||||||
False
|
|
||||||
let b =
|
let b =
|
||||||
when a is {
|
when a is {
|
||||||
True ->
|
True -> 14
|
||||||
14
|
False -> 42
|
||||||
False ->
|
|
||||||
42
|
|
||||||
}
|
}
|
||||||
b == 42
|
b == 42
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ fn fibonnaci(n) {
|
||||||
test foo() {
|
test foo() {
|
||||||
let right =
|
let right =
|
||||||
fn() { fibonnaci(15) == 610 }
|
fn() { fibonnaci(15) == 610 }
|
||||||
let left =
|
let left = False
|
||||||
False
|
|
||||||
left || right()
|
left || right()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,9 @@ test sort_by_1() {
|
||||||
let xs =
|
let xs =
|
||||||
[[4, 3, 2, 1], [2, 3, 4, 5]]
|
[[4, 3, 2, 1], [2, 3, 4, 5]]
|
||||||
when xs is {
|
when xs is {
|
||||||
[[], ys] ->
|
[[], ys] -> False
|
||||||
False
|
[xs, []] -> False
|
||||||
[xs, []] ->
|
[[x, ..xs2], [y, ..ys2]] -> True
|
||||||
False
|
_ -> False
|
||||||
[[x, ..xs2], [y, ..ys2]] ->
|
|
||||||
True
|
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"plutusVersion": "v2",
|
"plutusVersion": "v2",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"name": "Aiken",
|
"name": "Aiken",
|
||||||
"version": "v1.0.21-alpha+0161cf6"
|
"version": "v1.0.21-alpha+bf96c3a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|
|
@ -1,48 +1,34 @@
|
||||||
test foo_1() {
|
test foo_1() {
|
||||||
let a =
|
let a = False
|
||||||
False
|
|
||||||
when a is {
|
when a is {
|
||||||
a if a ->
|
a if a -> False
|
||||||
False
|
_ -> True
|
||||||
_ ->
|
|
||||||
True
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test foo_2() {
|
test foo_2() {
|
||||||
let point =
|
let point = (14, 42)
|
||||||
(14, 42)
|
|
||||||
when point is {
|
when point is {
|
||||||
(x, _) if x > 100 ->
|
(x, _) if x > 100 -> False
|
||||||
False
|
(x, _) if x > 10 -> True
|
||||||
(x, _) if x > 10 ->
|
_ -> False
|
||||||
True
|
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test foo_3() {
|
test foo_3() {
|
||||||
let point =
|
let point = (14, 42)
|
||||||
(14, 42)
|
|
||||||
when point is {
|
when point is {
|
||||||
(x, y) if x == 14 && y <= 100 ->
|
(x, y) if x == 14 && y <= 100 -> True
|
||||||
True
|
_ -> False
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test foo_4() {
|
test foo_4() {
|
||||||
let a =
|
let a = False
|
||||||
False
|
let point = (14, 42)
|
||||||
let point =
|
|
||||||
(14, 42)
|
|
||||||
when point is {
|
when point is {
|
||||||
(x, y) if !a ->
|
(x, y) if !a -> x + y == 56
|
||||||
x + y == 56
|
_ -> False
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,12 +41,9 @@ type Seasons {
|
||||||
|
|
||||||
fn is_cold(season, hour) {
|
fn is_cold(season, hour) {
|
||||||
when season is {
|
when season is {
|
||||||
Winter | Fall ->
|
Winter | Fall -> True
|
||||||
True
|
_ if hour >= 18 -> True
|
||||||
_ if hour >= 18 ->
|
_ -> False
|
||||||
True
|
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +53,7 @@ test foo_5() {
|
||||||
|
|
||||||
fn when_tuple(a: (Int, Int)) -> Int {
|
fn when_tuple(a: (Int, Int)) -> Int {
|
||||||
when a is {
|
when a is {
|
||||||
(a, _b) ->
|
(a, _b) -> a
|
||||||
a
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
pub fn when_tuple(a: (Int, Int)) -> Int {
|
pub fn when_tuple(a: (Int, Int)) -> Int {
|
||||||
when a is {
|
when a is {
|
||||||
(a, b) ->
|
(a, b) -> a
|
||||||
a
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,55 +5,46 @@ pub type Thing {
|
||||||
}
|
}
|
||||||
|
|
||||||
test let_1() {
|
test let_1() {
|
||||||
let x: Data =
|
let x: Data = 1
|
||||||
1
|
|
||||||
|
|
||||||
x == builtin.i_data(1)
|
x == builtin.i_data(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
test let_2() {
|
test let_2() {
|
||||||
let x: Data =
|
let x: Data = 1
|
||||||
1
|
|
||||||
|
|
||||||
expect y: Int =
|
expect y: Int = x
|
||||||
x
|
|
||||||
|
|
||||||
y == 1
|
y == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
test assert_1() {
|
test assert_1() {
|
||||||
expect thing: Thing =
|
expect thing: Thing = builtin.constr_data(0, [builtin.i_data(1)])
|
||||||
builtin.constr_data(0, [builtin.i_data(1)])
|
|
||||||
|
|
||||||
thing.wow == 1
|
thing.wow == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cast_to_thing(x: Data) -> Thing {
|
fn cast_to_thing(x: Data) -> Thing {
|
||||||
expect x: Thing =
|
expect x: Thing = x
|
||||||
x
|
|
||||||
|
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
test assert_2() {
|
test assert_2() {
|
||||||
let thing =
|
let thing = Thing { wow: 1 }
|
||||||
Thing { wow: 1 }
|
|
||||||
|
|
||||||
let still_thing =
|
let still_thing = cast_to_thing(thing)
|
||||||
cast_to_thing(thing)
|
|
||||||
|
|
||||||
still_thing.wow == 1
|
still_thing.wow == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
test tuple_1() {
|
test tuple_1() {
|
||||||
let thing =
|
let thing = (#"aa", #"bb", #"cc")
|
||||||
(#"aa", #"bb", #"cc")
|
|
||||||
thing.1st == #"aa"
|
thing.1st == #"aa"
|
||||||
}
|
}
|
||||||
|
|
||||||
test pair_1() {
|
test pair_1() {
|
||||||
let thing =
|
let thing = (#"aa", #"bb")
|
||||||
(#"aa", #"bb")
|
|
||||||
thing.1st == #"aa"
|
thing.1st == #"aa"
|
||||||
}
|
}
|
||||||
// should not typecheck
|
// should not typecheck
|
||||||
|
|
|
@ -3,20 +3,16 @@ type TransactionId {
|
||||||
}
|
}
|
||||||
|
|
||||||
test pattern_match_let() {
|
test pattern_match_let() {
|
||||||
let x =
|
let x = TransactionId { inner: #"0000" }
|
||||||
TransactionId { inner: #"0000" }
|
let TransactionId(y) = x
|
||||||
let TransactionId(y) =
|
|
||||||
x
|
|
||||||
y == #"0000"
|
y == #"0000"
|
||||||
}
|
}
|
||||||
|
|
||||||
test pattern_match_when() {
|
test pattern_match_when() {
|
||||||
let x =
|
let x = TransactionId { inner: #"0000" }
|
||||||
TransactionId { inner: #"0000" }
|
|
||||||
let y =
|
let y =
|
||||||
when x is {
|
when x is {
|
||||||
TransactionId(y) ->
|
TransactionId(y) -> y
|
||||||
y
|
|
||||||
}
|
}
|
||||||
y == #"0000"
|
y == #"0000"
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,12 @@ pub type LinkedList<a> {
|
||||||
|
|
||||||
pub fn size(t: LinkedList<alg>) -> Int {
|
pub fn size(t: LinkedList<alg>) -> Int {
|
||||||
when t is {
|
when t is {
|
||||||
Empty ->
|
Empty -> 0
|
||||||
0
|
Node(_, tail) -> 1 + size(tail)
|
||||||
Node(_, tail) ->
|
|
||||||
1 + size(tail)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test foo() {
|
test foo() {
|
||||||
let xs =
|
let xs = Node(0, Node(1, Node(2, Empty)))
|
||||||
Node(0, Node(1, Node(2, Empty)))
|
|
||||||
size(xs) == 3
|
size(xs) == 3
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181048, nanos_since_epoch = 152219000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743640, nanos_since_epoch = 944875000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use aiken/transaction/value
|
use aiken/transaction/value
|
||||||
|
|
||||||
test test_quantity_of_1() {
|
test test_quantity_of_1() {
|
||||||
let x =
|
let x = value.from_asset(#"000000", #"000020e05363726970744f776e6572", -1)
|
||||||
value.from_asset(#"000000", #"000020e05363726970744f776e6572", -1)
|
|
||||||
value.quantity_of(x, #"000000", #"000020e05363726970744f776e6572") < 0
|
value.quantity_of(x, #"000000", #"000020e05363726970744f776e6572") < 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181051, nanos_since_epoch = 995566000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 21373000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use aiken/bytearray
|
use aiken/bytearray
|
||||||
use aiken/dict
|
use aiken/dict
|
||||||
use aiken/hash.{Hash, Sha2_256, sha2_256}
|
use aiken/hash.{Hash, Sha2_256, sha2_256}
|
||||||
use aiken/interval.{between, intersection, is_empty, entirely_between}
|
use aiken/interval.{between, entirely_between, intersection, is_empty}
|
||||||
use aiken/list
|
use aiken/list
|
||||||
use aiken/transaction.{InlineDatum}
|
use aiken/transaction.{InlineDatum}
|
||||||
|
|
||||||
|
@ -15,12 +15,9 @@ pub type MerkleTree {
|
||||||
|
|
||||||
pub fn root_hash(t: MerkleTree) -> Hash<Sha2_256, ByteArray> {
|
pub fn root_hash(t: MerkleTree) -> Hash<Sha2_256, ByteArray> {
|
||||||
when t is {
|
when t is {
|
||||||
Empty ->
|
Empty -> #""
|
||||||
#""
|
Leaf { hash, .. } -> hash
|
||||||
Leaf { hash, .. } ->
|
Node { hash, .. } -> hash
|
||||||
hash
|
|
||||||
Node { hash, .. } ->
|
|
||||||
hash
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +27,9 @@ pub fn is_equal(a: MerkleTree, b: MerkleTree) -> Bool {
|
||||||
|
|
||||||
pub fn size(t: MerkleTree) -> Int {
|
pub fn size(t: MerkleTree) -> Int {
|
||||||
when t is {
|
when t is {
|
||||||
Empty ->
|
Empty -> 0
|
||||||
0
|
Leaf { .. } -> 1
|
||||||
Leaf { .. } ->
|
Node { left, right, .. } -> size(left) + size(right)
|
||||||
1
|
|
||||||
Node { left, right, .. } ->
|
|
||||||
size(left) + size(right)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,13 +43,10 @@ pub fn from_list(items0: List<ByteArray>) -> MerkleTree {
|
||||||
|
|
||||||
fn do_from_list(items: List<ByteArray>, len: Int) -> MerkleTree {
|
fn do_from_list(items: List<ByteArray>, len: Int) -> MerkleTree {
|
||||||
when items is {
|
when items is {
|
||||||
[] ->
|
[] -> Empty
|
||||||
Empty
|
[value] -> Leaf { hash: sha2_256(value), value }
|
||||||
[value] ->
|
|
||||||
Leaf { hash: sha2_256(value), value }
|
|
||||||
all -> {
|
all -> {
|
||||||
let cutoff: Int =
|
let cutoff: Int = len / 2
|
||||||
len / 2
|
|
||||||
let left =
|
let left =
|
||||||
all
|
all
|
||||||
|> list.take(cutoff)
|
|> list.take(cutoff)
|
||||||
|
@ -64,8 +55,7 @@ fn do_from_list(items: List<ByteArray>, len: Int) -> MerkleTree {
|
||||||
all
|
all
|
||||||
|> list.drop(cutoff)
|
|> list.drop(cutoff)
|
||||||
|> do_from_list(len - cutoff)
|
|> do_from_list(len - cutoff)
|
||||||
let hash =
|
let hash = combine_hash(root_hash(left), root_hash(right))
|
||||||
combine_hash(root_hash(left), root_hash(right))
|
|
||||||
Node { hash, left, right }
|
Node { hash, left, right }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,8 +64,7 @@ fn do_from_list(items: List<ByteArray>, len: Int) -> MerkleTree {
|
||||||
test foo() {
|
test foo() {
|
||||||
let items =
|
let items =
|
||||||
[#"aa", #"bb", #"cc"]
|
[#"aa", #"bb", #"cc"]
|
||||||
let mt =
|
let mt = from_list(items)
|
||||||
from_list(items)
|
|
||||||
size(mt) == 3
|
size(mt) == 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,19 +73,15 @@ test some_test1() {
|
||||||
}
|
}
|
||||||
|
|
||||||
test intersection_3() {
|
test intersection_3() {
|
||||||
let iv1 =
|
let iv1 = between(0, 1)
|
||||||
between(0, 1)
|
let iv2 = entirely_between(1, 2)
|
||||||
let iv2 =
|
|
||||||
entirely_between(1, 2)
|
|
||||||
intersection(iv1, iv2)
|
intersection(iv1, iv2)
|
||||||
|> is_empty
|
|> is_empty
|
||||||
}
|
}
|
||||||
|
|
||||||
const fooz =
|
const fooz = #"666f6f"
|
||||||
#"666f6f"
|
|
||||||
|
|
||||||
const bar =
|
const bar = #"626172"
|
||||||
#"626172"
|
|
||||||
|
|
||||||
fn fixture_1() {
|
fn fixture_1() {
|
||||||
dict.new()
|
dict.new()
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
// Could possibly be forbidden by the parser instead if we have no intent to support that.
|
// Could possibly be forbidden by the parser instead if we have no intent to support that.
|
||||||
pub fn choice(self: List<Option<a>>) -> Option<a> {
|
pub fn choice(self: List<Option<a>>) -> Option<a> {
|
||||||
when self is {
|
when self is {
|
||||||
[] ->
|
[] -> None
|
||||||
None
|
[Some(_) as result, ..] -> result
|
||||||
[Some(_) as result, ..] ->
|
[None, ..others] -> choice(others)
|
||||||
result
|
|
||||||
[None, ..others] ->
|
|
||||||
choice(others)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
pub fn choice(self: List<Option<a>>) -> Option<a> {
|
pub fn choice(self: List<Option<a>>) -> Option<a> {
|
||||||
when self is {
|
when self is {
|
||||||
[] ->
|
[] -> None
|
||||||
None
|
[Some(x), ..] -> Some(x)
|
||||||
[Some(x), ..] ->
|
[None, ..others] -> choice(others)
|
||||||
Some(x)
|
|
||||||
[None, ..others] ->
|
|
||||||
choice(others)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
pub fn choice(self: List<Option<a>>) -> Option<a> {
|
pub fn choice(self: List<Option<a>>) -> Option<a> {
|
||||||
when self is {
|
when self is {
|
||||||
[] ->
|
[] -> None
|
||||||
None
|
[None, ..others] -> choice(others)
|
||||||
[None, ..others] ->
|
[result, ..] -> result
|
||||||
choice(others)
|
|
||||||
[result, ..] ->
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
pub fn alt(left: Option<a>, right: Option<a>) -> Option<a> {
|
pub fn alt(left: Option<a>, right: Option<a>) -> Option<a> {
|
||||||
when (left, right) is {
|
when (left, right) is {
|
||||||
(Some(a), Some(_)) ->
|
(Some(a), Some(_)) -> Some(a)
|
||||||
Some(a)
|
(None, Some(a)) -> Some(a)
|
||||||
(None, Some(a)) ->
|
(Some(a), None) -> Some(a)
|
||||||
Some(a)
|
(None, None) -> None
|
||||||
(Some(a), None) ->
|
|
||||||
Some(a)
|
|
||||||
(None, None) ->
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,8 @@ test foo() {
|
||||||
let xs =
|
let xs =
|
||||||
[1, 2, 3]
|
[1, 2, 3]
|
||||||
when xs is {
|
when xs is {
|
||||||
[x] ->
|
[x] -> x == 1
|
||||||
x == 1
|
_ -> whatever(xs)
|
||||||
_ ->
|
|
||||||
whatever(xs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +15,7 @@ test bar() {
|
||||||
let xs =
|
let xs =
|
||||||
[1, 2, 3]
|
[1, 2, 3]
|
||||||
when xs is {
|
when xs is {
|
||||||
[x] ->
|
[x] -> x == 1
|
||||||
x == 1
|
ys -> whatever(ys)
|
||||||
ys ->
|
|
||||||
whatever(ys)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,8 @@ test foo() {
|
||||||
let xs =
|
let xs =
|
||||||
[[1, 2], [4, 5]]
|
[[1, 2], [4, 5]]
|
||||||
when xs is {
|
when xs is {
|
||||||
[[_, _], [_, _]] ->
|
[[_, _], [_, _]] -> True
|
||||||
True
|
_ -> False
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,10 +12,8 @@ test sort_by_1() {
|
||||||
[[4, 3], [2, 3]]
|
[[4, 3], [2, 3]]
|
||||||
let g =
|
let g =
|
||||||
when xs is {
|
when xs is {
|
||||||
[[x, xs2], [y, ys2]] ->
|
[[x, xs2], [y, ys2]] -> True
|
||||||
True
|
_ -> False
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g == True
|
g == True
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
const int_constant =
|
const int_constant = 42
|
||||||
42
|
|
||||||
|
|
||||||
test int() {
|
test int() {
|
||||||
int_constant == 42
|
int_constant == 42
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytearray_constant =
|
const bytearray_constant = #"abcd"
|
||||||
#"abcd"
|
|
||||||
|
|
||||||
test bytearray() {
|
test bytearray() {
|
||||||
bytearray_constant == #"abcd"
|
bytearray_constant == #"abcd"
|
||||||
}
|
}
|
||||||
|
|
||||||
const string_constant =
|
const string_constant = "FOO"
|
||||||
"FOO"
|
|
||||||
|
|
||||||
test string() {
|
test string() {
|
||||||
string_constant == "FOO"
|
string_constant == "FOO"
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181064, nanos_since_epoch = 69739000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743643, nanos_since_epoch = 126963000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -8,11 +8,9 @@ use aiken/transaction/credential.{
|
||||||
}
|
}
|
||||||
use aiken/transaction/value
|
use aiken/transaction/value
|
||||||
|
|
||||||
const keyhash =
|
const keyhash = #"010203040506"
|
||||||
#"010203040506"
|
|
||||||
|
|
||||||
const scripthash =
|
const scripthash = #"060504030201"
|
||||||
#"060504030201"
|
|
||||||
|
|
||||||
pub fn keyhash_address(with_stake_credential: Option<StakeCredential>) {
|
pub fn keyhash_address(with_stake_credential: Option<StakeCredential>) {
|
||||||
Address {
|
Address {
|
||||||
|
@ -34,8 +32,7 @@ type SampleData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tx_1() -> Transaction {
|
pub fn tx_1() -> Transaction {
|
||||||
let sample_datum =
|
let sample_datum = SampleData { a: 1, b: #"01" }
|
||||||
SampleData { a: 1, b: #"01" }
|
|
||||||
let tx =
|
let tx =
|
||||||
Transaction {
|
Transaction {
|
||||||
inputs: [
|
inputs: [
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181052, nanos_since_epoch = 418642000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 40391000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -4,8 +4,7 @@ fn must_be_signed(signatories) {
|
||||||
trace @"no signatories"
|
trace @"no signatories"
|
||||||
False
|
False
|
||||||
}
|
}
|
||||||
[sig, ..] ->
|
[sig, ..] -> (sig == "#ffff")?
|
||||||
(sig == "#ffff")?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181066, nanos_since_epoch = 607926000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743643, nanos_since_epoch = 283477000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -37,25 +37,19 @@ pub fn to_list(self: MerkleTree<a>) -> List<a> {
|
||||||
[]
|
[]
|
||||||
Leaf { value, .. } ->
|
Leaf { value, .. } ->
|
||||||
[value]
|
[value]
|
||||||
Node { left, right, .. } ->
|
Node { left, right, .. } -> list.concat(to_list(left), to_list(right))
|
||||||
list.concat(to_list(left), to_list(right))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test to_list_1() {
|
test to_list_1() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse]
|
[dog, cat, mouse]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
items == to_list(mt)
|
items == to_list(mt)
|
||||||
}
|
}
|
||||||
|
@ -63,54 +57,39 @@ test to_list_1() {
|
||||||
// Function returning a hash of a given Merkle Tree element
|
// Function returning a hash of a given Merkle Tree element
|
||||||
pub fn root_hash(self: MerkleTree<a>) -> Hash<Sha2_256, ByteArray> {
|
pub fn root_hash(self: MerkleTree<a>) -> Hash<Sha2_256, ByteArray> {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> ""
|
||||||
""
|
Leaf { hash, .. } -> hash
|
||||||
Leaf { hash, .. } ->
|
Node { hash, .. } -> hash
|
||||||
hash
|
|
||||||
Node { hash, .. } ->
|
|
||||||
hash
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test root_hash_1() {
|
test root_hash_1() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
|
||||||
let items =
|
let items =
|
||||||
[dog]
|
[dog]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let node_hash =
|
let node_hash = hash_fn(dog)
|
||||||
hash_fn(dog)
|
|
||||||
|
|
||||||
root_hash(mt) == node_hash
|
root_hash(mt) == node_hash
|
||||||
}
|
}
|
||||||
|
|
||||||
test root_hash_3() {
|
test root_hash_3() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse]
|
[dog, cat, mouse]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let node_hash =
|
let node_hash = sha2_256(bytearray.concat(hash_fn(cat), hash_fn(mouse)))
|
||||||
sha2_256(bytearray.concat(hash_fn(cat), hash_fn(mouse)))
|
let rh = sha2_256(bytearray.concat(hash_fn(dog), node_hash))
|
||||||
let rh =
|
|
||||||
sha2_256(bytearray.concat(hash_fn(dog), node_hash))
|
|
||||||
|
|
||||||
expect Node { hash: root_hash, .. } =
|
expect Node { hash: root_hash, .. } = mt
|
||||||
mt
|
|
||||||
|
|
||||||
rh == root_hash
|
rh == root_hash
|
||||||
}
|
}
|
||||||
|
@ -118,13 +97,10 @@ test root_hash_3() {
|
||||||
test root_hash_2() {
|
test root_hash_2() {
|
||||||
let items =
|
let items =
|
||||||
[]
|
[]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let node_hash =
|
let node_hash = #""
|
||||||
#""
|
|
||||||
|
|
||||||
root_hash(mt) == node_hash
|
root_hash(mt) == node_hash
|
||||||
}
|
}
|
||||||
|
@ -137,78 +113,55 @@ pub fn is_equal(left: MerkleTree<a>, right: MerkleTree<a>) -> Bool {
|
||||||
/// Function returns a total numbers of leaves in the tree.
|
/// Function returns a total numbers of leaves in the tree.
|
||||||
pub fn size(self: MerkleTree<a>) -> Int {
|
pub fn size(self: MerkleTree<a>) -> Int {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> 0
|
||||||
0
|
Leaf { .. } -> 1
|
||||||
Leaf { .. } ->
|
Node { left, right, .. } -> size(left) + size(right)
|
||||||
1
|
|
||||||
Node { left, right, .. } ->
|
|
||||||
size(left) + size(right)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test size_1() {
|
test size_1() {
|
||||||
let items =
|
let items =
|
||||||
[]
|
[]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
size(mt) == 0
|
size(mt) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
test size_2() {
|
test size_2() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let hash_fn = create_string_item_hash_fn()
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
let hash_fn =
|
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_list([dog, cat, mouse], hash_fn)
|
||||||
from_list([dog, cat, mouse], hash_fn)
|
|
||||||
size(mt) == 3
|
size(mt) == 3
|
||||||
}
|
}
|
||||||
|
|
||||||
test size_3() {
|
test size_3() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse]
|
[dog, cat, mouse]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
size(mt) == 3
|
size(mt) == 3
|
||||||
}
|
}
|
||||||
|
|
||||||
test size_4() {
|
test size_4() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let horse = "horse"
|
||||||
let mouse =
|
let pig = "pig"
|
||||||
"mouse"
|
let bull = "bull"
|
||||||
let horse =
|
|
||||||
"horse"
|
|
||||||
let pig =
|
|
||||||
"pig"
|
|
||||||
let bull =
|
|
||||||
"bull"
|
|
||||||
|
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse, pig, bull]
|
[dog, cat, mouse, horse, pig, bull]
|
||||||
|
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
size(mt) == 6
|
size(mt) == 6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,28 +175,22 @@ fn combine_hash(
|
||||||
/// Function that returns whether merkle tree has any elements
|
/// Function that returns whether merkle tree has any elements
|
||||||
pub fn is_empty(self: MerkleTree<a>) -> Bool {
|
pub fn is_empty(self: MerkleTree<a>) -> Bool {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> True
|
||||||
True
|
_ -> False
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test is_empty_1() {
|
test is_empty_1() {
|
||||||
let mt =
|
let mt = Empty
|
||||||
Empty
|
|
||||||
|
|
||||||
is_empty(mt)
|
is_empty(mt)
|
||||||
}
|
}
|
||||||
|
|
||||||
test is_empty_2() {
|
test is_empty_2() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let hash = create_string_item_hash_fn()
|
||||||
let hash =
|
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = Leaf { value: dog, hash: hash(dog) }
|
||||||
Leaf { value: dog, hash: hash(dog) }
|
|
||||||
|
|
||||||
is_empty(mt) == False
|
is_empty(mt) == False
|
||||||
}
|
}
|
||||||
|
@ -255,8 +202,7 @@ fn do_proof(
|
||||||
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
||||||
) -> Option<Proof> {
|
) -> Option<Proof> {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> None
|
||||||
None
|
|
||||||
Leaf { hash, .. } ->
|
Leaf { hash, .. } ->
|
||||||
if hash == item_hash {
|
if hash == item_hash {
|
||||||
Some(proof)
|
Some(proof)
|
||||||
|
@ -264,10 +210,8 @@ fn do_proof(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Node { left, right, .. } -> {
|
Node { left, right, .. } -> {
|
||||||
let rh =
|
let rh = root_hash(right)
|
||||||
root_hash(right)
|
let lh = root_hash(left)
|
||||||
let lh =
|
|
||||||
root_hash(left)
|
|
||||||
let go_left: Option<Proof> =
|
let go_left: Option<Proof> =
|
||||||
do_proof(left, item_hash, list.push(proof, Right { hash: rh }), hash_fn)
|
do_proof(left, item_hash, list.push(proof, Right { hash: rh }), hash_fn)
|
||||||
let go_right: Option<Proof> =
|
let go_right: Option<Proof> =
|
||||||
|
@ -292,130 +236,91 @@ pub fn get_proof(
|
||||||
}
|
}
|
||||||
|
|
||||||
test get_proof_1() {
|
test get_proof_1() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let horse = "horse"
|
||||||
let mouse =
|
let pig = "pig"
|
||||||
"mouse"
|
let bull = "bull"
|
||||||
let horse =
|
|
||||||
"horse"
|
|
||||||
let pig =
|
|
||||||
"pig"
|
|
||||||
let bull =
|
|
||||||
"bull"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse, pig, bull]
|
[dog, cat, mouse, horse, pig, bull]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
let hash_fn = create_string_item_hash_fn()
|
||||||
let hash_fn =
|
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let maybe_proof: Option<Proof> =
|
let maybe_proof: Option<Proof> = get_proof(mt, "parrot", hash_fn)
|
||||||
get_proof(mt, "parrot", hash_fn)
|
|
||||||
|
|
||||||
is_none(maybe_proof)
|
is_none(maybe_proof)
|
||||||
}
|
}
|
||||||
|
|
||||||
test get_proof_2() {
|
test get_proof_2() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog]
|
[dog]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let maybe_proof: Option<Proof> =
|
let maybe_proof: Option<Proof> = get_proof(mt, dog, hash_fn)
|
||||||
get_proof(mt, dog, hash_fn)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = maybe_proof
|
||||||
maybe_proof
|
|
||||||
|
|
||||||
// when proof is empty list it actually means that root of the tree is in fact element
|
// when proof is empty list it actually means that root of the tree is in fact element
|
||||||
proof == []
|
proof == []
|
||||||
}
|
}
|
||||||
|
|
||||||
test get_proof_3() {
|
test get_proof_3() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse]
|
[dog, cat, mouse]
|
||||||
|
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let node_hash =
|
let node_hash = sha2_256(bytearray.concat(hash_fn(cat), hash_fn(mouse)))
|
||||||
sha2_256(bytearray.concat(hash_fn(cat), hash_fn(mouse)))
|
|
||||||
|
|
||||||
let maybe_proof: Option<Proof> =
|
let maybe_proof: Option<Proof> = get_proof(mt, dog, hash_fn)
|
||||||
get_proof(mt, dog, hash_fn)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = maybe_proof
|
||||||
maybe_proof
|
|
||||||
|
|
||||||
let size_match =
|
let size_match = list.length(proof) == 1
|
||||||
list.length(proof) == 1
|
|
||||||
|
|
||||||
expect Some(p1) =
|
expect Some(p1) = list.at(proof, 0)
|
||||||
list.at(proof, 0)
|
|
||||||
|
|
||||||
let h1: ByteArray =
|
let h1: ByteArray = get_proof_item_value(p1)
|
||||||
get_proof_item_value(p1)
|
|
||||||
|
|
||||||
size_match && h1 == node_hash
|
size_match && h1 == node_hash
|
||||||
}
|
}
|
||||||
|
|
||||||
test get_proof_4() {
|
test get_proof_4() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let horse = "horse"
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
let horse =
|
|
||||||
"horse"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse]
|
[dog, cat, mouse, horse]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let right_node_hash =
|
let right_node_hash =
|
||||||
sha2_256(bytearray.concat(hash_fn(mouse), hash_fn(horse)))
|
sha2_256(bytearray.concat(hash_fn(mouse), hash_fn(horse)))
|
||||||
let maybe_proof: Option<Proof> =
|
let maybe_proof: Option<Proof> = get_proof(mt, dog, hash_fn)
|
||||||
get_proof(mt, dog, hash_fn)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = maybe_proof
|
||||||
maybe_proof
|
|
||||||
|
|
||||||
let size_match =
|
let size_match = list.length(proof) == 2
|
||||||
list.length(proof) == 2
|
|
||||||
|
|
||||||
expect Some(p1) =
|
expect Some(p1) = list.at(proof, 0)
|
||||||
list.at(proof, 0)
|
expect Some(p2) = list.at(proof, 1)
|
||||||
expect Some(p2) =
|
|
||||||
list.at(proof, 1)
|
|
||||||
|
|
||||||
let h1: ByteArray =
|
let h1: ByteArray = get_proof_item_value(p1)
|
||||||
get_proof_item_value(p1)
|
let h2: ByteArray = get_proof_item_value(p2)
|
||||||
let h2: ByteArray =
|
|
||||||
get_proof_item_value(p2)
|
|
||||||
|
|
||||||
size_match && h1 == hash_fn(cat) && h2 == right_node_hash
|
size_match && h1 == hash_fn(cat) && h2 == right_node_hash
|
||||||
}
|
}
|
||||||
|
@ -426,16 +331,13 @@ fn do_from_list(
|
||||||
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
||||||
) -> MerkleTree<a> {
|
) -> MerkleTree<a> {
|
||||||
when items is {
|
when items is {
|
||||||
[] ->
|
[] -> Empty
|
||||||
Empty
|
|
||||||
[item] -> {
|
[item] -> {
|
||||||
let hashed_item =
|
let hashed_item = hash_fn(item)
|
||||||
hash_fn(item)
|
|
||||||
Leaf { value: item, hash: hashed_item }
|
Leaf { value: item, hash: hashed_item }
|
||||||
}
|
}
|
||||||
all -> {
|
all -> {
|
||||||
let cutoff: Int =
|
let cutoff: Int = len / 2
|
||||||
len / 2
|
|
||||||
let left =
|
let left =
|
||||||
all
|
all
|
||||||
|> list.take(cutoff)
|
|> list.take(cutoff)
|
||||||
|
@ -444,8 +346,7 @@ fn do_from_list(
|
||||||
all
|
all
|
||||||
|> list.drop(cutoff)
|
|> list.drop(cutoff)
|
||||||
|> do_from_list(len - cutoff, hash_fn)
|
|> do_from_list(len - cutoff, hash_fn)
|
||||||
let hash =
|
let hash = combine_hash(root_hash(left), root_hash(right))
|
||||||
combine_hash(root_hash(left), root_hash(right))
|
|
||||||
Node { hash, left, right }
|
Node { hash, left, right }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,46 +363,35 @@ pub fn from_list(
|
||||||
}
|
}
|
||||||
|
|
||||||
test from_1() {
|
test from_1() {
|
||||||
let _a =
|
let _a = -1
|
||||||
-1
|
|
||||||
let items =
|
let items =
|
||||||
[]
|
[]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
Empty == mt
|
Empty == mt
|
||||||
}
|
}
|
||||||
|
|
||||||
test from_2() {
|
test from_2() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
|
||||||
let items =
|
let items =
|
||||||
[dog]
|
[dog]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
Leaf { value: dog, hash: hash_fn(dog) } == mt
|
Leaf { value: dog, hash: hash_fn(dog) } == mt
|
||||||
}
|
}
|
||||||
|
|
||||||
test from_3() {
|
test from_3() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
|
||||||
"cat"
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat]
|
[dog, cat]
|
||||||
|
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let root_hash =
|
let root_hash = sha2_256(bytearray.concat(hash_fn(dog), hash_fn(cat)))
|
||||||
sha2_256(bytearray.concat(hash_fn(dog), hash_fn(cat)))
|
|
||||||
|
|
||||||
Node {
|
Node {
|
||||||
hash: root_hash,
|
hash: root_hash,
|
||||||
|
@ -511,25 +401,18 @@ test from_3() {
|
||||||
}
|
}
|
||||||
|
|
||||||
test from_4() {
|
test from_4() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse]
|
[dog, cat, mouse]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let node_hash =
|
let node_hash = sha2_256(bytearray.concat(hash_fn(cat), hash_fn(mouse)))
|
||||||
sha2_256(bytearray.concat(hash_fn(cat), hash_fn(mouse)))
|
let root_hash = sha2_256(bytearray.concat(hash_fn(dog), node_hash))
|
||||||
let root_hash =
|
|
||||||
sha2_256(bytearray.concat(hash_fn(dog), node_hash))
|
|
||||||
|
|
||||||
Node {
|
Node {
|
||||||
hash: root_hash,
|
hash: root_hash,
|
||||||
|
@ -543,30 +426,22 @@ test from_4() {
|
||||||
}
|
}
|
||||||
|
|
||||||
test from_5() {
|
test from_5() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let horse = "horse"
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
let horse =
|
|
||||||
"horse"
|
|
||||||
|
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse]
|
[dog, cat, mouse, horse]
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let left_node_hash =
|
let left_node_hash = sha2_256(bytearray.concat(hash_fn(dog), hash_fn(cat)))
|
||||||
sha2_256(bytearray.concat(hash_fn(dog), hash_fn(cat)))
|
|
||||||
let right_node_hash =
|
let right_node_hash =
|
||||||
sha2_256(bytearray.concat(hash_fn(mouse), hash_fn(horse)))
|
sha2_256(bytearray.concat(hash_fn(mouse), hash_fn(horse)))
|
||||||
|
|
||||||
let root_hash =
|
let root_hash = sha2_256(bytearray.concat(left_node_hash, right_node_hash))
|
||||||
sha2_256(bytearray.concat(left_node_hash, right_node_hash))
|
|
||||||
|
|
||||||
Node {
|
Node {
|
||||||
hash: root_hash,
|
hash: root_hash,
|
||||||
|
@ -594,8 +469,7 @@ pub fn member_from_hash(
|
||||||
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
when proof is {
|
when proof is {
|
||||||
[] ->
|
[] -> root_hash == item_hash
|
||||||
root_hash == item_hash
|
|
||||||
[head, ..tail] ->
|
[head, ..tail] ->
|
||||||
when head is {
|
when head is {
|
||||||
Left { hash: l } ->
|
Left { hash: l } ->
|
||||||
|
@ -614,173 +488,119 @@ pub fn member(
|
||||||
proof: Proof,
|
proof: Proof,
|
||||||
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
hash_fn: fn(a) -> Hash<Sha2_256, a>,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let item_hash =
|
let item_hash = hash_fn(item)
|
||||||
hash_fn(item)
|
|
||||||
member_from_hash(item_hash, root_hash, proof, hash_fn)
|
member_from_hash(item_hash, root_hash, proof, hash_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
test member_1() {
|
test member_1() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
|
||||||
let items =
|
let items =
|
||||||
[dog]
|
[dog]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let item =
|
let item = dog
|
||||||
dog
|
let rh = root_hash(mt)
|
||||||
let rh =
|
|
||||||
root_hash(mt)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = get_proof(mt, item, hash_fn)
|
||||||
get_proof(mt, item, hash_fn)
|
|
||||||
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
test member_2() {
|
test member_2() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let horse = "horse"
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
let horse =
|
|
||||||
"horse"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse]
|
[dog, cat, mouse, horse]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let item =
|
let item = cat
|
||||||
cat
|
let rh = root_hash(mt)
|
||||||
let rh =
|
|
||||||
root_hash(mt)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = get_proof(mt, item, hash_fn)
|
||||||
get_proof(mt, item, hash_fn)
|
|
||||||
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
test member_3() {
|
test member_3() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
|
||||||
"cat"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat]
|
[dog, cat]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let item =
|
let item = cat
|
||||||
cat
|
let rh = root_hash(mt)
|
||||||
let rh =
|
|
||||||
root_hash(mt)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = get_proof(mt, item, hash_fn)
|
||||||
get_proof(mt, item, hash_fn)
|
|
||||||
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
test member_4() {
|
test member_4() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
|
||||||
let mouse =
|
|
||||||
"mouse"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse]
|
[dog, cat, mouse]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let item =
|
let item = mouse
|
||||||
mouse
|
let rh = root_hash(mt)
|
||||||
let rh =
|
|
||||||
root_hash(mt)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = get_proof(mt, item, hash_fn)
|
||||||
get_proof(mt, item, hash_fn)
|
|
||||||
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
test member_5() {
|
test member_5() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let horse = "horse"
|
||||||
let mouse =
|
let pig = "pig"
|
||||||
"mouse"
|
let bull = "bull"
|
||||||
let horse =
|
|
||||||
"horse"
|
|
||||||
let pig =
|
|
||||||
"pig"
|
|
||||||
let bull =
|
|
||||||
"bull"
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse, pig, bull]
|
[dog, cat, mouse, horse, pig, bull]
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
let mt = from_list(items, hash_fn)
|
||||||
let mt =
|
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let item =
|
let item = pig
|
||||||
pig
|
let rh = root_hash(mt)
|
||||||
let rh =
|
|
||||||
root_hash(mt)
|
|
||||||
|
|
||||||
expect Some(proof) =
|
expect Some(proof) = get_proof(mt, item, hash_fn)
|
||||||
get_proof(mt, item, hash_fn)
|
|
||||||
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
member(item: item, root_hash: rh, proof: proof, hash_fn: hash_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
test member_6() {
|
test member_6() {
|
||||||
let dog =
|
let dog = "dog"
|
||||||
"dog"
|
let cat = "cat"
|
||||||
let cat =
|
let mouse = "mouse"
|
||||||
"cat"
|
let horse = "horse"
|
||||||
let mouse =
|
let pig = "pig"
|
||||||
"mouse"
|
let bull = "bull"
|
||||||
let horse =
|
|
||||||
"horse"
|
|
||||||
let pig =
|
|
||||||
"pig"
|
|
||||||
let bull =
|
|
||||||
"bull"
|
|
||||||
|
|
||||||
let hash_fn =
|
let hash_fn = create_string_item_hash_fn()
|
||||||
create_string_item_hash_fn()
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse, pig, bull]
|
[dog, cat, mouse, horse, pig, bull]
|
||||||
let mt =
|
let mt = from_list(items, hash_fn)
|
||||||
from_list(items, hash_fn)
|
|
||||||
|
|
||||||
let item =
|
let item = "parrot"
|
||||||
"parrot"
|
|
||||||
|
|
||||||
let proof =
|
let proof = get_proof(mt, item, hash_fn)
|
||||||
get_proof(mt, item, hash_fn)
|
|
||||||
proof == None
|
proof == None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_proof_item_value(proof_item: ProofItem) -> Hash<Sha2_256, ByteArray> {
|
fn get_proof_item_value(proof_item: ProofItem) -> Hash<Sha2_256, ByteArray> {
|
||||||
when proof_item is {
|
when proof_item is {
|
||||||
Left(x) ->
|
Left(x) -> x
|
||||||
x
|
Right(y) -> y
|
||||||
Right(y) ->
|
|
||||||
y
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181064, nanos_since_epoch = 977089000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743643, nanos_since_epoch = 186230000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -40,8 +40,7 @@ pub fn add(left v0: Value, right v1: Value) -> Value {
|
||||||
a0,
|
a0,
|
||||||
a1,
|
a1,
|
||||||
fn(_, q0, q1) {
|
fn(_, q0, q1) {
|
||||||
let q =
|
let q = q0 + q1
|
||||||
q0 + q1
|
|
||||||
if q == 0 {
|
if q == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,8 +77,7 @@ pub fn flatten_with(
|
||||||
assets,
|
assets,
|
||||||
fn(asset_name, quantity, xs) {
|
fn(asset_name, quantity, xs) {
|
||||||
when transform(policy_id, asset_name, quantity) is {
|
when transform(policy_id, asset_name, quantity) is {
|
||||||
None ->
|
None -> xs
|
||||||
xs
|
|
||||||
Some(x) ->
|
Some(x) ->
|
||||||
[x, ..xs]
|
[x, ..xs]
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705179899, nanos_since_epoch = 505049000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743643, nanos_since_epoch = 242458000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181045, nanos_since_epoch = 255817000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743640, nanos_since_epoch = 944756000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"plutusVersion": "v2",
|
"plutusVersion": "v2",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"name": "Aiken",
|
"name": "Aiken",
|
||||||
"version": "v1.0.21-alpha+0161cf6"
|
"version": "v1.0.21-alpha+bf96c3a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|
|
@ -69,13 +69,10 @@ pub fn validate_pool_deposit(
|
||||||
datum: PoolDatum,
|
datum: PoolDatum,
|
||||||
redeemer: PoolDepositRedeemer,
|
redeemer: PoolDepositRedeemer,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let validator_address =
|
let validator_address = scripthash_address(#"ff")
|
||||||
scripthash_address(#"ff")
|
|
||||||
|
|
||||||
expect Some(pool_output) =
|
expect Some(pool_output) = get_output(ctx, validator_address)
|
||||||
get_output(ctx, validator_address)
|
expect Some(pool_input) = get_input(ctx, validator_address)
|
||||||
expect Some(pool_input) =
|
|
||||||
get_input(ctx, validator_address)
|
|
||||||
|
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
@ -86,34 +83,28 @@ pub fn validate_pool_borrow(
|
||||||
datum: PoolDatum,
|
datum: PoolDatum,
|
||||||
redeemer: PoolBorrowRedeemer,
|
redeemer: PoolBorrowRedeemer,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let validator_address =
|
let validator_address = scripthash_address(#"ff")
|
||||||
scripthash_address(#"ff")
|
|
||||||
|
|
||||||
expect Some(pool_output) =
|
expect Some(pool_output) = get_output(ctx, validator_address)
|
||||||
get_output(ctx, validator_address)
|
expect Some(pool_input) = get_input(ctx, validator_address)
|
||||||
expect Some(pool_input) =
|
|
||||||
get_input(ctx, validator_address)
|
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
validator {
|
validator {
|
||||||
fn pool_contract(datum: PoolDatum, redeemer: PoolRedeemer, ctx: ScriptContext) {
|
fn pool_contract(datum: PoolDatum, redeemer: PoolRedeemer, ctx: ScriptContext) {
|
||||||
when redeemer.action is {
|
when redeemer.action is {
|
||||||
PoolWithdraw(_) ->
|
PoolWithdraw(_) -> True
|
||||||
True
|
|
||||||
PoolDeposit(pool_deposit_redeemer) ->
|
PoolDeposit(pool_deposit_redeemer) ->
|
||||||
when ctx.purpose is {
|
when ctx.purpose is {
|
||||||
Spend(output_ref) ->
|
Spend(output_ref) ->
|
||||||
validate_pool_deposit(ctx, output_ref, datum, pool_deposit_redeemer)
|
validate_pool_deposit(ctx, output_ref, datum, pool_deposit_redeemer)
|
||||||
_ ->
|
_ -> False
|
||||||
False
|
|
||||||
}
|
}
|
||||||
PoolBorrow(pool_borrow_redeemer) ->
|
PoolBorrow(pool_borrow_redeemer) ->
|
||||||
when ctx.purpose is {
|
when ctx.purpose is {
|
||||||
Spend(output_ref) ->
|
Spend(output_ref) ->
|
||||||
validate_pool_borrow(ctx, output_ref, datum, pool_borrow_redeemer)
|
validate_pool_borrow(ctx, output_ref, datum, pool_borrow_redeemer)
|
||||||
_ ->
|
_ -> False
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181059, nanos_since_epoch = 86246000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 736511000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -30,34 +30,24 @@ fn find_outbound_datum(possible_output: Option<Output>) -> Data {
|
||||||
when possible_output is {
|
when possible_output is {
|
||||||
Some(possible_output) ->
|
Some(possible_output) ->
|
||||||
when possible_output.datum is {
|
when possible_output.datum is {
|
||||||
InlineDatum(outbound_datum) ->
|
InlineDatum(outbound_datum) -> outbound_datum
|
||||||
outbound_datum
|
_ -> fail @"expected outbound inline datum"
|
||||||
_ ->
|
|
||||||
error @"expected outbound inline datum"
|
|
||||||
}
|
}
|
||||||
None ->
|
None -> fail @"no outbound datum found"
|
||||||
error @"no outbound datum found"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn datum_a_cont() -> OtherDatum {
|
fn datum_a_cont() -> OtherDatum {
|
||||||
let owner: OwnerInfo =
|
let owner: OwnerInfo = OwnerInfo { pkh: #"", sc: #"" }
|
||||||
OwnerInfo { pkh: #"", sc: #"" }
|
let have: TokenInfo = TokenInfo { pid: #"", tkn: #"", amt: 100 }
|
||||||
let have: TokenInfo =
|
let want: TokenInfo = TokenInfo { pid: #"acab", tkn: #"beef", amt: 50 }
|
||||||
TokenInfo { pid: #"", tkn: #"", amt: 100 }
|
let info: SwapInfo = SwapInfo { slip: 40 }
|
||||||
let want: TokenInfo =
|
|
||||||
TokenInfo { pid: #"acab", tkn: #"beef", amt: 50 }
|
|
||||||
let info: SwapInfo =
|
|
||||||
SwapInfo { slip: 40 }
|
|
||||||
OtherDatum { owner, have, want, info }
|
OtherDatum { owner, have, want, info }
|
||||||
}
|
}
|
||||||
|
|
||||||
test foo() {
|
test foo() {
|
||||||
let outbound_datum =
|
let outbound_datum = InlineDatum(datum_a_cont())
|
||||||
InlineDatum(datum_a_cont())
|
let outbound_output = Some(Output { datum: outbound_datum })
|
||||||
let outbound_output =
|
expect outbound_datum: OtherDatum = find_outbound_datum(outbound_output)
|
||||||
Some(Output { datum: outbound_datum })
|
|
||||||
expect outbound_datum: OtherDatum =
|
|
||||||
find_outbound_datum(outbound_output)
|
|
||||||
outbound_datum == datum_a_cont()
|
outbound_datum == datum_a_cont()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181056, nanos_since_epoch = 151986000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 350520000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -25,12 +25,9 @@ pub type ProofItem {
|
||||||
// Function returning a hash of a given Merkle Tree element
|
// Function returning a hash of a given Merkle Tree element
|
||||||
pub fn root_hash(self: MerkleTree<a>) -> Hash<Sha2_256, ByteArray> {
|
pub fn root_hash(self: MerkleTree<a>) -> Hash<Sha2_256, ByteArray> {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> #""
|
||||||
#""
|
Leaf { hash } -> hash
|
||||||
Leaf { hash } ->
|
Node { hash, .. } -> hash
|
||||||
hash
|
|
||||||
Node { hash, .. } ->
|
|
||||||
hash
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +39,9 @@ pub fn is_equal(left: MerkleTree<a>, right: MerkleTree<a>) -> Bool {
|
||||||
/// Function returns a total numbers of leaves in the tree.
|
/// Function returns a total numbers of leaves in the tree.
|
||||||
pub fn size(self: MerkleTree<a>) -> Int {
|
pub fn size(self: MerkleTree<a>) -> Int {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> 0
|
||||||
0
|
Leaf { .. } -> 1
|
||||||
Leaf { .. } ->
|
Node { left, right, .. } -> size(left) + size(right)
|
||||||
1
|
|
||||||
Node { left, right, .. } ->
|
|
||||||
size(left) + size(right)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,10 +55,8 @@ fn combine_hash(
|
||||||
/// Function that returns whether merkle tree has any elements
|
/// Function that returns whether merkle tree has any elements
|
||||||
pub fn is_empty(self: MerkleTree<a>) -> Bool {
|
pub fn is_empty(self: MerkleTree<a>) -> Bool {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> True
|
||||||
True
|
_ -> False
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,8 +67,7 @@ fn do_proof(
|
||||||
serialise_fn: fn(a) -> ByteArray,
|
serialise_fn: fn(a) -> ByteArray,
|
||||||
) -> Option<Proof> {
|
) -> Option<Proof> {
|
||||||
when self is {
|
when self is {
|
||||||
Empty ->
|
Empty -> None
|
||||||
None
|
|
||||||
Leaf { hash } ->
|
Leaf { hash } ->
|
||||||
if hash == item_hash {
|
if hash == item_hash {
|
||||||
Some(proof)
|
Some(proof)
|
||||||
|
@ -84,10 +75,8 @@ fn do_proof(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Node { left, right, .. } -> {
|
Node { left, right, .. } -> {
|
||||||
let rh =
|
let rh = root_hash(right)
|
||||||
root_hash(right)
|
let lh = root_hash(left)
|
||||||
let lh =
|
|
||||||
root_hash(left)
|
|
||||||
let go_left: Option<Proof> =
|
let go_left: Option<Proof> =
|
||||||
do_proof(
|
do_proof(
|
||||||
left,
|
left,
|
||||||
|
@ -127,16 +116,13 @@ fn do_from_list(
|
||||||
serialise_fn: fn(a) -> ByteArray,
|
serialise_fn: fn(a) -> ByteArray,
|
||||||
) -> MerkleTree<a> {
|
) -> MerkleTree<a> {
|
||||||
when items is {
|
when items is {
|
||||||
[] ->
|
[] -> Empty
|
||||||
Empty
|
|
||||||
[item] -> {
|
[item] -> {
|
||||||
let hashed_item =
|
let hashed_item = sha2_256(serialise_fn(item))
|
||||||
sha2_256(serialise_fn(item))
|
|
||||||
Leaf { hash: hashed_item }
|
Leaf { hash: hashed_item }
|
||||||
}
|
}
|
||||||
all -> {
|
all -> {
|
||||||
let cutoff: Int =
|
let cutoff: Int = len / 2
|
||||||
len / 2
|
|
||||||
let left =
|
let left =
|
||||||
all
|
all
|
||||||
|> list.take(cutoff)
|
|> list.take(cutoff)
|
||||||
|
@ -145,8 +131,7 @@ fn do_from_list(
|
||||||
all
|
all
|
||||||
|> list.drop(cutoff)
|
|> list.drop(cutoff)
|
||||||
|> do_from_list(len - cutoff, serialise_fn)
|
|> do_from_list(len - cutoff, serialise_fn)
|
||||||
let hash =
|
let hash = combine_hash(root_hash(left), root_hash(right))
|
||||||
combine_hash(root_hash(left), root_hash(right))
|
|
||||||
Node { hash, left, right }
|
Node { hash, left, right }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,13 +152,10 @@ fn do_from_hashes_list(
|
||||||
len: Int,
|
len: Int,
|
||||||
) -> MerkleTree<a> {
|
) -> MerkleTree<a> {
|
||||||
when items is {
|
when items is {
|
||||||
[] ->
|
[] -> Empty
|
||||||
Empty
|
[hashed_item] -> Leaf { hash: hashed_item }
|
||||||
[hashed_item] ->
|
|
||||||
Leaf { hash: hashed_item }
|
|
||||||
all -> {
|
all -> {
|
||||||
let cutoff: Int =
|
let cutoff: Int = len / 2
|
||||||
len / 2
|
|
||||||
let left =
|
let left =
|
||||||
all
|
all
|
||||||
|> list.take(cutoff)
|
|> list.take(cutoff)
|
||||||
|
@ -182,8 +164,7 @@ fn do_from_hashes_list(
|
||||||
all
|
all
|
||||||
|> list.drop(cutoff)
|
|> list.drop(cutoff)
|
||||||
|> do_from_hashes_list(len - cutoff)
|
|> do_from_hashes_list(len - cutoff)
|
||||||
let hash =
|
let hash = combine_hash(root_hash(left), root_hash(right))
|
||||||
combine_hash(root_hash(left), root_hash(right))
|
|
||||||
Node { hash, left, right }
|
Node { hash, left, right }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,8 +188,7 @@ pub fn member_from_hash(
|
||||||
serialise_fn: fn(a) -> ByteArray,
|
serialise_fn: fn(a) -> ByteArray,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
when proof is {
|
when proof is {
|
||||||
[] ->
|
[] -> root_hash == item_hash
|
||||||
root_hash == item_hash
|
|
||||||
[head, ..tail] ->
|
[head, ..tail] ->
|
||||||
when head is {
|
when head is {
|
||||||
Left { hash: l } ->
|
Left { hash: l } ->
|
||||||
|
@ -237,8 +217,7 @@ pub fn member(
|
||||||
proof: Proof,
|
proof: Proof,
|
||||||
serialise_fn: fn(a) -> ByteArray,
|
serialise_fn: fn(a) -> ByteArray,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let item_hash =
|
let item_hash = sha2_256(serialise_fn(item))
|
||||||
sha2_256(serialise_fn(item))
|
|
||||||
member_from_hash(item_hash, root_hash, proof, serialise_fn)
|
member_from_hash(item_hash, root_hash, proof, serialise_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,16 +226,12 @@ pub fn member_from_tree(
|
||||||
item: a,
|
item: a,
|
||||||
serialise_fn: fn(a) -> ByteArray,
|
serialise_fn: fn(a) -> ByteArray,
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let proof: Option<Proof> =
|
let proof: Option<Proof> = get_proof(tree, item, serialise_fn)
|
||||||
get_proof(tree, item, serialise_fn)
|
let rh = root_hash(tree)
|
||||||
let rh =
|
|
||||||
root_hash(tree)
|
|
||||||
|
|
||||||
when proof is {
|
when proof is {
|
||||||
Some(p) ->
|
Some(p) -> member(item, rh, p, serialise_fn)
|
||||||
member(item, rh, p, serialise_fn)
|
None -> False
|
||||||
None ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,25 +241,18 @@ fn create_string_item_serialise_fn() -> fn(String) -> ByteArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
test from_hashes_list_5() {
|
test from_hashes_list_5() {
|
||||||
let dog =
|
let dog = @"dog"
|
||||||
@"dog"
|
let cat = @"cat"
|
||||||
let cat =
|
let mouse = @"mouse"
|
||||||
@"cat"
|
let horse = @"horse"
|
||||||
let mouse =
|
|
||||||
@"mouse"
|
|
||||||
let horse =
|
|
||||||
@"horse"
|
|
||||||
|
|
||||||
let serialise_fn =
|
let serialise_fn = create_string_item_serialise_fn()
|
||||||
create_string_item_serialise_fn()
|
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
[dog, cat, mouse, horse]
|
[dog, cat, mouse, horse]
|
||||||
let hashes_items =
|
let hashes_items = list.map(items, fn(item) { sha2_256(serialise_fn(item)) })
|
||||||
list.map(items, fn(item) { sha2_256(serialise_fn(item)) })
|
|
||||||
|
|
||||||
let mt =
|
let mt = from_hashes_list(hashes_items)
|
||||||
from_hashes_list(hashes_items)
|
|
||||||
|
|
||||||
let left_node_hash =
|
let left_node_hash =
|
||||||
sha2_256(
|
sha2_256(
|
||||||
|
@ -298,8 +266,7 @@ test from_hashes_list_5() {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
let root_hash =
|
let root_hash = sha2_256(bytearray.concat(left_node_hash, right_node_hash))
|
||||||
sha2_256(bytearray.concat(left_node_hash, right_node_hash))
|
|
||||||
|
|
||||||
Node {
|
Node {
|
||||||
hash: root_hash,
|
hash: root_hash,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
test expect_positive() {
|
test expect_positive() {
|
||||||
let val = 5
|
let val = 5
|
||||||
expect True = val > 0
|
expect val > 0
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181044, nanos_since_epoch = 445717000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743640, nanos_since_epoch = 940487000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"plutusVersion": "v2",
|
"plutusVersion": "v2",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"name": "Aiken",
|
"name": "Aiken",
|
||||||
"version": "v1.0.21-alpha+0161cf6"
|
"version": "v1.0.21-alpha+bf96c3a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use aiken/list.{find, foldr}
|
|
||||||
use aiken/transaction.{Input, ScriptContext, Spend, OutputReference, Transaction} as tx
|
|
||||||
use aiken/transaction/value.{add, zero}
|
|
||||||
use aiken/dict
|
use aiken/dict
|
||||||
|
use aiken/list.{find, foldr}
|
||||||
|
use aiken/transaction.{Input,
|
||||||
|
OutputReference, ScriptContext, Spend, Transaction} as tx
|
||||||
|
use aiken/transaction/value.{add, zero}
|
||||||
|
|
||||||
type Action {
|
type Action {
|
||||||
Mint
|
Mint
|
||||||
|
@ -11,28 +11,21 @@ type Action {
|
||||||
|
|
||||||
validator(token_name: ByteArray, utxo_ref: OutputReference) {
|
validator(token_name: ByteArray, utxo_ref: OutputReference) {
|
||||||
fn gift_card(rdmr: Action, ctx: ScriptContext) -> Bool {
|
fn gift_card(rdmr: Action, ctx: ScriptContext) -> Bool {
|
||||||
let ScriptContext { transaction, purpose } =
|
let ScriptContext { transaction, purpose } = ctx
|
||||||
ctx
|
expect tx.Mint(policy_id) = purpose
|
||||||
|
let Transaction { inputs, mint, .. } = transaction
|
||||||
expect tx.Mint(policy_id) =
|
expect [(asset_name, amount)] =
|
||||||
purpose
|
mint
|
||||||
|
|
||||||
let Transaction { inputs, mint, .. } =
|
|
||||||
transaction
|
|
||||||
|
|
||||||
expect [(asset_name, amount)] = mint
|
|
||||||
|> value.from_minted_value
|
|> value.from_minted_value
|
||||||
|> value.tokens(policy_id)
|
|> value.tokens(policy_id)
|
||||||
|> dict.to_list()
|
|> dict.to_list()
|
||||||
|
|
||||||
when rdmr is {
|
when rdmr is {
|
||||||
Mint -> {
|
Mint -> {
|
||||||
expect True =
|
expect
|
||||||
list.any(inputs, fn(input) { input.output_reference == utxo_ref })
|
list.any(inputs, fn(input) { input.output_reference == utxo_ref })
|
||||||
amount == 1 && asset_name == token_name
|
amount == 1 && asset_name == token_name
|
||||||
}
|
}
|
||||||
Burn ->
|
Burn -> todo @"burn"
|
||||||
todo @"burn"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,8 @@ type DayOfTheWeek {
|
||||||
|
|
||||||
fn is_work(day: DayOfTheWeek) {
|
fn is_work(day: DayOfTheWeek) {
|
||||||
when day is {
|
when day is {
|
||||||
Tuesday | Wednesday | Thursday | Friday | Saturday ->
|
Tuesday | Wednesday | Thursday | Friday | Saturday -> True
|
||||||
True
|
_ -> False
|
||||||
_ ->
|
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,12 +25,10 @@ test is_work_2() {
|
||||||
|
|
||||||
fn is_happy_hour(day: DayOfTheWeek, current_time: Int) {
|
fn is_happy_hour(day: DayOfTheWeek, current_time: Int) {
|
||||||
when day is {
|
when day is {
|
||||||
Monday | Sunday ->
|
Monday | Sunday -> True
|
||||||
True
|
|
||||||
Tuesday | Wednesday | Thursday | Friday | Saturday if current_time > 18 ->
|
Tuesday | Wednesday | Thursday | Friday | Saturday if current_time > 18 ->
|
||||||
True
|
True
|
||||||
_ ->
|
_ -> False
|
||||||
False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"plutusVersion": "v2",
|
"plutusVersion": "v2",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"name": "Aiken",
|
"name": "Aiken",
|
||||||
"version": "v1.0.21-alpha+0161cf6"
|
"version": "v1.0.21-alpha+bf96c3a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181045, nanos_since_epoch = 361146000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743640, nanos_since_epoch = 972182000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -149,36 +149,36 @@ test satisfying() {
|
||||||
!satisfied(n, s, v)
|
!satisfied(n, s, v)
|
||||||
}
|
}
|
||||||
and {
|
and {
|
||||||
satisfied(sig1, [keyHash1], validRange(0, 1))?,
|
satisfied(sig1, [keyHash1], validRange(0, 1))?,
|
||||||
satisfied(sig2, [keyHash1, keyHash2], validRange(0, 1))?,
|
satisfied(sig2, [keyHash1, keyHash2], validRange(0, 1))?,
|
||||||
satisfied(allOf, [keyHash1, keyHash2], validRange(0, 1))?,
|
satisfied(allOf, [keyHash1, keyHash2], validRange(0, 1))?,
|
||||||
satisfied(anyOf, [keyHash2], validRange(0, 1))?,
|
satisfied(anyOf, [keyHash2], validRange(0, 1))?,
|
||||||
satisfied(atLeast, [keyHash2, keyHash3], validRange(0, 1))?,
|
satisfied(atLeast, [keyHash2, keyHash3], validRange(0, 1))?,
|
||||||
satisfied(before, [], validRange(0, 5))?,
|
satisfied(before, [], validRange(0, 5))?,
|
||||||
satisfied(after, [], validRange(15, 20))?,
|
satisfied(after, [], validRange(15, 20))?,
|
||||||
satisfied(after, [], validRange(10, 15))?,
|
satisfied(after, [], validRange(10, 15))?,
|
||||||
satisfied(between, [], validRange(12, 13))?,
|
satisfied(between, [], validRange(12, 13))?,
|
||||||
satisfied(vesting, [keyHash1], validRange(0, 5))?,
|
satisfied(vesting, [keyHash1], validRange(0, 5))?,
|
||||||
satisfied(vesting, [keyHash2], validRange(15, 20))?,
|
satisfied(vesting, [keyHash2], validRange(15, 20))?,
|
||||||
unsatisfied(sig1, [keyHash2], validRange(0, 1))?,
|
unsatisfied(sig1, [keyHash2], validRange(0, 1))?,
|
||||||
unsatisfied(sig3, [keyHash1, keyHash2], validRange(0, 1))?,
|
unsatisfied(sig3, [keyHash1, keyHash2], validRange(0, 1))?,
|
||||||
unsatisfied(allOf, [keyHash1, keyHash3], validRange(0, 1))?,
|
unsatisfied(allOf, [keyHash1, keyHash3], validRange(0, 1))?,
|
||||||
unsatisfied(anyOf, [keyHash3], validRange(0, 1))?,
|
unsatisfied(anyOf, [keyHash3], validRange(0, 1))?,
|
||||||
unsatisfied(atLeast, [keyHash2], validRange(0, 1))?,
|
unsatisfied(atLeast, [keyHash2], validRange(0, 1))?,
|
||||||
unsatisfied(before, [], validRange(5, 15))?,
|
unsatisfied(before, [], validRange(5, 15))?,
|
||||||
unsatisfied(before, [], validRange(5, 10))?,
|
unsatisfied(before, [], validRange(5, 10))?,
|
||||||
unsatisfied(before, [], validRange(10, 10))?,
|
unsatisfied(before, [], validRange(10, 10))?,
|
||||||
unsatisfied(after, [], validRange(5, 15))?,
|
unsatisfied(after, [], validRange(5, 15))?,
|
||||||
unsatisfied(between, [], validRange(0, 5))?,
|
unsatisfied(between, [], validRange(0, 5))?,
|
||||||
unsatisfied(between, [], validRange(0, 13))?,
|
unsatisfied(between, [], validRange(0, 13))?,
|
||||||
unsatisfied(between, [], validRange(0, 20))?,
|
unsatisfied(between, [], validRange(0, 20))?,
|
||||||
unsatisfied(between, [], validRange(13, 20))?,
|
unsatisfied(between, [], validRange(13, 20))?,
|
||||||
unsatisfied(between, [], validRange(13, 15))?,
|
unsatisfied(between, [], validRange(13, 15))?,
|
||||||
unsatisfied(between, [], validRange(15, 20))?,
|
unsatisfied(between, [], validRange(15, 20))?,
|
||||||
unsatisfied(vesting, [keyHash2], validRange(0, 5))?,
|
unsatisfied(vesting, [keyHash2], validRange(0, 5))?,
|
||||||
unsatisfied(vesting, [keyHash1], validRange(15, 20))?,
|
unsatisfied(vesting, [keyHash1], validRange(15, 20))?,
|
||||||
unsatisfied(vesting, [keyHash3], validRange(10, 10))?,
|
unsatisfied(vesting, [keyHash3], validRange(10, 10))?,
|
||||||
unsatisfied(vesting, [keyHash3], validRange(0, 5))?,
|
unsatisfied(vesting, [keyHash3], validRange(0, 5))?,
|
||||||
unsatisfied(vesting, [keyHash3], validRange(15, 20))?,
|
unsatisfied(vesting, [keyHash3], validRange(15, 20))?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181044, nanos_since_epoch = 445541000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743640, nanos_since_epoch = 966665000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -27,7 +27,7 @@ fn compare_value(
|
||||||
if
|
if
|
||||||
value.quantity_of(val1, sym, loan_id) == value.quantity_of(val2, sym, loan_id){
|
value.quantity_of(val1, sym, loan_id) == value.quantity_of(val2, sym, loan_id){
|
||||||
|
|
||||||
error @"Should not be equal"
|
fail @"Should not be equal"
|
||||||
} else {
|
} else {
|
||||||
Less
|
Less
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181045, nanos_since_epoch = 301366000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743640, nanos_since_epoch = 968996000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181045, nanos_since_epoch = 320068000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743640, nanos_since_epoch = 975570000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181059, nanos_since_epoch = 76573000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 725442000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"plutusVersion": "v2",
|
"plutusVersion": "v2",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"name": "Aiken",
|
"name": "Aiken",
|
||||||
"version": "v1.0.21-alpha+0161cf6"
|
"version": "v1.0.21-alpha+bf96c3a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181055, nanos_since_epoch = 546831000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 191574000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181060, nanos_since_epoch = 328311000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 768373000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -13,4 +13,4 @@ requirements = []
|
||||||
source = "github"
|
source = "github"
|
||||||
|
|
||||||
[etags]
|
[etags]
|
||||||
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705181054, nanos_since_epoch = 373675000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1705743642, nanos_since_epoch = 175324000 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"plutusVersion": "v2",
|
"plutusVersion": "v2",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"name": "Aiken",
|
"name": "Aiken",
|
||||||
"version": "v1.0.21-alpha+9f263c4"
|
"version": "v1.0.21-alpha+bf96c3a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|
Loading…
Reference in New Issue