Skip to content

Commit

Permalink
[adapter] Use Move's transactional test framework (MystenLabs#1643)
Browse files Browse the repository at this point in the history
* [adapter] Use Move's transactional test framework

- Move has a transactional test framework designed for invoking the adapter in a series of transactions specified in a file
- Added a Sui instantiation of this
- Used it for some adapter tests (more to come)
  • Loading branch information
tnowacki authored May 2, 2022
1 parent d3ac68a commit 766a44c
Show file tree
Hide file tree
Showing 21 changed files with 982 additions and 113 deletions.
133 changes: 133 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 @@ -4,6 +4,8 @@ members = [
"sui",
"sui_programmability/adapter",
"sui_programmability/framework",
"sui_programmability/transactional-test-runner",
"sui_programmability/adapter/transactional-tests",
"sui_types",
"faucet",
"test_utils"
Expand Down
81 changes: 0 additions & 81 deletions sui_programmability/adapter/src/unit_tests/adapter_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,84 +940,3 @@ fn test_publish_init() {
}
assert!(move_obj_exists);
}

#[test]
/// Tests public initializer that should not be executed upon
/// publishing the module.
fn test_publish_init_public() {
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);

// crate 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
assert!(publish_from_src(
&mut storage,
&native_functions,
"src/unit_tests/data/publish_init_public",
gas_object,
GAS_BUDGET,
)
.is_err());

// nothing should have been crated
assert_eq!(storage.created().len(), 0);
}

#[test]
/// Tests initializer returning a value that should not be executed
/// upon publishing the module.
fn test_publish_init_ret() {
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);

// crate 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
assert!(publish_from_src(
&mut storage,
&native_functions,
"src/unit_tests/data/publish_init_ret",
gas_object,
GAS_BUDGET,
)
.is_err());

// nothing should have been crated
assert_eq!(storage.created().len(), 0);
}

#[test]
/// Tests initializer with parameters other than &mut TxContext that
/// should not be executed upon publishing the module.
fn test_publish_init_param() {
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);

// crate 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
assert!(publish_from_src(
&mut storage,
&native_functions,
"src/unit_tests/data/publish_init_param",
gas_object,
GAS_BUDGET,
)
.is_err());

// nothing should have been crated
assert_eq!(storage.created().len(), 0);
}

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 16 additions & 0 deletions sui_programmability/adapter/transactional-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "sui-adapter-transactional-tests"
version = "0.1.0"
authors = ["Mysten Labs <[email protected]>"]
description = "Adapter and accompanying CLI for local sui development"
license = "Apache-2.0"
publish = false
edition = "2021"

[dev-dependencies]
datatest-stable = "0.1.1"
sui-transactional-test-runner = { path = "../../transactional-test-runner" }

[[test]]
name = "tests"
harness = false
6 changes: 6 additions & 0 deletions sui_programmability/adapter/transactional-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![forbid(unsafe_code)]

// Empty src/lib.rs to get rusty-tags working.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
processed 2 tasks

task 1 'publish'. lines 5-24:
Error: Failed to verify the Move module, reason: "'init' function can have 0 or 1 parameter(s)".
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//# init --addresses Test=0x0
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# publish

// initializer not valid due extra non-ctx param

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand All @@ -11,7 +16,7 @@ module Test::M1 {
value: u64,
}

// initializer that should be executed upon publishing this module
// value param invalid
fun init(ctx: &mut TxContext, value: u64) {
let singleton = Object { id: TxContext::new_id(ctx), value };
Transfer::transfer(singleton, TxContext::sender(ctx))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
processed 2 tasks

task 1 'publish'. lines 5-25:
Error: Failed to verify the Move module, reason: "_::M1. 'init' function cannot be public".
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//# init --addresses Test=0x0
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# publish

// initializer not valid due to public visibility

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand All @@ -12,7 +17,7 @@ module Test::M1 {
}

// public initializer - should not be executed
public(script) fun init(ctx: &mut TxContext) {
public fun init(ctx: &mut TxContext) {
let value = 42;
let singleton = Object { id: TxContext::new_id(ctx), value };
Transfer::transfer(singleton, TxContext::sender(ctx))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
processed 2 tasks

task 1 'publish'. lines 5-26:
Error: Failed to verify the Move module, reason: "_::M1, 'init' function cannot have return values".
Loading

0 comments on commit 766a44c

Please sign in to comment.