Skip to content

Commit

Permalink
[package-upgrades] Type param testing (MystenLabs#10271)
Browse files Browse the repository at this point in the history
## Description 

Added tests for type parameters.
  • Loading branch information
awelc authored Apr 1, 2023
1 parent 72179fe commit 9593c1c
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/sui-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ mod move_package_upgrade_tests;
#[path = "unit_tests/pay_sui_tests.rs"]
mod pay_sui_tests;
pub mod test_authority_clients;
#[cfg(test)]
#[path = "unit_tests/type_param_tests.rs"]
mod type_param_tests;

pub mod signature_verifier;

Expand Down
9 changes: 9 additions & 0 deletions crates/sui-core/src/unit_tests/data/type_params/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "type_params"
version = "0.0.1"

[dependencies]
Sui = { local = "../../../../../sui-framework/packages/sui-framework" }

[addresses]
type_params = "0x0"
40 changes: 40 additions & 0 deletions crates/sui-core/src/unit_tests/data/type_params/sources/m1.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module type_params::m1 {
use sui::object::{Self, UID};
use sui::tx_context::TxContext;
use sui::transfer;
use type_params::m2;

struct Object has key, store {
id: UID,
value: u64,
}

struct GenObject<T: key + store> has key, store {
id: UID,
o: T,
}

public entry fun create_and_transfer(value: u64, recipient: address, ctx: &mut TxContext) {
transfer::public_transfer(
Object { id: object::new(ctx), value },
recipient
)
}

public entry fun create_and_transfer_gen(value: u64, recipient: address, ctx: &mut TxContext) {
let another = m2::create(value, ctx);
transfer::public_transfer(
GenObject { id: object::new(ctx), o: another },
recipient
)
}

public entry fun transfer_object<T: key + store>(o: T, recipient: address) {
transfer::public_transfer(o, recipient);
}


}
26 changes: 26 additions & 0 deletions crates/sui-core/src/unit_tests/data/type_params/sources/m2.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module type_params::m2 {
use sui::object::{Self, UID};
use sui::tx_context::TxContext;
use sui::transfer;

struct AnotherObject has key, store {
id: UID,
value: u64,
}

public entry fun create_and_transfer(value: u64, recipient: address, ctx: &mut TxContext) {
transfer::public_transfer(
AnotherObject { id: object::new(ctx), value },
recipient
)
}

public fun create(value: u64, ctx: &mut TxContext): AnotherObject {
AnotherObject { id: object::new(ctx), value }
}


}
12 changes: 12 additions & 0 deletions crates/sui-core/src/unit_tests/data/type_params/sources/m3.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module type_params::m3 {
use sui::transfer;

public entry fun transfer_object<T: key + store>(o: T, recipient: address) {
transfer::public_transfer(o, recipient);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "type_params_extra"
version = "0.0.1"

[dependencies]
Sui = { local = "../../../../../sui-framework/packages/sui-framework" }

[addresses]
type_params = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module type_params::m1 {
use sui::transfer;

public entry fun transfer_object<T: key + store>(o: T, recipient: address) {
transfer::public_transfer(o, recipient);
}


}
Loading

0 comments on commit 9593c1c

Please sign in to comment.