Skip to content

Commit

Permalink
[move] introduce Sui variant of CompiledPackage
Browse files Browse the repository at this point in the history
- Add a Sui wrapper around the Move CompiledPackage so we can add extra metadata and traits
- Use this to clean up the build API's, which previously made it very hard for clients to get a package and led to a lot of code duplication
- Did this because I'm looking at generating Move struct layout files to be consumed by SDK's like the TS SDK, but was finding it hard to get my hands on the package object
  • Loading branch information
sblackshear committed Oct 27, 2022
1 parent a9f4f60 commit 9cdec4f
Show file tree
Hide file tree
Showing 22 changed files with 419 additions and 355 deletions.
14 changes: 6 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/sui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ sui-macros = { path = "../sui-macros" }
[dev-dependencies]
clap = { version = "3.2.17", features = ["derive"] }
rand = "0.8.5"
move-package.workspace = true

serde-reflection = "0.3.6"
serde_yaml = "0.8.26"
pretty_assertions = "1.2.1"
telemetry-subscribers.workspace = true

sui-framework-build = { path = "../sui-framework-build" }
sui-macros = { path = "../sui-macros" }

test-fuzz = "3.0.4"
Expand Down
16 changes: 13 additions & 3 deletions crates/sui-core/src/unit_tests/authority_aggregator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

use bcs::to_bytes;
use move_core_types::{account_address::AccountAddress, ident_str};
use move_package::BuildConfig;
use multiaddr::Multiaddr;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use sui_config::genesis::Genesis;
use sui_config::ValidatorInfo;
use sui_framework_build::compiled_package::BuildConfig;
use sui_network::{DEFAULT_CONNECT_TIMEOUT_SEC, DEFAULT_REQUEST_TIMEOUT_SEC};
use sui_types::crypto::{
generate_proof_of_possession, get_authority_key_pair, get_key_pair, AccountKeyPair,
Expand Down Expand Up @@ -80,7 +80,12 @@ pub async fn init_local_authorities(
let build_config = BuildConfig::default();
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("src/unit_tests/data/object_basics");
let modules = sui_framework::build_move_package(&path, build_config).unwrap();
let modules = sui_framework::build_move_package(&path, build_config)
.unwrap()
.get_modules()
.into_iter()
.cloned()
.collect();
let pkg = Object::new_package(modules, TransactionDigest::genesis());
let pkg_ref = pkg.compute_object_reference();
genesis_objects.push(pkg);
Expand Down Expand Up @@ -436,7 +441,12 @@ async fn test_quorum_map_and_reduce_timeout() {
let build_config = BuildConfig::default();
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("src/unit_tests/data/object_basics");
let modules = sui_framework::build_move_package(&path, build_config).unwrap();
let modules = sui_framework::build_move_package(&path, build_config)
.unwrap()
.get_modules()
.into_iter()
.cloned()
.collect();
let pkg = Object::new_package(modules, TransactionDigest::genesis());
let pkg_ref = pkg.compute_object_reference();
let (addr1, key1): (_, AccountKeyPair) = get_key_pair();
Expand Down
11 changes: 8 additions & 3 deletions crates/sui-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ pub async fn init_state_with_ids_and_object_basics<
>(
objects: I,
) -> (AuthorityState, ObjectRef) {
use move_package::BuildConfig;
use sui_framework_build::compiled_package::BuildConfig;

let state = init_state().await;
for (address, object_id) in objects {
Expand All @@ -2040,10 +2040,15 @@ pub async fn init_state_with_ids_and_object_basics<
}

// add object_basics package object to genesis, since lots of test use it
let build_config = BuildConfig::default();
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("src/unit_tests/data/object_basics");
let modules = sui_framework::build_move_package(&path, build_config).unwrap();
let modules = BuildConfig::default()
.build(path)
.unwrap()
.get_modules()
.into_iter()
.cloned()
.collect();
let pkg = Object::new_package(modules, TransactionDigest::genesis());
let pkg_ref = pkg.compute_object_reference();
state.insert_genesis_object(pkg).await;
Expand Down
15 changes: 9 additions & 6 deletions crates/sui-core/src/unit_tests/gateway_state_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use move_package::BuildConfig;
use serde_json::json;
use std::{collections::HashSet, path::Path};

use signature::Signer;
use typed_store::Map;

use sui_framework::build_move_package_to_bytes;
use sui_framework_build::compiled_package::BuildConfig;
use sui_types::crypto::{AccountKeyPair, Signature};
use sui_types::gas_coin::GasCoin;
use sui_types::messages::Transaction;
Expand Down Expand Up @@ -145,8 +144,10 @@ async fn test_publish() {
let mut path = env!("CARGO_MANIFEST_DIR").to_owned();
path.push_str("/src/unit_tests/data/object_owner/");

let compiled_modules =
build_move_package_to_bytes(Path::new(&path), BuildConfig::default()).unwrap();
let compiled_modules = BuildConfig::default()
.build(Path::new(&path).to_path_buf())
.unwrap()
.get_package_bytes();
let data = gateway
.publish(
addr1,
Expand Down Expand Up @@ -521,8 +522,10 @@ async fn test_get_owner_object() {
path.push_str("/src/unit_tests/data/object_owner/");

// Publish object_owner package
let compiled_modules =
build_move_package_to_bytes(Path::new(&path), BuildConfig::default()).unwrap();
let compiled_modules = BuildConfig::default()
.build(Path::new(&path).to_path_buf())
.unwrap()
.get_package_bytes();
let data = gateway
.publish(
addr1,
Expand Down
15 changes: 4 additions & 11 deletions crates/sui-core/src/unit_tests/move_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use move_core_types::{
language_storage::TypeTag,
value::{MoveStruct, MoveValue},
};
use move_package::BuildConfig;
use sui_framework_build::compiled_package::BuildConfig;
use sui_types::{
crypto::{get_key_pair, AccountKeyPair},
event::{Event, EventType, TransferType},
Expand Down Expand Up @@ -1836,16 +1836,9 @@ pub async fn build_and_try_publish_test_package(
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("src/unit_tests/data/");
path.push(test_dir);
let modules = sui_framework::build_move_package(&path, build_config).unwrap();

let all_module_bytes = modules
.iter()
.map(|m| {
let mut module_bytes = Vec::new();
m.serialize(&mut module_bytes).unwrap();
module_bytes
})
.collect();
let all_module_bytes = sui_framework::build_move_package(&path, build_config)
.unwrap()
.get_package_bytes();

let gas_object = authority.get_object(gas_object_id).await.unwrap();
let gas_object_ref = gas_object.unwrap().compute_object_reference();
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
publish = false

[dependencies]

anyhow = { version = "1.0.64", features = ["backtrace"] }
once_cell = "1.14.0"

sui-types = { path = "../sui-types" }
Expand Down
Loading

0 comments on commit 9cdec4f

Please sign in to comment.