Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object Code Deployment module with CLI commands #11748

Merged
merged 12 commits into from
Feb 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub enum FeatureFlag {
JWKConsensus,
ConcurrentFungibleAssets,
RefundableBytes,
ObjectCodeDeployment,
}

fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
Expand Down Expand Up @@ -262,6 +263,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
FeatureFlag::JWKConsensus => AptosFeatureFlag::JWK_CONSENSUS,
FeatureFlag::ConcurrentFungibleAssets => AptosFeatureFlag::CONCURRENT_FUNGIBLE_ASSETS,
FeatureFlag::RefundableBytes => AptosFeatureFlag::REFUNDABLE_BYTES,
FeatureFlag::ObjectCodeDeployment => AptosFeatureFlag::OBJECT_CODE_DEPLOYMENT,
}
}
}
Expand Down Expand Up @@ -345,6 +347,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
AptosFeatureFlag::JWK_CONSENSUS => FeatureFlag::JWKConsensus,
AptosFeatureFlag::CONCURRENT_FUNGIBLE_ASSETS => FeatureFlag::ConcurrentFungibleAssets,
AptosFeatureFlag::REFUNDABLE_BYTES => FeatureFlag::RefundableBytes,
AptosFeatureFlag::OBJECT_CODE_DEPLOYMENT => FeatureFlag::ObjectCodeDeployment,
}
}
}
Expand Down
120 changes: 120 additions & 0 deletions aptos-move/e2e-move-tests/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,56 @@ impl MoveHarness {
)
}

/// Creates a transaction which publishes the passed already-built Move Package to an object,
/// on behalf of the given account.
///
/// The passed function allows to manipulate the generated metadata for testing purposes.
pub fn create_object_code_deployment_built_package(
&mut self,
account: &Account,
package: &BuiltPackage,
mut patch_metadata: impl FnMut(&mut PackageMetadata),
) -> SignedTransaction {
let code = package.extract_code();
let mut metadata = package
.extract_metadata()
.expect("extracting package metadata must succeed");
patch_metadata(&mut metadata);
self.create_transaction_payload(
account,
aptos_stdlib::object_code_deployment_publish(
bcs::to_bytes(&metadata).expect("PackageMetadata has BCS"),
code,
),
)
}

/// Creates a transaction which upgrades the passed already-built Move Package,
/// on behalf of the given account.
///
/// The passed function allows to manipulate the generated for testing purposes.
pub fn create_object_code_upgrade_built_package(
&mut self,
account: &Account,
package: &BuiltPackage,
mut patch_metadata: impl FnMut(&mut PackageMetadata),
publisher_ref: AccountAddress,
) -> SignedTransaction {
let code = package.extract_code();
let mut metadata = package
.extract_metadata()
.expect("extracting package metadata must succeed");
patch_metadata(&mut metadata);
self.create_transaction_payload(
account,
aptos_stdlib::object_code_deployment_upgrade(
bcs::to_bytes(&metadata).expect("PackageMetadata has BCS"),
code,
publisher_ref,
),
)
}

/// Creates a transaction which publishes the Move Package found at the given path on behalf
/// of the given account.
///
Expand All @@ -395,6 +445,36 @@ impl MoveHarness {
self.create_publish_built_package(account, &package, patch_metadata)
}

pub fn create_object_code_upgrade_package(
&mut self,
account: &Account,
path: &Path,
options: BuildOptions,
patch_metadata: impl FnMut(&mut PackageMetadata),
publisher_ref: AccountAddress,
) -> SignedTransaction {
let package =
build_package(path.to_owned(), options).expect("building package must succeed");
self.create_object_code_upgrade_built_package(
account,
&package,
patch_metadata,
publisher_ref,
)
}

pub fn create_object_code_deployment_package(
&mut self,
account: &Account,
path: &Path,
options: BuildOptions,
patch_metadata: impl FnMut(&mut PackageMetadata),
) -> SignedTransaction {
let package =
build_package(path.to_owned(), options).expect("building package must succeed");
self.create_object_code_deployment_built_package(account, &package, patch_metadata)
}

pub fn create_publish_package_cache_building(
&mut self,
account: &Account,
Expand Down Expand Up @@ -431,6 +511,46 @@ impl MoveHarness {
self.run(txn)
}

/// Runs the transaction which publishes the Move Package to an object.
pub fn object_code_deployment_package(
&mut self,
account: &Account,
path: &Path,
options: BuildOptions,
) -> TransactionStatus {
let txn = self.create_object_code_deployment_package(account, path, options, |_| {});
self.run(txn)
}

/// Creates a transaction which publishes the passed already-built Move Package to an object,
/// on behalf of the given account.
///
/// The passed function allows to manipulate the generated metadata for testing purposes.
pub fn object_code_upgrade_package(
&mut self,
account: &Account,
path: &Path,
options: BuildOptions,
publisher_ref: AccountAddress,
) -> TransactionStatus {
let txn =
self.create_object_code_upgrade_package(account, path, options, |_| {}, publisher_ref);
self.run(txn)
}

/// Marks all the packages in the `code_object` as immutable.
pub fn object_code_freeze_code_object(
&mut self,
account: &Account,
code_object: AccountAddress,
) -> TransactionStatus {
let txn = self.create_transaction_payload(
account,
aptos_stdlib::object_code_deployment_freeze_code_object(code_object),
);
self.run(txn)
}

pub fn evaluate_publish_gas(&mut self, account: &Account, path: &Path) -> u64 {
let txn = self.create_publish_package(account, path, None, |_| {});
let output = self.run_raw(txn);
Expand Down
1 change: 1 addition & 0 deletions aptos-move/e2e-move-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod missing_gas_parameter;
mod module_event;
mod new_integer_types;
mod nft_dao;
mod object_code_deployment;
mod offer_rotation_capability;
mod offer_signer_capability;
mod per_category_gas_limits;
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/tests/module_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn test_module_event_enabled() {
vec![bcs::to_bytes(&10u64).unwrap()],
);
let events = h.get_events();
assert_eq!(events.len(), 12);
assert_eq!(events.len(), 13);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because we emit PublishPackage event in code.move when a package gets published.

let my_event_tag = TypeTag::from_str("0xcafe::event::MyEvent").unwrap();
let mut count = 0;
for event in events.iter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_package"
version = "0.0.0"
upgrade_policy = "compatible"

[dependencies]
AptosFramework = { local = "../../../../../framework/aptos-framework" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module object::test {

struct State has key {
value: u64
}

public entry fun hello(s: &signer, value: u64) {
move_to(s, State { value })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_package"
version = "0.0.0"
upgrade_policy = "immutable"

[dependencies]
AptosFramework = { local = "../../../../../framework/aptos-framework" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module object::test {

struct State has key {
value: u64
}

public entry fun hello(s: &signer, value: u64) {
move_to(s, State { value })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "other_test_package"
version = "0.0.0"
upgrade_policy = "compatible"

[dependencies]
AptosFramework = { local = "../../../../../framework/aptos-framework" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module object::test {

struct State has key {
value: u64
}

public entry fun hello(s: &signer, value: u64) {
move_to(s, State { value })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_package"
version = "0.0.0"
upgrade_policy = "compatible"

[dependencies]
AptosFramework = { local = "../../../../../framework/aptos-framework" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module object::test {

struct State has key {
value: u64
}

public entry fun hello(s: &signer, value: u64) {
move_to(s, State { value })
}

public entry fun hello2(s: &signer, value: u64) {
move_to(s, State { value })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_package"
version = "0.0.0"
upgrade_policy = "compatible"

[dependencies]
AptosFramework = { local = "../../../../../framework/aptos-framework" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module object::test {

struct State has key {
value: u64
}

public entry fun hello(s: &signer, value: u64, _incompat_additional: u64) {
move_to(s, State { value })
}
}
Loading
Loading