test: fix acceptance tests
This commit is contained in:
@@ -4,14 +4,16 @@ use aiken/transaction.{NoDatum, ScriptContext, Spend, TransactionId}
|
||||
use aiken/transaction/credential.{VerificationKeyCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
[
|
||||
assert_id(ctx.transaction),
|
||||
assert_purpose(ctx.purpose),
|
||||
assert_outputs(ctx.transaction),
|
||||
assert_fee(ctx.transaction),
|
||||
]
|
||||
|> list.and
|
||||
validator spend {
|
||||
fn(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
[
|
||||
assert_id(ctx.transaction),
|
||||
assert_purpose(ctx.purpose),
|
||||
assert_outputs(ctx.transaction),
|
||||
assert_fee(ctx.transaction),
|
||||
]
|
||||
|> list.and
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_id(transaction) {
|
||||
@@ -26,7 +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'"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +49,6 @@ fn assert_outputs(transaction) {
|
||||
output.reference_script == None,
|
||||
]
|
||||
|> list.and
|
||||
_ -> error("unexpected number of outputs")
|
||||
_ -> error "unexpected number of outputs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,15 @@ use aiken/list
|
||||
use aiken/transaction.{DatumHash, InlineDatum, ScriptContext}
|
||||
use aiken/transaction/credential.{Inline, VerificationKeyCredential}
|
||||
|
||||
fn spend(datum: Data, _redeemer: Data, ctx: ScriptContext) {
|
||||
[
|
||||
assert_datum(datum),
|
||||
assert_datums(ctx.transaction.datums),
|
||||
assert_outputs(ctx.transaction.outputs),
|
||||
]
|
||||
|> list.and
|
||||
validator spend {
|
||||
fn(datum: Data, _redeemer: Data, ctx: ScriptContext) {
|
||||
[
|
||||
assert_datum(datum),
|
||||
assert_datums(ctx.transaction.datums),
|
||||
assert_outputs(ctx.transaction.outputs),
|
||||
]
|
||||
|> list.and
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_datum(datum) {
|
||||
@@ -38,7 +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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +67,7 @@ fn assert_second_output(output) {
|
||||
),
|
||||
when output.datum is {
|
||||
InlineDatum(_) -> True
|
||||
_ -> error("expected inline datum")
|
||||
_ -> error "expected inline datum"
|
||||
},
|
||||
]
|
||||
|> list.and
|
||||
|
||||
@@ -3,13 +3,15 @@ use aiken/list
|
||||
use aiken/transaction.{Mint, ScriptContext}
|
||||
use aiken/transaction/value
|
||||
|
||||
fn mint(redeemer: Data, ctx: ScriptContext) {
|
||||
[
|
||||
assert_purpose(ctx),
|
||||
assert_mint(ctx.purpose, ctx.transaction),
|
||||
assert_redeemers(ctx, redeemer),
|
||||
]
|
||||
|> list.and
|
||||
validator mint {
|
||||
fn(redeemer: Data, ctx: ScriptContext) {
|
||||
[
|
||||
assert_purpose(ctx),
|
||||
assert_mint(ctx.purpose, ctx.transaction),
|
||||
assert_redeemers(ctx, redeemer),
|
||||
]
|
||||
|> list.and
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_purpose(ctx) {
|
||||
@@ -27,7 +29,7 @@ fn assert_mint(purpose, transaction) {
|
||||
let tokens = value.tokens(transaction.mint, policy_id)
|
||||
|
||||
when dict.get(tokens, #"666f6f") is {
|
||||
None -> error("token not found")
|
||||
None -> error "token not found"
|
||||
Some(quantity) -> quantity == 1337
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,31 +5,33 @@ use aiken/transaction/credential.{
|
||||
Inline, ScriptCredential, VerificationKeyCredential,
|
||||
}
|
||||
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
let alice =
|
||||
Inline(
|
||||
VerificationKeyCredential(
|
||||
#"22222222222222222222222222222222222222222222222222222222",
|
||||
),
|
||||
)
|
||||
validator spend {
|
||||
fn(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
let alice =
|
||||
Inline(
|
||||
VerificationKeyCredential(
|
||||
#"22222222222222222222222222222222222222222222222222222222",
|
||||
),
|
||||
)
|
||||
|
||||
let bob =
|
||||
Inline(
|
||||
ScriptCredential(
|
||||
#"afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
|
||||
),
|
||||
)
|
||||
let bob =
|
||||
Inline(
|
||||
ScriptCredential(
|
||||
#"afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
|
||||
),
|
||||
)
|
||||
|
||||
[
|
||||
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
|
||||
[
|
||||
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