Skip to content

Commit

Permalink
passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Dec 4, 2024
1 parent b4bb358 commit c0e3f55
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 29 deletions.
15 changes: 9 additions & 6 deletions crates/chia-sdk-driver/src/layers/cat_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,26 @@ mod tests {
use chia_protocol::Coin;
use chia_puzzles::CoinProof;

use crate::ValueLayer;

use super::*;

#[test]
fn test_cat_layer() -> anyhow::Result<()> {
let mut ctx = SpendContext::new();
let asset_id = Bytes32::new([1; 32]);

let layer = CatLayer::new(asset_id, "Hello, world!".to_string());
let layer = CatLayer::new(asset_id, ValueLayer("Hello, world!".to_string()));

let ptr = layer.construct_puzzle(&mut ctx)?;
let puzzle = Puzzle::parse(&ctx.allocator, ptr);
let roundtrip =
CatLayer::<String>::parse_puzzle(&ctx.allocator, puzzle)?.expect("invalid CAT layer");
let roundtrip = CatLayer::<ValueLayer<String>>::parse_puzzle(&ctx.allocator, puzzle)?
.expect("invalid CAT layer");

assert_eq!(roundtrip.asset_id, layer.asset_id);
assert_eq!(roundtrip.inner_puzzle, layer.inner_puzzle);

let expected = CatArgs::curry_tree_hash(asset_id, layer.inner_puzzle.tree_hash());
let expected = CatArgs::curry_tree_hash(asset_id, layer.inner_puzzle.0.tree_hash());
assert_eq!(hex::encode(ctx.tree_hash(ptr)), hex::encode(expected));

Ok(())
Expand All @@ -142,7 +144,7 @@ mod tests {
fn test_cat_solution() -> anyhow::Result<()> {
let mut ctx = SpendContext::new();

let layer = CatLayer::new(Bytes32::default(), NodePtr::NIL);
let layer = CatLayer::new(Bytes32::default(), ValueLayer(NodePtr::NIL));

let solution = CatSolution {
inner_puzzle_solution: NodePtr::NIL,
Expand All @@ -165,7 +167,8 @@ mod tests {

assert_eq!(hex::encode(actual_hash), hex::encode(expected_hash));

let roundtrip = CatLayer::<NodePtr>::parse_solution(&ctx.allocator, actual_ptr)?;
let roundtrip =
CatLayer::<ValueLayer<NodePtr>>::parse_solution(&ctx.allocator, actual_ptr)?;
assert_eq!(roundtrip, solution);

Ok(())
Expand Down
29 changes: 15 additions & 14 deletions crates/chia-sdk-driver/src/layers/p2_singleton_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ mod tests {

use super::*;

use crate::{Launcher, SingletonLayer, SpendWithConditions, StandardLayer};
use crate::{Launcher, SingletonLayer, SpendWithConditions, StandardLayer, ValueLayer};

#[test]
fn test_p2_singleton_layer() -> anyhow::Result<()> {
Expand Down Expand Up @@ -149,19 +149,20 @@ mod tests {
.create_puzzle_announcement(p2_coin.coin_id().into()),
)?
.solution;
let singleton_spend = SingletonLayer::new(launcher_id, p2.construct_puzzle(ctx)?)
.construct_coin_spend(
ctx,
singleton,
SingletonSolution {
lineage_proof: Proof::Eve(EveProof {
parent_parent_coin_info: coin.coin_id(),
parent_amount: 1,
}),
amount: singleton.amount,
inner_solution,
},
)?;
let singleton_spend =
SingletonLayer::new(launcher_id, ValueLayer(p2.construct_puzzle(ctx)?))
.construct_coin_spend(
ctx,
singleton,
SingletonSolution {
lineage_proof: Proof::Eve(EveProof {
parent_parent_coin_info: coin.coin_id(),
parent_amount: 1,
}),
amount: singleton.amount,
inner_solution,
},
)?;
ctx.insert(singleton_spend);

sim.spend_coins(ctx.take(), &[sk])?;
Expand Down
6 changes: 3 additions & 3 deletions crates/chia-sdk-driver/src/primitives/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use chia_sdk_types::{run_puzzle, Condition, Conditions, CreateCoin};
use clvm_traits::{clvm_quote, FromClvm};
use clvmr::{Allocator, NodePtr};

use crate::{CatLayer, DriverError, Layer, Puzzle, Spend, SpendContext};
use crate::{CatLayer, DriverError, Layer, Puzzle, Spend, SpendContext, ValueLayer};

mod cat_spend;
mod single_cat_spend;
Expand Down Expand Up @@ -85,7 +85,7 @@ impl Cat {
conditions: Conditions,
) -> Result<(Conditions, Cat), DriverError> {
let inner_puzzle = ctx.alloc(&clvm_quote!(conditions))?;
let eve_layer = CatLayer::new(asset_id, inner_puzzle);
let eve_layer = CatLayer::new(asset_id, ValueLayer(inner_puzzle));
let inner_puzzle_hash = ctx.tree_hash(inner_puzzle).into();
let puzzle_ptr = eve_layer.construct_puzzle(ctx)?;
let puzzle_hash = ctx.tree_hash(puzzle_ptr).into();
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Cat {

/// Creates a coin spend for this CAT.
pub fn spend(&self, ctx: &mut SpendContext, spend: SingleCatSpend) -> Result<(), DriverError> {
let cat_layer = CatLayer::new(self.asset_id, spend.inner_spend.puzzle);
let cat_layer = CatLayer::new(self.asset_id, ValueLayer(spend.inner_spend.puzzle));

let puzzle = cat_layer.construct_puzzle(ctx)?;
let solution = cat_layer.construct_solution(
Expand Down
6 changes: 4 additions & 2 deletions crates/chia-sdk-driver/src/primitives/datalayer/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use clvm_utils::{tree_hash, CurriedProgram, ToTreeHash, TreeHash};
use clvmr::{Allocator, NodePtr};
use num_bigint::BigInt;

use crate::{DriverError, Layer, NftStateLayer, Puzzle, SingletonLayer, Spend, SpendContext};
use crate::{
DriverError, Layer, NftStateLayer, Puzzle, SingletonLayer, Spend, SpendContext, ValueLayer,
};

use super::{
get_merkle_tree, DataStoreInfo, DataStoreMetadata, DelegatedPuzzle, HintType,
Expand Down Expand Up @@ -51,7 +53,7 @@ where
let layers = self
.info
.clone()
.into_layers_without_delegation_layer(inner_spend.puzzle);
.into_layers_without_delegation_layer(ValueLayer(inner_spend.puzzle));

Check warning on line 56 in crates/chia-sdk-driver/src/primitives/datalayer/datastore.rs

View check run for this annotation

Codecov / codecov/patch

crates/chia-sdk-driver/src/primitives/datalayer/datastore.rs#L56

Added line #L56 was not covered by tests

let solution_ptr = layers.construct_solution(
ctx,
Expand Down
8 changes: 6 additions & 2 deletions crates/chia-sdk-driver/src/primitives/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use clvmr::{Allocator, NodePtr};

use crate::{
DidLayer, DriverError, Layer, Puzzle, SingletonLayer, Spend, SpendContext, SpendWithConditions,
ValueLayer,
};

mod did_info;
Expand Down Expand Up @@ -85,7 +86,10 @@ where
{
/// Creates a coin spend for this DID.
pub fn spend(&self, ctx: &mut SpendContext, inner_spend: Spend) -> Result<(), DriverError> {
let layers = self.info.clone().into_layers(inner_spend.puzzle);
let layers = self
.info

Check warning on line 90 in crates/chia-sdk-driver/src/primitives/did.rs

View check run for this annotation

Codecov / codecov/patch

crates/chia-sdk-driver/src/primitives/did.rs#L89-L90

Added lines #L89 - L90 were not covered by tests
.clone()
.into_layers(ValueLayer(inner_spend.puzzle));

Check warning on line 92 in crates/chia-sdk-driver/src/primitives/did.rs

View check run for this annotation

Codecov / codecov/patch

crates/chia-sdk-driver/src/primitives/did.rs#L92

Added line #L92 was not covered by tests

let puzzle = layers.construct_puzzle(ctx)?;
let solution = layers.construct_solution(
Expand Down Expand Up @@ -230,7 +234,7 @@ where
}

let singleton_solution =
SingletonLayer::<NodePtr>::parse_solution(allocator, parent_solution)?;
SingletonLayer::<Puzzle>::parse_solution(allocator, parent_solution)?;

Check warning on line 237 in crates/chia-sdk-driver/src/primitives/did.rs

View check run for this annotation

Codecov / codecov/patch

crates/chia-sdk-driver/src/primitives/did.rs#L237

Added line #L237 was not covered by tests

let output = run_puzzle(
allocator,
Expand Down
7 changes: 5 additions & 2 deletions crates/chia-sdk-driver/src/primitives/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use clvmr::{sha2::Sha256, Allocator, NodePtr};

use crate::{
DriverError, Layer, NftOwnershipLayer, NftStateLayer, Puzzle, RoyaltyTransferLayer,
SettlementLayer, SingletonLayer, Spend, SpendContext, SpendWithConditions,
SettlementLayer, SingletonLayer, Spend, SpendContext, SpendWithConditions, ValueLayer,
};

mod did_owner;
Expand Down Expand Up @@ -106,7 +106,10 @@ where
{
/// Creates a coin spend for this NFT.
pub fn spend(&self, ctx: &mut SpendContext, inner_spend: Spend) -> Result<(), DriverError> {
let layers = self.info.clone().into_layers(inner_spend.puzzle);
let layers = self
.info

Check warning on line 110 in crates/chia-sdk-driver/src/primitives/nft.rs

View check run for this annotation

Codecov / codecov/patch

crates/chia-sdk-driver/src/primitives/nft.rs#L109-L110

Added lines #L109 - L110 were not covered by tests
.clone()
.into_layers(ValueLayer(inner_spend.puzzle));

Check warning on line 112 in crates/chia-sdk-driver/src/primitives/nft.rs

View check run for this annotation

Codecov / codecov/patch

crates/chia-sdk-driver/src/primitives/nft.rs#L112

Added line #L112 was not covered by tests

let puzzle = layers.construct_puzzle(ctx)?;
let solution = layers.construct_solution(
Expand Down
9 changes: 9 additions & 0 deletions crates/chia-sdk-types/src/puzzle_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ pub trait Mod {
}
}

impl<T> Mod for &T
where
T: Mod,
{
const MOD_REVEAL: &'static [u8] = T::MOD_REVEAL;
const MOD_HASH: TreeHash = T::MOD_HASH;
type Solution = T::Solution;
}

impl Mod for StandardArgs {
const MOD_REVEAL: &[u8] = &STANDARD_PUZZLE;
const MOD_HASH: TreeHash = STANDARD_PUZZLE_HASH;
Expand Down

0 comments on commit c0e3f55

Please sign in to comment.