Skip to content

Commit

Permalink
[package-upgrades] Added transactional tests for package upgrades (My…
Browse files Browse the repository at this point in the history
…stenLabs#11035)

## Description 

Added some more tests related to package upgrades.

## Test Plan 

These are the actual tests
  • Loading branch information
awelc authored Apr 20, 2023
1 parent 4d2f3d4 commit c78c695
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 0 deletions.
101 changes: 101 additions & 0 deletions crates/sui-adapter-transactional-tests/tests/upgrade/dep_override.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
processed 21 tasks

init:
A: object(0,0)

task 1 'publish'. lines 10-18:
created: object(1,0), object(1,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 6809600, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'upgrade'. lines 20-28:
created: object(2,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 6809600, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 3 'upgrade'. lines 30-41:
created: object(3,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 6809600, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 4 'publish'. lines 44-49:
created: object(4,0), object(4,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 6551200, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5 'upgrade'. lines 51-59:
created: object(5,0)
mutated: object(0,0), object(4,1)
gas summary: computation_cost: 1000000, storage_cost: 6551200, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 6 'publish'. lines 62-69:
created: object(6,0), object(6,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 7030000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 7 'upgrade'. lines 71-78:
created: object(7,0)
mutated: object(0,0), object(6,1)
gas summary: computation_cost: 1000000, storage_cost: 7030000, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 8 'upgrade'. lines 80-85:
created: object(8,0)
mutated: object(0,0), object(6,1)
gas summary: computation_cost: 1000000, storage_cost: 7030000, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 9 'run'. lines 87-87:
created: object(9,0)
mutated: object(0,1)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 0, non_refundable_storage_fee: 0

task 10 'view-object'. lines 89-89:
Owner: Shared
Version: 2
Contents: Test_DepDepV1::DepDepM1::Obj {id: sui::object::UID {id: sui::object::ID {bytes: fake(9,0)}}, v: 42u64}

task 11 'run'. lines 91-91:
created: object(11,0)
mutated: object(0,1)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 12 'view-object'. lines 93-93:
Owner: Shared
Version: 3
Contents: Test_DepDepV1::DepDepM1::Obj {id: sui::object::UID {id: sui::object::ID {bytes: fake(11,0)}}, v: 7u64}

task 13 'run'. lines 95-95:
created: object(13,0)
mutated: object(0,1)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 14 'view-object'. lines 97-100:
Owner: Shared
Version: 4
Contents: Test_DepDepV1::DepDepM1::Obj {id: sui::object::UID {id: sui::object::ID {bytes: fake(13,0)}}, v: 0u64}

task 15 'programmable'. lines 101-103:
created: object(15,0), object(15,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 3663200, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 16 'view-object'. lines 105-105:
Owner: Shared
Version: 10
Contents: Test_DepDepV1::DepDepM1::Obj {id: sui::object::UID {id: sui::object::ID {bytes: fake(15,0)}}, v: 0u64}

task 17 'view-object'. lines 107-112:
Owner: Shared
Version: 10
Contents: Test_DepDepV1::DepDepM1::Obj {id: sui::object::UID {id: sui::object::ID {bytes: fake(15,1)}}, v: 7u64}

task 18 'upgrade'. lines 114-120:
Error: Transaction Effects Status: Publish/Upgrade Error, Missing dependency. A dependency of a published or upgraded package has not been assigned an on-chain address.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: PublishUpgradeMissingDependency, source: None, command: Some(1) } }

task 19 'upgrade'. lines 122-128:
Error: Transaction Effects Status: Publish/Upgrade Error, Missing dependency. A dependency of a published or upgraded package has not been assigned an on-chain address.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: PublishUpgradeMissingDependency, source: None, command: Some(1) } }

task 20 'upgrade'. lines 130-134:
Error: Transaction Effects Status: Publish/Upgrade Error, Dependency downgrade. Indirect (transitive) dependency of published or upgraded package has been assigned an on-chain version that is less than the version required by one of the package's transitive dependencies.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: PublishUpgradeDependencyDowngrade, source: None, command: Some(1) } }
134 changes: 134 additions & 0 deletions crates/sui-adapter-transactional-tests/tests/upgrade/dep_override.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --addresses Test_DepDepV1=0x0 Test_DepDepV2=0x0 Test_DepDepV3=0x0 Test_DepV1=0x0 Test_DepV2=0x0 Test_V1=0x0 Test_V2=0x0 Test_V3=0x0 Test_V4=0x0 --accounts A


// 3 versions of the transitive dependency


//# publish --upgradeable --sender A
module Test_DepDepV1::DepDepM1 {

struct Obj has key, store { id: sui::object::UID, v: u64 }

public fun foo(ctx: &mut sui::tx_context::TxContext) {
sui::transfer::share_object(Obj { id: sui::object::new(ctx), v: 42 })
}
}

//# upgrade --package Test_DepDepV1 --upgrade-capability 1,1 --sender A
module Test_DepDepV2::DepDepM1 {

struct Obj has key, store { id: sui::object::UID, v: u64 }

public fun foo(ctx: &mut sui::tx_context::TxContext) {
sui::transfer::share_object(Obj { id: sui::object::new(ctx), v: 7 })
}
}

//# upgrade --package Test_DepDepV2 --upgrade-capability 1,1 --sender A
module Test_DepDepV3::DepDepM1 {

struct Obj has key, store { id: sui::object::UID, v: u64 }

public fun foo(ctx: &mut sui::tx_context::TxContext) {
sui::transfer::share_object(Obj { id: sui::object::new(ctx), v: 0 })
}
}


// 2 versions of the direct dependency


//# publish --upgradeable --dependencies Test_DepDepV1 --sender A
module Test_DepV1::DepM1 {
use Test_DepDepV1::DepDepM1;

public fun bar(ctx: &mut sui::tx_context::TxContext) { DepDepM1::foo(ctx) }
}

//# upgrade --package Test_DepV1 --upgrade-capability 4,1 --dependencies Test_DepDepV2 --sender A
module Test_DepV2::DepM1 {
use Test_DepDepV1::DepDepM1;

public fun bar(ctx: &mut sui::tx_context::TxContext) { DepDepM1::foo(ctx) }
}


// 3 versions of the root package


//# publish --upgradeable --dependencies Test_DepV1 Test_DepDepV1 --sender A
module Test_V1::M1 {
use Test_DepV1::DepM1;

public entry fun baz(ctx: &mut sui::tx_context::TxContext) { DepM1::bar(ctx) }
}

// override direct dependency

//# upgrade --package Test_V1 --upgrade-capability 6,1 --dependencies Test_DepV2 Test_DepDepV2 --sender A
module Test_V2::M1 {
use Test_DepV1::DepM1;

public entry fun baz(ctx: &mut sui::tx_context::TxContext) { DepM1::bar(ctx) }
}

// override indirect dependency

//# upgrade --package Test_V2 --upgrade-capability 6,1 --dependencies Test_DepV1 Test_DepDepV3 --sender A
module Test_V3::M1 {
use Test_DepV1::DepM1;

public entry fun baz(ctx: &mut sui::tx_context::TxContext) { DepM1::bar(ctx) }
}

//# run Test_V1::M1::baz

//# view-object 9,0

//# run Test_V2::M1::baz

//# view-object 11,0

//# run Test_V3::M1::baz

//# view-object 13,0

// call same function from two different module versions but defined in both modules (should produce
// different result due to overrides)
//# programmable --sender A
//> 0: Test_V2::M1::baz();
//> 1: Test_V3::M1::baz();

//# view-object 15,0

//# view-object 15,1


// expected upgrade errors

// missing direct dependency (should fail)

//# upgrade --package Test_V3 --upgrade-capability 6,1 --dependencies Test_DepDepV1 --sender A
module Test_V4::M1 {
use Test_DepV1::DepM1;
public entry fun baz(ctx: &mut sui::tx_context::TxContext) { DepM1::bar(ctx) }
}

// missing indirect dependency (should fail)

//# upgrade --package Test_V3 --upgrade-capability 6,1 --dependencies Test_DepV2 --sender A
module Test_V4::M1 {
use Test_DepV1::DepM1;
public entry fun baz(ctx: &mut sui::tx_context::TxContext) { DepM1::bar(ctx) }
}

// downgrade indirect dependency (should fail)

//# upgrade --package Test_V3 --upgrade-capability 6,1 --dependencies Test_DepV2 Test_DepDepV1 --sender A
module Test_V4::M1 {
use Test_DepV1::DepM1;
public entry fun baz(ctx: &mut sui::tx_context::TxContext) { DepM1::bar(ctx) }
}
66 changes: 66 additions & 0 deletions crates/sui-adapter-transactional-tests/tests/upgrade/new_types.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
processed 14 tasks

init:
A: object(0,0)

task 1 'publish'. lines 6-18:
created: object(1,0), object(1,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 7166800, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'upgrade'. lines 21-33:
created: object(2,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 7166800, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 3 'publish'. lines 36-47:
created: object(3,0), object(3,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 6908400, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4 'upgrade'. lines 49-60:
created: object(4,0)
mutated: object(0,0), object(3,1)
gas summary: computation_cost: 1000000, storage_cost: 6908400, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 5 'upgrade'. lines 62-73:
created: object(5,0)
mutated: object(0,0), object(3,1)
gas summary: computation_cost: 1000000, storage_cost: 6908400, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 6 'run'. lines 76-76:
created: object(6,0)
mutated: object(0,1)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 0, non_refundable_storage_fee: 0

task 7 'view-object'. lines 78-80:
Owner: Shared
Version: 2
Contents: Test_DepV1::DepM1::DepObj {id: sui::object::UID {id: sui::object::ID {bytes: fake(6,0)}}, v: 42u64}

task 8 'programmable'. lines 81-83:
mutated: object(0,0), object(6,0)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 2302344, non_refundable_storage_fee: 23256

task 9 'view-object'. lines 85-88:
Owner: Shared
Version: 7
Contents: Test_DepV1::DepM1::DepObj {id: sui::object::UID {id: sui::object::ID {bytes: fake(6,0)}}, v: 39u64}

task 10 'programmable'. lines 89-91:
mutated: object(0,0), object(6,0)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 2302344, non_refundable_storage_fee: 23256

task 11 'view-object'. lines 93-96:
Owner: Shared
Version: 8
Contents: Test_DepV1::DepM1::DepObj {id: sui::object::UID {id: sui::object::ID {bytes: fake(6,0)}}, v: 37u64}

task 12 'programmable'. lines 97-99:
mutated: object(0,0), object(6,0)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 2302344, non_refundable_storage_fee: 23256

task 13 'view-object'. lines 101-101:
Owner: Shared
Version: 9
Contents: Test_DepV1::DepM1::DepObj {id: sui::object::UID {id: sui::object::ID {bytes: fake(6,0)}}, v: 34u64}
Loading

0 comments on commit c78c695

Please sign in to comment.