Add new script_context acceptance scenario for withdrawals.
This commit is contained in:
43
examples/acceptance_tests/script_context/validators/basic.ak
Normal file
43
examples/acceptance_tests/script_context/validators/basic.ak
Normal file
@@ -0,0 +1,43 @@
|
||||
use aiken/list
|
||||
use aiken/option
|
||||
use aiken/transaction.{ScriptContext, Spend, TransactionId}
|
||||
use aiken/transaction/credential.{VerificationKeyCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
[
|
||||
assert_purpose(ctx.purpose),
|
||||
assert_outputs(ctx.transaction),
|
||||
assert_fee(ctx.transaction),
|
||||
]
|
||||
|> list.and
|
||||
}
|
||||
|
||||
fn assert_purpose(purpose) {
|
||||
when purpose is {
|
||||
Spend(ref) ->
|
||||
ref.transaction_id == TransactionId(
|
||||
#"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
) && ref.output_index == 0
|
||||
_ -> error("script purpose isn't 'Spend'")
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_fee(transaction) {
|
||||
transaction.fee == value.from_lovelace(42)
|
||||
}
|
||||
|
||||
fn assert_outputs(transaction) {
|
||||
when transaction.outputs is {
|
||||
[output] ->
|
||||
[
|
||||
output.value == value.from_lovelace(1000000000),
|
||||
output.address.payment_credential == VerificationKeyCredential(
|
||||
#"11111111111111111111111111111111111111111111111111111111",
|
||||
),
|
||||
option.is_none(output.address.stake_credential),
|
||||
]
|
||||
|> list.and
|
||||
_ -> error("unexpected number of outputs")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
use aiken/dict
|
||||
use aiken/list
|
||||
use aiken/transaction.{ScriptContext}
|
||||
use aiken/transaction/credential.{
|
||||
Inline, ScriptCredential, VerificationKeyCredential,
|
||||
}
|
||||
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
let alice =
|
||||
Inline(
|
||||
VerificationKeyCredential(
|
||||
#"22222222222222222222222222222222222222222222222222222222",
|
||||
))
|
||||
|
||||
|
||||
let bob =
|
||||
Inline(
|
||||
ScriptCredential(
|
||||
#"5e1e8fa84f2b557ddc362329413caa3fd89a1be26bfd24be05ce0a02",
|
||||
))
|
||||
|
||||
|
||||
[
|
||||
when dict.get(ctx.transaction.withdrawals, alice) is {
|
||||
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
|
||||
},
|
||||
dict.keys(ctx.transaction.withdrawals) == [alice, bob],
|
||||
]
|
||||
|> list.and
|
||||
}
|
||||
Reference in New Issue
Block a user