Skip to content

Commit

Permalink
size -> bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakuhito committed Aug 16, 2024
1 parent 4783de4 commit f474f52
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 77 deletions.
96 changes: 49 additions & 47 deletions src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ pub mod tests {
run_block_generator::run_block_generator, solution_generator::solution_generator,
},
};
use chia_protocol::{Bytes32, Coin};
use chia_protocol::{Bytes as OgBytes, Bytes32, Coin};
use chia_puzzles::standard::StandardArgs;
use chia_sdk_driver::Launcher;
use chia_sdk_test::{test_transaction, Simulator};
Expand Down Expand Up @@ -763,18 +763,18 @@ pub mod tests {
}

#[derive(PartialEq)]
pub enum Size {
pub enum Bytes {
NONE,
SOME,
NEW,
}

impl Size {
impl Bytes {
pub fn value(&self) -> Option<u64> {
match self {
Size::NONE => None,
Size::SOME => Some(1337),
Size::NEW => Some(42),
Bytes::NONE => None,
Bytes::SOME => Some(1337),
Bytes::NEW => Some(42),
}
}
}
Expand Down Expand Up @@ -870,7 +870,7 @@ pub mod tests {
root_hash: Hash::SOME.value(),
label: Label::SOME.value(),
description: Description::SOME.value(),
size: Size::SOME.value(),
bytes: Bytes::SOME.value(),
};
let new_metadata_condition = NewMetadataCondition::<i32, DataStoreMetadata, Bytes32, i32> {
metadata_updater_reveal: 11,
Expand Down Expand Up @@ -997,7 +997,7 @@ pub mod tests {
new_coin,
owner_pk,
Conditions::new()
.assert_puzzle_announcement(datastore_info.coin.puzzle_hash, &Bytes::new("$".into())),
.assert_puzzle_announcement(datastore_info.coin.puzzle_hash, &OgBytes::new("$".into())),
)?;

// finally, remove delegation layer altogether
Expand Down Expand Up @@ -1089,7 +1089,7 @@ pub mod tests {
root_hash: Hash::ZERO.value(),
label: Label::SOME.value(),
description: Description::SOME.value(),
size: Size::SOME.value(),
bytes: Bytes::SOME.value(),
}
} else {
DataStoreMetadata::default()
Expand Down Expand Up @@ -1153,13 +1153,13 @@ pub mod tests {
dst_with_writer => [true, false],
dst_with_oracle => [true, false],
src_meta => [
(Hash::ZERO, Label::NONE, Description::NONE, Size::NONE),
(Hash::SOME, Label::SOME, Description::SOME, Size::SOME),
(Hash::ZERO, Label::NONE, Description::NONE, Bytes::NONE),
(Hash::SOME, Label::SOME, Description::SOME, Bytes::SOME),
],
dst_meta => [
(Hash::ZERO, Label::NONE, Description::NONE, Size::NONE),
(Hash::ZERO, Label::SOME, Description::SOME, Size::SOME),
(Hash::ZERO, Label::NEW, Description::NEW, Size::NEW),
(Hash::ZERO, Label::NONE, Description::NONE, Bytes::NONE),
(Hash::ZERO, Label::SOME, Description::SOME, Bytes::SOME),
(Hash::ZERO, Label::NEW, Description::NEW, Bytes::NEW),
],
dst_admin => [
DstAdmin::None,
Expand All @@ -1169,14 +1169,14 @@ pub mod tests {
)]
#[tokio::test]
async fn test_datastore_admin_transition(
src_meta: (Hash, Label, Description, Size),
src_meta: (Hash, Label, Description, Bytes),
src_with_writer: bool,
// src must have admin layer in this scenario
src_with_oracle: bool,
dst_with_writer: bool,
dst_with_oracle: bool,
dst_admin: DstAdmin,
dst_meta: (Hash, Label, Description, Size),
dst_meta: (Hash, Label, Description, Bytes),
) -> anyhow::Result<()> {
let sim = Simulator::new().await?;
let peer = sim.connect().await?;
Expand Down Expand Up @@ -1223,7 +1223,7 @@ pub mod tests {
root_hash: src_meta.0.value(),
label: src_meta.1.value(),
description: src_meta.2.value(),
size: src_meta.3.value(),
bytes: src_meta.3.value(),
},
owner_puzzle_hash: owner_puzzle_hash.into(),
delegated_puzzles: src_delegated_puzzles.clone(),
Expand Down Expand Up @@ -1291,7 +1291,7 @@ pub mod tests {
root_hash: dst_meta.0.value(),
label: dst_meta.1.value(),
description: dst_meta.2.value(),
size: dst_meta.3.value(),
bytes: dst_meta.3.value(),
};
let new_metadata_condition = NewMetadataCondition::<i32, DataStoreMetadata, Bytes32, i32> {
metadata_updater_reveal: 11,
Expand Down Expand Up @@ -1455,26 +1455,26 @@ pub mod tests {
dst_with_writer => [true, false],
dst_with_oracle => [true, false],
src_meta => [
(Hash::ZERO, Label::NONE, Description::NONE, Size::NONE),
(Hash::SOME, Label::SOME, Description::SOME, Size::SOME),
(Hash::ZERO, Label::NONE, Description::NONE, Bytes::NONE),
(Hash::SOME, Label::SOME, Description::SOME, Bytes::SOME),
],
dst_meta => [
(Hash::ZERO, Label::NONE, Description::NONE, Size::NONE),
(Hash::ZERO, Label::SOME, Description::SOME, Size::SOME),
(Hash::ZERO, Label::NEW, Description::NEW, Size::NEW),
(Hash::ZERO, Label::NONE, Description::NONE, Bytes::NONE),
(Hash::ZERO, Label::SOME, Description::SOME, Bytes::SOME),
(Hash::ZERO, Label::NEW, Description::NEW, Bytes::NEW),
],
also_change_owner => [true, false],
)]
#[tokio::test]
async fn test_datastore_owner_transition(
src_meta: (Hash, Label, Description, Size),
src_meta: (Hash, Label, Description, Bytes),
src_with_admin: bool,
src_with_writer: bool,
src_with_oracle: bool,
dst_with_admin: bool,
dst_with_writer: bool,
dst_with_oracle: bool,
dst_meta: (Hash, Label, Description, Size),
dst_meta: (Hash, Label, Description, Bytes),
also_change_owner: bool,
) -> anyhow::Result<()> {
let sim = Simulator::new().await?;
Expand Down Expand Up @@ -1524,7 +1524,7 @@ pub mod tests {
root_hash: src_meta.0.value(),
label: src_meta.1.value(),
description: src_meta.2.value(),
size: src_meta.3.value(),
bytes: src_meta.3.value(),
},
owner_puzzle_hash: owner_puzzle_hash.into(),
delegated_puzzles: src_delegated_puzzles.clone(),
Expand Down Expand Up @@ -1586,7 +1586,7 @@ pub mod tests {
root_hash: dst_meta.0.value(),
label: dst_meta.1.value(),
description: dst_meta.2.value(),
size: dst_meta.3.value(),
bytes: dst_meta.3.value(),
};
let new_metadata_condition = NewMetadataCondition::<i32, DataStoreMetadata, Bytes32, i32> {
metadata_updater_reveal: 11,
Expand Down Expand Up @@ -1748,31 +1748,31 @@ pub mod tests {
(Hash::ZERO, Hash::ZERO),
(Label::NONE, Label::SOME),
(Description::NONE, Description::SOME),
(Size::NONE, Size::SOME)
(Bytes::NONE, Bytes::SOME)
),
(
(Hash::ZERO, Hash::SOME),
(Label::NONE, Label::NONE),
(Description::NONE, Description::NONE),
(Size::NONE, Size::NONE)
(Bytes::NONE, Bytes::NONE)
),
(
(Hash::ZERO, Hash::SOME),
(Label::SOME, Label::SOME),
(Description::SOME, Description::SOME),
(Size::SOME, Size::SOME)
(Bytes::SOME, Bytes::SOME)
),
(
(Hash::ZERO, Hash::ZERO),
(Label::SOME, Label::NEW),
(Description::SOME, Description::NEW),
(Size::SOME, Size::NEW)
(Bytes::SOME, Bytes::NEW)
),
(
(Hash::ZERO, Hash::ZERO),
(Label::NONE, Label::NONE),
(Description::NONE, Description::NONE),
(Size::NONE, Size::SOME)
(Bytes::NONE, Bytes::SOME)
),
],
)]
Expand All @@ -1784,7 +1784,7 @@ pub mod tests {
(Hash, Hash),
(Label, Label),
(Description, Description),
(Size, Size),
(Bytes, Bytes),
),
) -> anyhow::Result<()> {
let sim = Simulator::new().await?;
Expand Down Expand Up @@ -1830,7 +1830,7 @@ pub mod tests {
root_hash: meta_transition.0 .0.value(),
label: meta_transition.1 .0.value(),
description: meta_transition.2 .0.value(),
size: meta_transition.3 .0.value(),
bytes: meta_transition.3 .0.value(),
},
owner_puzzle_hash: owner_puzzle_hash.into(),
delegated_puzzles: delegated_puzzles.clone(),
Expand All @@ -1856,7 +1856,7 @@ pub mod tests {
root_hash: meta_transition.0 .1.value(),
label: meta_transition.1 .1.value(),
description: meta_transition.2 .1.value(),
size: meta_transition.3 .1.value(),
bytes: meta_transition.3 .1.value(),
};
let new_metadata_condition = NewMetadataCondition::<i32, DataStoreMetadata, Bytes32, i32> {
metadata_updater_reveal: 11,
Expand Down Expand Up @@ -2016,17 +2016,17 @@ pub mod tests {
with_admin_layer => [true, false],
with_writer_layer => [true, false],
meta => [
(Hash::ZERO, Label::NONE, Description::NONE, Size::NONE),
(Hash::ZERO, Label::NONE, Description::NONE, Size::SOME),
(Hash::ZERO, Label::NONE, Description::SOME, Size::SOME),
(Hash::ZERO, Label::SOME, Description::SOME, Size::SOME),
(Hash::ZERO, Label::NONE, Description::NONE, Bytes::NONE),
(Hash::ZERO, Label::NONE, Description::NONE, Bytes::SOME),
(Hash::ZERO, Label::NONE, Description::SOME, Bytes::SOME),
(Hash::ZERO, Label::SOME, Description::SOME, Bytes::SOME),
],
)]
#[tokio::test]
async fn test_datastore_oracle_transition(
with_admin_layer: bool,
with_writer_layer: bool,
meta: (Hash, Label, Description, Size),
meta: (Hash, Label, Description, Bytes),
) -> anyhow::Result<()> {
let sim = Simulator::new().await?;
let peer = sim.connect().await?;
Expand Down Expand Up @@ -2073,7 +2073,7 @@ pub mod tests {
root_hash: meta.0.value(),
label: meta.1.value(),
description: meta.2.value(),
size: meta.3.value(),
bytes: meta.3.value(),
},
owner_puzzle_hash: owner_puzzle_hash.into(),
delegated_puzzles: delegated_puzzles.clone(),
Expand Down Expand Up @@ -2125,8 +2125,10 @@ pub mod tests {
ctx.spend_p2_coin(
new_coin,
dude_pk,
Conditions::new()
.assert_puzzle_announcement(src_datastore_info.coin.puzzle_hash, &Bytes::new("$".into())),
Conditions::new().assert_puzzle_announcement(
src_datastore_info.coin.puzzle_hash,
&OgBytes::new("$".into()),
),
)?;

// asserts
Expand Down Expand Up @@ -2241,16 +2243,16 @@ pub mod tests {
with_writer_layer => [true, false],
with_oracle_layer => [true, false],
meta => [
(Hash::ZERO, Label::NONE, Description::NONE, Size::NONE),
(Hash::ZERO, Label::SOME, Description::SOME, Size::SOME),
(Hash::ZERO, Label::NONE, Description::NONE, Bytes::NONE),
(Hash::ZERO, Label::SOME, Description::SOME, Bytes::SOME),
],
)]
#[tokio::test]
async fn test_melt(
with_admin_layer: bool,
with_writer_layer: bool,
with_oracle_layer: bool,
meta: (Hash, Label, Description, Size),
meta: (Hash, Label, Description, Bytes),
) -> anyhow::Result<()> {
let sim = Simulator::new().await?;
let peer = sim.connect().await?;
Expand Down Expand Up @@ -2296,7 +2298,7 @@ pub mod tests {
root_hash: meta.0.value(),
label: meta.1.value(),
description: meta.2.value(),
size: meta.3.value(),
bytes: meta.3.value(),
},
owner_puzzle_hash: owner_puzzle_hash.into(),
delegated_puzzles: delegated_puzzles.clone(),
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ pub fn new_eve_proof(eve_proof: EveProof) -> Proof {
/// @property {Buffer} rootHash - Root hash.
/// @property {Option<String>} label - Label (optional).
/// @property {Option<String>} description - Description (optional).
/// @property {Option<BigInt>} size - Size of the store (optional).
/// @property {Option<BigInt>} bytes - Size of the store in bytes (optional).
pub struct DataStoreMetadata {
pub root_hash: Buffer,
pub label: Option<String>,
pub description: Option<String>,
pub size: Option<BigInt>,
pub bytes: Option<BigInt>,
}

impl FromJS<DataStoreMetadata> for RustDataStoreMetadata {
Expand All @@ -350,7 +350,7 @@ impl FromJS<DataStoreMetadata> for RustDataStoreMetadata {
root_hash: RustBytes32::from_js(value.root_hash),
label: value.label,
description: value.description,
size: value.size.map(|s| u64::from_js(s)),
bytes: value.bytes.map(|s| u64::from_js(s)),
}
}
}
Expand All @@ -361,7 +361,7 @@ impl ToJS<DataStoreMetadata> for RustDataStoreMetadata {
root_hash: self.root_hash.to_js(),
label: self.label.clone(),
description: self.description.clone(),
size: self.size.map(|s| s.to_js()),
bytes: self.bytes.map(|s| s.to_js()),
}
}
}
Expand Down Expand Up @@ -851,7 +851,7 @@ pub fn select_coins(all_coins: Vec<Coin>, total_amount: BigInt) -> napi::Result<
/// @param {Buffer} rootHash - Root hash of the store.
/// @param {Option<String>} label - Store label (optional).
/// @param {Option<String>} description - Store description (optional).
/// @param {Option<BigInt>} size - Store size (optional).
/// @param {Option<BigInt>} bytes - Store size in bytes (optional).
/// @param {Buffer} ownerPuzzleHash - Owner puzzle hash.
/// @param {Vec<DelegatedPuzzle>} delegatedPuzzles - Delegated puzzles.
/// @param {BigInt} fee - Fee to use for the transaction. Total amount - 1 - fee will be sent back to the minter.
Expand All @@ -862,7 +862,7 @@ pub fn mint_store(
root_hash: Buffer,
label: Option<String>,
description: Option<String>,
size: Option<BigInt>,
bytes: Option<BigInt>,
owner_puzzle_hash: Buffer,
delegated_puzzles: Vec<DelegatedPuzzle>,
fee: BigInt,
Expand All @@ -876,7 +876,7 @@ pub fn mint_store(
RustBytes32::from_js(root_hash),
label,
description,
size.map(|s| u64::from_js(s)),
bytes.map(|s| u64::from_js(s)),
RustBytes32::from_js(owner_puzzle_hash),
delegated_puzzles
.iter()
Expand Down Expand Up @@ -1113,7 +1113,7 @@ pub fn get_coin_id(coin: Coin) -> Buffer {
/// @param {Buffer} newRootHash - New root hash.
/// @param {Option<String>} newLabel - New label (optional).
/// @param {Option<String>} newDescription - New description (optional).
/// @param {Option<BigInt>} newSize - New size (optional).
/// @param {Option<BigInt>} newBytes - New size in bytes (optional).
/// @param {Option<Buffer>} ownerPublicKey - Owner public key.
/// @param {Option<Buffer>} adminPublicKey - Admin public key.
/// @param {Option<Buffer>} writerPublicKey - Writer public key.
Expand All @@ -1123,7 +1123,7 @@ pub fn update_store_metadata(
new_root_hash: Buffer,
new_label: Option<String>,
new_description: Option<String>,
new_size: Option<BigInt>,
new_bytes: Option<BigInt>,
owner_public_key: Option<Buffer>,
admin_public_key: Option<Buffer>,
writer_public_key: Option<Buffer>,
Expand All @@ -1150,7 +1150,7 @@ pub fn update_store_metadata(
RustBytes32::from_js(new_root_hash),
new_label,
new_description,
new_size.map(|s| u64::from_js(s)),
new_bytes.map(|s| u64::from_js(s)),
inner_spend_info,
)
.map_err(js)?;
Expand Down
Loading

0 comments on commit f474f52

Please sign in to comment.