Skip to content

Commit

Permalink
use 1 as cache weight for all cache items
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 30, 2024
1 parent f17410f commit 1ab2947
Show file tree
Hide file tree
Showing 26 changed files with 123 additions and 1,712 deletions.
16 changes: 12 additions & 4 deletions crates/e2e-move-tests/src/tests/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fn success_generic(ty_args: Vec<TypeTag>, tests: Vec<TestInput>) {
h.initialize();

// publish package
let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

// Check in initial state, resource does not exist.
Expand Down Expand Up @@ -75,7 +77,9 @@ fn fail_generic(ty_args: Vec<TypeTag>, tests: Vec<(&str, Vec<Vec<u8>>, StatusCod
h.initialize();

// publish package
let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

// Check in initial state, resource does not exist.
Expand Down Expand Up @@ -750,7 +754,9 @@ fn json_object_args() {
h.initialize();

// publish package
let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

// execute create_object
Expand Down Expand Up @@ -795,7 +801,9 @@ fn biguint_bigdecimal() {
h.initialize();

// publish package
let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

// execute create_object
Expand Down
69 changes: 54 additions & 15 deletions crates/e2e-move-tests/src/tests/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,43 @@ fn setup_harness() -> (MoveHarness, AccountAddress) {
(h, acc)
}

fn publish_and_commit(h: &mut MoveHarness, acc: &AccountAddress, path: &str, policy: UpgradePolicy) {
let output = h.publish_package(acc, path, policy).expect("should succeed");
fn publish_and_commit(
h: &mut MoveHarness,
acc: &AccountAddress,
path: &str,
policy: UpgradePolicy,
) {
let output = h
.publish_package(acc, path, policy)
.expect("should succeed");
h.commit(output, true);
}

fn view_string(h: &mut MoveHarness, path: &str) -> String {
let view_function = h.create_view_function(
str::parse(path).unwrap(),
vec![],
vec![],
);
let view_function = h.create_view_function(str::parse(path).unwrap(), vec![], vec![]);

h.run_view_function(view_function).expect("should succeed")
}

#[test]
fn test_simple_publish_compatible() {
let (mut h, acc) = setup_harness();
publish_and_commit(&mut h, &acc, "src/tests/string_viewer.data/viewer", UpgradePolicy::Compatible);
publish_and_commit(
&mut h,
&acc,
"src/tests/string_viewer.data/viewer",
UpgradePolicy::Compatible,
);

let view_output = view_string(&mut h, "0x9999::string_viewer::view_string");
assert_eq!("\"Hello, World!\"".to_string(), view_output);

publish_and_commit(&mut h, &acc, "src/tests/string_viewer.data/viewer2", UpgradePolicy::Compatible);
publish_and_commit(
&mut h,
&acc,
"src/tests/string_viewer.data/viewer2",
UpgradePolicy::Compatible,
);

let view_output = view_string(&mut h, "0x9999::string_viewer2::view_my_string");
assert_eq!("\"Hello, World!\"".to_string(), view_output);
Expand All @@ -41,12 +54,22 @@ fn test_simple_publish_compatible() {
#[test]
fn test_simple_publish_immutable() {
let (mut h, acc) = setup_harness();
publish_and_commit(&mut h, &acc, "src/tests/string_viewer.data/viewer", UpgradePolicy::Immutable);
publish_and_commit(
&mut h,
&acc,
"src/tests/string_viewer.data/viewer",
UpgradePolicy::Immutable,
);

let view_output = view_string(&mut h, "0x9999::string_viewer::view_string");
assert_eq!("\"Hello, World!\"".to_string(), view_output);

publish_and_commit(&mut h, &acc, "src/tests/string_viewer.data/viewer2", UpgradePolicy::Immutable);
publish_and_commit(
&mut h,
&acc,
"src/tests/string_viewer.data/viewer2",
UpgradePolicy::Immutable,
);

let view_output = view_string(&mut h, "0x9999::string_viewer2::view_my_string");
assert_eq!("\"Hello, World!\"".to_string(), view_output);
Expand All @@ -55,24 +78,40 @@ fn test_simple_publish_immutable() {
#[test]
fn test_publish_immutable_referring_compatible() {
let (mut h, acc) = setup_harness();
publish_and_commit(&mut h, &acc, "src/tests/string_viewer.data/viewer", UpgradePolicy::Compatible);
publish_and_commit(
&mut h,
&acc,
"src/tests/string_viewer.data/viewer",
UpgradePolicy::Compatible,
);

let view_output = view_string(&mut h, "0x9999::string_viewer::view_string");
assert_eq!("\"Hello, World!\"".to_string(), view_output);

let path = "src/tests/string_viewer.data/viewer2";
h.publish_package(&acc, path, UpgradePolicy::Immutable).expect_err("expected an error during package publishing");
h.publish_package(&acc, path, UpgradePolicy::Immutable)
.expect_err("expected an error during package publishing");
}

#[test]
fn test_publish_compatible_referring_immutable() {
let (mut h, acc) = setup_harness();
publish_and_commit(&mut h, &acc, "src/tests/string_viewer.data/viewer", UpgradePolicy::Immutable);
publish_and_commit(
&mut h,
&acc,
"src/tests/string_viewer.data/viewer",
UpgradePolicy::Immutable,
);

let view_output = view_string(&mut h, "0x9999::string_viewer::view_string");
assert_eq!("\"Hello, World!\"".to_string(), view_output);

publish_and_commit(&mut h, &acc, "src/tests/string_viewer.data/viewer2", UpgradePolicy::Compatible);
publish_and_commit(
&mut h,
&acc,
"src/tests/string_viewer.data/viewer2",
UpgradePolicy::Compatible,
);

let view_output = view_string(&mut h, "0x9999::string_viewer2::view_my_string");
assert_eq!("\"Hello, World!\"".to_string(), view_output);
Expand Down
4 changes: 3 additions & 1 deletion crates/e2e-move-tests/src/tests/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ fn run_tests(tests: Vec<TestInput>) {
h.initialize();

// publish package
let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

for (sender, entry, ty_args, args, exp_output) in tests {
Expand Down
4 changes: 3 additions & 1 deletion crates/e2e-move-tests/src/tests/infinite_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ fn empty_while_loop() {

h.initialize();

let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

let err = h
Expand Down
8 changes: 6 additions & 2 deletions crates/e2e-move-tests/src/tests/max_loop_depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ fn module_loop_depth_at_limit() {
let mut h = MoveHarness::new();

h.initialize();
let _ = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let _ = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
}

#[test]
Expand All @@ -18,6 +20,8 @@ fn module_loop_depth_just_above_limit() {
let path = "src/tests/max_loop_depth.data/pack-bad";
let mut h = MoveHarness::new();
h.initialize();
let status = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect_err("should error");
let status = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect_err("should error");
assert!(status.status_code() == StatusCode::LOOP_MAX_DEPTH_REACHED);
}
8 changes: 6 additions & 2 deletions crates/e2e-move-tests/src/tests/memory_quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ fn clone_large_vectors() {
let mut h = MoveHarness::new();

h.initialize();
let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

let _ = h
Expand Down Expand Up @@ -42,7 +44,9 @@ fn add_vec_to_table() {

// Load the code
h.initialize();
let output = h.publish_package(&acc, path, UpgradePolicy::Compatible).expect("should success");
let output = h
.publish_package(&acc, path, UpgradePolicy::Compatible)
.expect("should success");
h.commit(output, true);

let status = h
Expand Down
14 changes: 7 additions & 7 deletions crates/json/src/json_to_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ pub trait StructResolver {
index: StructNameIndex,
module_storage: &impl ModuleStorage,
) -> Option<Arc<StructType>>;
fn type_to_type_tag(
&self,
ty: &Type,
module_storage: &impl ModuleStorage,
) -> VMResult<TypeTag>;
fn type_to_type_tag(&self, ty: &Type, module_storage: &impl ModuleStorage)
-> VMResult<TypeTag>;
}

// deserialize json argument to JSONValue and convert to MoveValue,
Expand Down Expand Up @@ -395,7 +392,8 @@ mod json_arg_testing {
Struct { idx, .. } => {
let struct_ty =
self.get_struct_type(*idx, module_storage).ok_or_else(|| {
PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR).finish(Location::Undefined)
PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
.finish(Location::Undefined)
})?;
Ok(TypeTag::Struct(Box::new(StructTag {
address: struct_ty.module.address,
Expand All @@ -404,7 +402,9 @@ mod json_arg_testing {
type_args: vec![],
})))
}
_ => Err(PartialVMError::new(StatusCode::TYPE_MISMATCH).finish(Location::Undefined)),
_ => {
Err(PartialVMError::new(StatusCode::TYPE_MISMATCH).finish(Location::Undefined))
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/natives/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ fn native_request_publish(

context.charge(gas_params.code_request_publish_base_cost)?;

let upgrade_policy = UpgradePolicy::try_from(safely_pop_arg!(arguments, u8))
.map_err(|_| SafeNativeError::Abort { abort_code: EINVALID_UPGRADE_POLICY})?;
let upgrade_policy = UpgradePolicy::try_from(safely_pop_arg!(arguments, u8)).map_err(|_| {
SafeNativeError::Abort {
abort_code: EINVALID_UPGRADE_POLICY,
}
})?;

let mut code: Vec<Vec<u8>> = vec![];
for module_code in safely_pop_vec_arg!(arguments, Vec<u8>) {
Expand Down
Loading

0 comments on commit 1ab2947

Please sign in to comment.