Skip to content

Commit

Permalink
[transaction tests] Hopefully complete support. Migrated more tests. (M…
Browse files Browse the repository at this point in the history
…ystenLabs#1885)

* [transaction tests] Hopefully complete support. Migrated more tests.

- Added support for viewing objects
- Migrated two more adapter tests

* fixup! [transaction tests] Hopefully complete support. Migrated more tests.
  • Loading branch information
tnowacki authored May 10, 2022
1 parent 5ff6899 commit 119832d
Show file tree
Hide file tree
Showing 13 changed files with 564 additions and 344 deletions.
134 changes: 134 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ members = [
"sui/open_rpc/macros",
"sui_core",
"sui_programmability/adapter",
"sui_programmability/adapter/transactional-tests",
"sui_programmability/framework",
"sui_programmability/transactional-test-runner",
"sui_programmability/verifier",
"sui_types",
"test_utils",
Expand Down
96 changes: 0 additions & 96 deletions sui_programmability/adapter/src/unit_tests/adapter_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,62 +848,6 @@ fn publish_from_src(
)
}

#[test]
fn test_simple_call() {
let native_functions =
sui_framework::natives::all_natives(MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS);
let genesis_objects = genesis::clone_genesis_packages();
let mut storage = InMemoryStorage::new(genesis_objects);

// create gas object for payment
let gas_object =
Object::with_id_owner_for_testing(ObjectID::random(), base_types::SuiAddress::default());

// publish modules at a given path
publish_from_src(
&mut storage,
&native_functions,
"src/unit_tests/data/simple_call",
gas_object,
GAS_BUDGET,
)
.unwrap();
storage.flush();

// call published module function
let obj_val = 42u64;

let addr = base_types::get_new_address();
let pure_args = vec![
obj_val.to_le_bytes().to_vec(),
bcs::to_bytes(&AccountAddress::from(addr)).unwrap(),
];

call(
&mut storage,
&native_functions,
"M1",
"create",
GAS_BUDGET,
Vec::new(),
Vec::new(),
pure_args,
)
.unwrap();

// check if the object was created and if it has the right value
let id = storage.get_created_keys().pop().unwrap();
storage.flush();
let obj = storage.read_object(&id).unwrap();
assert!(obj.owner == addr);
assert_eq!(obj.version(), SequenceNumber::from(1));
let move_obj = obj.data.try_as_move().unwrap();
assert_eq!(
u64::from_le_bytes(move_obj.type_specific_contents().try_into().unwrap()),
obj_val
);
}

#[test]
fn test_child_of_shared_object() {
// TODO: Also add test cases where there are circular dependencies in the input.
Expand Down Expand Up @@ -1008,43 +952,3 @@ fn test_child_of_shared_object() {
)
.unwrap();
}

#[test]
/// Tests publishing of a module with a constructor that creates a
/// single object with a single u64 value 42.
fn test_publish_init() {
let native_functions =
sui_framework::natives::all_natives(MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS);
let genesis_objects = genesis::clone_genesis_packages();
let mut storage = InMemoryStorage::new(genesis_objects);

// create gas object for payment
let gas_object =
Object::with_id_owner_for_testing(ObjectID::random(), base_types::SuiAddress::default());

// publish modules at a given path
publish_from_src(
&mut storage,
&native_functions,
"src/unit_tests/data/publish_init",
gas_object,
GAS_BUDGET,
)
.unwrap();

// a package object and a fresh object in the constructor should
// have been created
assert_eq!(storage.created().len(), 2);
let to_check = mem::take(&mut storage.temporary.created);
let mut move_obj_exists = false;
for o in to_check.values() {
if let Data::Move(move_obj) = &o.data {
move_obj_exists = true;
assert_eq!(
u64::from_le_bytes(move_obj.type_specific_contents().try_into().unwrap()),
42u64
);
}
}
assert!(move_obj_exists);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
processed 4 tasks

task 1 'publish'. lines 6-28:
created: object(103)
written: object(102)

task 2 'run'. lines 30-30:
created: object(105)
written: object(104)

task 3 'view-object'. lines 32-32:
Owner: Account Address ( A )
Contents: Test::M1::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(105)}}, version: 1u64}, value: 0u64}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --addresses Test=0x0 A=0x42

//# publish
module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand All @@ -23,3 +26,7 @@ module Test::M1 {
)
}
}

//# run Test::M1::create --args 0 @A

//# view-object 105
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
processed 4 tasks

task 1 'publish'. lines 6-23:
created: object(103), object(104)
written: object(102)

task 2 'view-object'. lines 25-25:
Owner: Account Address ( _ )
Contents: Test::M1::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(104)}}, version: 1u64}, value: 42u64}

task 3 'view-object'. lines 27-27:
103::M1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --addresses Test=0x0

//# publish
module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand All @@ -18,3 +21,7 @@ module Test::M1 {
Transfer::transfer(singleton, TxContext::sender(ctx))
}
}

//# view-object 104

//# view-object 103
1 change: 1 addition & 0 deletions sui_programmability/transactional-test-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ hex = "0.4.3"
itertools = "0.10.3"
once_cell = "1.7.2"
regex = "1.1.9"
rand = "0.7.3"
rayon = "1.5.0"
tempfile = "3.2.0"

Expand Down
Loading

0 comments on commit 119832d

Please sign in to comment.