misc changes

This commit is contained in:
Kasey White
2023-04-07 02:36:39 -04:00
committed by Kasey
parent f8483da4e0
commit 897011e9bc
11 changed files with 217 additions and 51 deletions

View File

@@ -12,7 +12,7 @@ validator {
assert_outputs(ctx.transaction),
assert_fee(ctx.transaction),
]
|> list.and
|> list.and
}
}
@@ -28,7 +28,8 @@ 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'"
}
}
@@ -48,7 +49,8 @@ fn assert_outputs(transaction) {
output.datum == NoDatum,
output.reference_script == None,
]
|> list.and
_ -> error @"unexpected number of outputs"
|> list.and
_ ->
error @"unexpected number of outputs"
}
}

View File

@@ -12,12 +12,13 @@ validator {
assert_datums(ctx.transaction.datums),
assert_outputs(ctx.transaction.outputs),
]
|> list.and
|> list.and
}
}
fn assert_datum(datum) {
let my_datum: Data = Void
let my_datum: Data =
Void
datum == my_datum
}
@@ -26,12 +27,14 @@ 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
}
@@ -40,7 +43,8 @@ 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"
}
}
@@ -53,7 +57,7 @@ fn assert_first_output(output) {
#"e37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4",
),
]
|> list.and
|> list.and
}
fn assert_second_output(output) {
@@ -66,9 +70,11 @@ fn assert_second_output(output) {
),
),
when output.datum is {
InlineDatum(_) -> True
_ -> error @"expected inline datum"
InlineDatum(_) ->
True
_ ->
error @"expected inline datum"
},
]
|> list.and
|> list.and
}

View File

@@ -10,31 +10,37 @@ validator {
assert_mint(ctx.purpose, ctx.transaction),
assert_redeemers(ctx, redeemer),
]
|> list.and
|> list.and
}
}
fn assert_purpose(ctx) {
expect [my_policy_id] =
ctx.transaction.mint
|> value.without_lovelace
|> value.policies
expect Mint(policy_id) = ctx.purpose
|> value.without_lovelace
|> value.policies
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
}

View File

@@ -23,15 +23,19 @@ 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],
]
|> list.and
|> list.and
}
}