Skip to content

Commit

Permalink
Merge pull request #145 from xch-dev/zero-test
Browse files Browse the repository at this point in the history
Zero cat test
  • Loading branch information
Rigidity authored Dec 28, 2024
2 parents 62ea36a + ac89f27 commit 667c980
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions crates/chia-sdk-driver/src/primitives/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,45 @@ mod tests {
Ok(())
}

#[test]
fn test_zero_cat_issuance() -> anyhow::Result<()> {
let mut sim = Simulator::new();
let ctx = &mut SpendContext::new();
let (sk, pk, puzzle_hash, coin) = sim.new_p2(0)?;
let p2 = StandardLayer::new(pk);

let memos = ctx.hint(puzzle_hash)?;
let (issue_cat, cat) = Cat::single_issuance_eve(
ctx,
coin.coin_id(),
0,
Conditions::new().create_coin(puzzle_hash, 0, Some(memos)),
)?;
p2.spend(ctx, coin, issue_cat)?;

sim.spend_coins(ctx.take(), &[sk.clone()])?;

let cat = cat.wrapped_child(puzzle_hash, 0);
assert_eq!(cat.p2_puzzle_hash, puzzle_hash);
assert_eq!(
cat.asset_id,
GenesisByCoinIdTailArgs::curry_tree_hash(coin.coin_id()).into()
);
assert!(sim.coin_state(cat.coin.coin_id()).is_some());

let cat_spend = CatSpend::new(
cat,
p2.spend_with_conditions(
ctx,
Conditions::new().create_coin(puzzle_hash, 0, Some(memos)),
)?,
);
Cat::spend_all(ctx, &[cat_spend])?;
sim.spend_coins(ctx.take(), &[sk])?;

Ok(())
}

#[test]
fn test_missing_cat_issuance_output() -> anyhow::Result<()> {
let mut sim = Simulator::new();
Expand Down

0 comments on commit 667c980

Please sign in to comment.