Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Aug 16, 2024
1 parent 1da84e0 commit 020d4a5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 49 deletions.
2 changes: 1 addition & 1 deletion dan_layer/engine/tests/shenanigans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn it_rejects_unknown_substate_addresses() {
);

assert_reject_reason(reason, RuntimeError::ReferencedSubstateNotFound {
address: ResourceAddress::from_hex("abababababababababababababababababababababababababababab")
address: ResourceAddress::from_hex("abababababababababababababababababababababababababababababababab")
.unwrap()
.into(),
})
Expand Down
8 changes: 2 additions & 6 deletions dan_layer/engine/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn test_buggy_template() {
.unwrap_err();
assert!(matches!(
err,
TemplateLoaderError::WasmModuleError(WasmExecutionError::AbiDecodeError { .. })
TemplateLoaderError::WasmModuleError(WasmExecutionError::MemoryPointerOutOfRange { .. })
));

let err = compile_template("tests/templates/buggy", &["unexpected_export_function"])
Expand Down Expand Up @@ -238,7 +238,7 @@ fn test_engine_errors() {
assert_eq!(
reason,
"Runtime error: Substate not found with address \
'resource_7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b'"
'resource_7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b'"
);
}

Expand Down Expand Up @@ -334,7 +334,6 @@ fn test_errors_on_infinite_loop() {
}

mod errors {

use super::*;

#[test]
Expand Down Expand Up @@ -392,7 +391,6 @@ mod errors {
}

mod consensus {

use super::*;

#[test]
Expand Down Expand Up @@ -909,7 +907,6 @@ mod basic_nft {
}

mod emoji_id {

use serde::{Deserialize, Serialize};

use super::*;
Expand Down Expand Up @@ -1102,7 +1099,6 @@ mod emoji_id {
}

mod tickets {

use serde::{Deserialize, Serialize};

use super::*;
Expand Down
21 changes: 12 additions & 9 deletions dan_layer/engine_types/src/argument_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,17 @@ mod tests {
assert_eq!(args, from_str);

// Deserialize from special string representation
let some_args: SomeArgs =
json::from_str(r#"{"args": ["component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d"] }"#)
.unwrap();
let some_args: SomeArgs = json::from_str(
r#"{"args": ["component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff"] }"#,
)
.unwrap();
match &some_args.args[0] {
Arg::Workspace(_) => panic!(),
Arg::Literal(a) => {
let a: ComponentAddress = decode_exact(a).unwrap();
assert_eq!(
a.to_string(),
"component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d"
"component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff"
);
},
}
Expand Down Expand Up @@ -305,8 +306,10 @@ mod tests {
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect(),
opt: Some(
ComponentAddress::from_str("component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d")
.unwrap(),
ComponentAddress::from_str(
"component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff",
)
.unwrap(),
),
};

Expand Down Expand Up @@ -366,9 +369,9 @@ mod tests {
#[test]
fn it_parses_addresses() {
let cases = &[
"component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d",
"resource_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d",
"vault_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d",
"component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff",
"resource_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff",
"vault_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff",
];

for case in cases {
Expand Down
55 changes: 29 additions & 26 deletions dan_layer/engine_types/src/substate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ pub enum SubstateId {
Component(#[serde(with = "serde_with::string")] ComponentAddress),
Resource(#[serde(with = "serde_with::string")] ResourceAddress),
Vault(#[serde(with = "serde_with::string")] VaultId),
UnclaimedConfidentialOutput(#[cfg_attr(feature = "ts", ts(type = "string"))] UnclaimedConfidentialOutputAddress),
UnclaimedConfidentialOutput(#[cfg_attr(
feature = "ts",
ts(type = "string")
)] UnclaimedConfidentialOutputAddress),
NonFungible(#[serde(with = "serde_with::string")] NonFungibleAddress),
NonFungibleIndex(NonFungibleIndexAddress),
TransactionReceipt(TransactionReceiptAddress),
Expand Down Expand Up @@ -318,7 +321,7 @@ impl FromStr for SubstateId {
Some(("component", addr)) => {
let addr = ComponentAddress::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(s.to_string()))?;
Ok(SubstateId::Component(addr))
},
}
Some(("resource", addr)) => {
match addr.split_once(' ') {
Some((resource_str, addr)) => match addr.split_once('_') {
Expand All @@ -327,7 +330,7 @@ impl FromStr for SubstateId {
let nft_address =
NonFungibleAddress::from_str(s).map_err(|e| InvalidSubstateIdFormat(e.to_string()))?;
Ok(SubstateId::NonFungible(nft_address))
},
}
// resource_xxxx index_
Some(("index", index_str)) => {
let resource_addr = ResourceAddress::from_hex(resource_str)
Expand All @@ -337,35 +340,35 @@ impl FromStr for SubstateId {
resource_addr,
index,
)))
},
}
_ => Err(InvalidSubstateIdFormat(s.to_string())),
},
// resource_xxxx
None => {
let addr =
ResourceAddress::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(s.to_string()))?;
Ok(SubstateId::Resource(addr))
},
}
}
},
}
Some(("vault", addr)) => {
let id = VaultId::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(s.to_string()))?;
Ok(SubstateId::Vault(id))
},
}
Some(("commitment", addr)) => {
let commitment_address = UnclaimedConfidentialOutputAddress::from_hex(addr)
.map_err(|_| InvalidSubstateIdFormat(s.to_string()))?;
Ok(SubstateId::UnclaimedConfidentialOutput(commitment_address))
},
}
Some(("txreceipt", addr)) => {
let tx_receipt_addr =
TransactionReceiptAddress::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(addr.to_string()))?;
Ok(SubstateId::TransactionReceipt(tx_receipt_addr))
},
}
Some(("feeclaim", addr)) => {
let addr = Hash::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(addr.to_string()))?;
Ok(SubstateId::FeeClaim(addr.into()))
},
}
Some(_) | None => Err(InvalidSubstateIdFormat(s.to_string())),
}
}
Expand Down Expand Up @@ -614,7 +617,7 @@ impl Display for SubstateValue {
// TODO: improve output
match self {
SubstateValue::Component(component) => write!(f, "{:?}", component.state()),
SubstateValue::Resource(resource) => write!(f, "{:?}", resource,),
SubstateValue::Resource(resource) => write!(f, "{:?}", resource, ),
SubstateValue::Vault(vault) => write!(f, "{:?}", vault),
SubstateValue::NonFungible(nft) => write!(f, "{:?}", nft),
SubstateValue::NonFungibleIndex(index) => write!(f, "{:?}", index),
Expand Down Expand Up @@ -648,15 +651,15 @@ impl SubstateDiff {
self.down_substates.push((address, version));
}

pub fn up_iter(&self) -> impl Iterator<Item = &(SubstateId, Substate)> + '_ {
pub fn up_iter(&self) -> impl Iterator<Item=&(SubstateId, Substate)> + '_ {
self.up_substates.iter()
}

pub fn into_up_iter(self) -> impl Iterator<Item = (SubstateId, Substate)> {
pub fn into_up_iter(self) -> impl Iterator<Item=(SubstateId, Substate)> {
self.up_substates.into_iter()
}

pub fn down_iter(&self) -> impl Iterator<Item = &(SubstateId, u32)> + '_ {
pub fn down_iter(&self) -> impl Iterator<Item=&(SubstateId, u32)> + '_ {
self.down_substates.iter()
}

Expand Down Expand Up @@ -686,32 +689,32 @@ mod tests {

#[test]
fn it_parses_valid_substate_addresses() {
SubstateId::from_str("component_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5")
SubstateId::from_str("component_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff")
.unwrap()
.as_component_address()
.unwrap();
SubstateId::from_str("vault_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5")
SubstateId::from_str("vault_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff")
.unwrap()
.as_vault_id()
.unwrap();
SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5")
SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff")
.unwrap()
.as_resource_address()
.unwrap();
SubstateId::from_str(
"resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5 nft_str:SpecialNft",
"resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff nft_str:SpecialNft",
)
.unwrap()
.as_non_fungible_address()
.unwrap();
.unwrap()
.as_non_fungible_address()
.unwrap();
SubstateId::from_str(
"resource_a7cf4fd18ada7f367b1c102a9c158abc3754491665033231c5eb907f \
"resource_a7cf4fd18ada7f367b1c102a9c158abc3754491665033231c5eb907fffffffff \
nft_uuid:7f19c3fe5fa13ff66a0d379fe5f9e3508acbd338db6bedd7350d8d565b2c5d32",
)
.unwrap()
.as_non_fungible_address()
.unwrap();
SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5 index_0")
.unwrap()
.as_non_fungible_address()
.unwrap();
SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff index_0")
.unwrap()
.as_non_fungible_index_address()
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/template_lib/src/models/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod tests {

#[test]
fn string_serialization_and_deserialization() {
let resx_str = "resource_00000000000000000000000000000000000000000000000000000000";
let resx_str = "resource_0000000000000000000000000000000000000000000000000000000000000000";
let resource = ResourceAddress::from_str(resx_str).unwrap();
let json = serde_json::to_string_pretty(&resource).unwrap();
assert_eq!(json.trim_matches('"'), resx_str);
Expand Down
14 changes: 8 additions & 6 deletions dan_layer/transaction_manifest/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,34 @@ mod tests {

#[test]
fn it_parses_address_strings() {
let addr = "component_00000000000000000000000000000000000000000000000000000000"
let addr = "component_0000000000000000000000000000000000000000000000000000000000000000"
.parse::<ManifestValue>()
.unwrap();
assert_eq!(
*addr.as_address().unwrap(),
SubstateId::Component(
ComponentAddress::from_hex("00000000000000000000000000000000000000000000000000000000").unwrap()
ComponentAddress::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap()
)
);

let addr = "resource_00000000000000000000000000000000000000000000000000000000"
let addr = "resource_0000000000000000000000000000000000000000000000000000000000000000"
.parse::<ManifestValue>()
.unwrap();
assert_eq!(
*addr.as_address().unwrap(),
SubstateId::Resource(
ResourceAddress::from_hex("00000000000000000000000000000000000000000000000000000000").unwrap()
ResourceAddress::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap()
)
);

let addr = "vault_00000000000000000000000000000000000000000000000000000000"
let addr = "vault_0000000000000000000000000000000000000000000000000000000000000000"
.parse::<ManifestValue>()
.unwrap();
assert_eq!(
*addr.as_address().unwrap(),
SubstateId::Vault(VaultId::from_hex("00000000000000000000000000000000000000000000000000000000").unwrap())
SubstateId::Vault(
VaultId::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap()
)
);
}
}

0 comments on commit 020d4a5

Please sign in to comment.