Support multi-validator in script context accept test.

This commit is contained in:
KtorZ
2024-08-10 14:11:24 +02:00
parent b158469144
commit eea8dc7d0a
15 changed files with 266 additions and 98 deletions

View File

@@ -110,8 +110,8 @@ pub fn exec(
let with_redeemer = |redeemer: &Redeemer| {
eprintln!(
"{} {:?}{}",
" Redeemer"
"{} {:?}[{}]",
" Evaluating"
.if_supports_color(Stderr, |s| s.purple())
.if_supports_color(Stderr, |s| s.bold()),
redeemer.tag,

View File

@@ -49,11 +49,11 @@ pub enum Error {
#[error("can't eval without redeemers")]
NoRedeemers,
#[error(
"mismatch in expected redeemers\n{:>13} {}\n{:>13} {}",
"missing and/or unexpected validator(s) and/or redeemer(s)\n{:>13} {}\n{:>13} {}",
"Missing",
if .missing.is_empty() { "ø".to_string() } else { .missing.join(&format!("\n{:>13}", "")) },
if .missing.is_empty() { "ø".to_string() } else { .missing.join(&format!("\n{:>14}", "")) },
"Unexpected",
if .extra.is_empty() { "ø".to_string() } else { .extra.join(&format!("\n{:>13}", "")) },
if .extra.is_empty() { "ø".to_string() } else { .extra.join(&format!("\n{:>14}", "")) },
)]
RequiredRedeemersMismatch {
missing: Vec<String>,
@@ -87,7 +87,7 @@ pub enum Error {
MissingRequiredInlineDatumOrHash,
#[error("redeemer points to an unsupported certificate type")]
UnsupportedCertificateType,
#[error("failed script execution\n{:>13} {}", format!("{}({})", tag, index), err)]
#[error("failed script execution\n{:>13} {}", format!("{}[{}]", tag, index), err)]
RedeemerError {
tag: String,
index: u32,

View File

@@ -44,7 +44,7 @@ pub fn eval_redeemer(
}
.apply_data(redeemer.data.clone())
.apply_data(script_context.to_plutus_data()),
ScriptContext::V3 { .. } => {
ScriptContext::V3 { .. } if datum.is_some() => {
program
// FIXME: Temporary, but needed until https://github.com/aiken-lang/aiken/pull/977
// is implemented.
@@ -52,6 +52,13 @@ pub fn eval_redeemer(
.apply_data(Data::constr(0, vec![]))
.apply_data(script_context.to_plutus_data())
}
ScriptContext::V3 { .. } => {
program
// FIXME: Temporary, but needed until https://github.com/aiken-lang/aiken/pull/977
// is implemented.
.apply_data(Data::constr(0, vec![]))
.apply_data(script_context.to_plutus_data())
}
};
let mut eval_result = if let Some(costs) = cost_mdl_opt {

View File

@@ -185,7 +185,7 @@ pub fn has_exact_set_of_redeemers(
let missing: Vec<_> = redeemers_needed
.into_iter()
.filter(|x| !wits_redeemer_keys.contains(&&x.0))
.map(|x| format!("{} (key: {:?}, purpose: {:?})", x.2, x.0, x.1,))
.map(|x| format!("{:?}[{:?}] -> {}", x.0.tag, x.0.index, x.2))
.collect();
let extra: Vec<_> = wits_redeemer_keys