forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move] Re-enabled bytecode verification of test code (MystenLabs#7792)
This is a new version of MystenLabs#6564 and it also closes MystenLabs#7759. Bytecode verification of of test code was introduced in MystenLabs#5732 but then temporarily disabled in MystenLabs#6435 due to developer complaints about inability to test `init` functions. This PR special-cases the bytecode verifier to avoid running checks related to calling `init` functions and to instantiating a one-time-witness struct by-hand in the test code. It also enables bytecode verification when running Move unit tests.
- Loading branch information
Showing
11 changed files
with
306 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
<a name="0x2_verifier_tests"></a> | ||
|
||
# Module `0x2::verifier_tests` | ||
|
||
Tests if normally illegal (in terms of Sui bytecode verification) code is allowed in tests. | ||
|
||
|
||
- [Struct `VERIFIER_TESTS`](#0x2_verifier_tests_VERIFIER_TESTS) | ||
- [Function `init`](#0x2_verifier_tests_init) | ||
- [Function `is_otw`](#0x2_verifier_tests_is_otw) | ||
|
||
|
||
<pre><code><b>use</b> <a href="tx_context.md#0x2_tx_context">0x2::tx_context</a>; | ||
<b>use</b> <a href="types.md#0x2_types">0x2::types</a>; | ||
</code></pre> | ||
|
||
|
||
|
||
<a name="0x2_verifier_tests_VERIFIER_TESTS"></a> | ||
|
||
## Struct `VERIFIER_TESTS` | ||
|
||
|
||
|
||
<pre><code><b>struct</b> <a href="verifier_tests.md#0x2_verifier_tests_VERIFIER_TESTS">VERIFIER_TESTS</a> <b>has</b> drop | ||
</code></pre> | ||
|
||
|
||
|
||
<details> | ||
<summary>Fields</summary> | ||
|
||
|
||
<dl> | ||
<dt> | ||
<code>dummy_field: bool</code> | ||
</dt> | ||
<dd> | ||
|
||
</dd> | ||
</dl> | ||
|
||
|
||
</details> | ||
|
||
<a name="0x2_verifier_tests_init"></a> | ||
|
||
## Function `init` | ||
|
||
|
||
|
||
<pre><code><b>fun</b> <a href="verifier_tests.md#0x2_verifier_tests_init">init</a>(otw: <a href="verifier_tests.md#0x2_verifier_tests_VERIFIER_TESTS">verifier_tests::VERIFIER_TESTS</a>, _: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>) | ||
</code></pre> | ||
|
||
|
||
|
||
<details> | ||
<summary>Implementation</summary> | ||
|
||
|
||
<pre><code><b>fun</b> <a href="verifier_tests.md#0x2_verifier_tests_init">init</a>(otw: <a href="verifier_tests.md#0x2_verifier_tests_VERIFIER_TESTS">VERIFIER_TESTS</a>, _: &<b>mut</b> sui::tx_context::TxContext) { | ||
<b>assert</b>!(sui::types::is_one_time_witness(&otw), 0); | ||
} | ||
</code></pre> | ||
|
||
|
||
|
||
</details> | ||
|
||
<a name="0x2_verifier_tests_is_otw"></a> | ||
|
||
## Function `is_otw` | ||
|
||
|
||
|
||
<pre><code><b>fun</b> <a href="verifier_tests.md#0x2_verifier_tests_is_otw">is_otw</a>(witness: <a href="verifier_tests.md#0x2_verifier_tests_VERIFIER_TESTS">verifier_tests::VERIFIER_TESTS</a>): bool | ||
</code></pre> | ||
|
||
|
||
|
||
<details> | ||
<summary>Implementation</summary> | ||
|
||
|
||
<pre><code><b>fun</b> <a href="verifier_tests.md#0x2_verifier_tests_is_otw">is_otw</a>(witness: <a href="verifier_tests.md#0x2_verifier_tests_VERIFIER_TESTS">VERIFIER_TESTS</a>): bool { | ||
sui::types::is_one_time_witness(&witness) | ||
} | ||
</code></pre> | ||
|
||
|
||
|
||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/// Tests if normally illegal (in terms of Sui bytecode verification) code is allowed in tests. | ||
module sui::verifier_tests { | ||
struct VERIFIER_TESTS has drop {} | ||
|
||
fun init(otw: VERIFIER_TESTS, _: &mut sui::tx_context::TxContext) { | ||
assert!(sui::types::is_one_time_witness(&otw), 0); | ||
} | ||
|
||
#[test] | ||
fun test_init() { | ||
use sui::test_scenario; | ||
let admin = @0xBABE; | ||
|
||
let scenario_val = test_scenario::begin(admin); | ||
let scenario = &mut scenario_val; | ||
let otw = VERIFIER_TESTS{}; | ||
init(otw, test_scenario::ctx(scenario)); | ||
test_scenario::end(scenario_val); | ||
} | ||
|
||
fun is_otw(witness: VERIFIER_TESTS): bool { | ||
sui::types::is_one_time_witness(&witness) | ||
} | ||
|
||
#[test] | ||
fun test_otw() { | ||
// we should be able to construct otw in test code | ||
let otw = VERIFIER_TESTS{}; | ||
assert!(is_otw(otw), 0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.