Skip to content

Commit

Permalink
Adding more tests, addressing some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Nov 14, 2024
1 parent 6480e3b commit 16b6fa3
Show file tree
Hide file tree
Showing 9 changed files with 655 additions and 110 deletions.
314 changes: 286 additions & 28 deletions aptos-move/framework/aptos-stdlib/doc/ordered_map.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions aptos-move/framework/move-stdlib/doc/cmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ and if equal we proceed to the next.
- enum's are compared first by their variant, and if equal - they are compared as structs are.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="cmp.md#0x1_cmp_compare">compare</a>&lt;T&gt;(first: &T, second: &T): <a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_compare">compare</a>&lt;T&gt;(first: &T, second: &T): <a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>
</code></pre>


Expand All @@ -104,7 +104,7 @@ and if equal we proceed to the next.
<summary>Implementation</summary>


<pre><code><b>native</b> <b>public</b>(<b>friend</b>) <b>fun</b> <a href="cmp.md#0x1_cmp_compare">compare</a>&lt;T&gt;(first: &T, second: &T): <a href="cmp.md#0x1_cmp_Ordering">Ordering</a>;
<pre><code><b>native</b> <b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_compare">compare</a>&lt;T&gt;(first: &T, second: &T): <a href="cmp.md#0x1_cmp_Ordering">Ordering</a>;
</code></pre>


Expand Down
12 changes: 6 additions & 6 deletions aptos-move/framework/move-stdlib/doc/mem.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Move prevents from having two mutable references to the same value,
so <code>left</code> and <code>right</code> references are always distinct.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
</code></pre>


Expand All @@ -36,7 +36,7 @@ so <code>left</code> and <code>right</code> references are always distinct.
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>native</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T);
<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T);
</code></pre>


Expand All @@ -51,7 +51,7 @@ Replace the value reference points to with the given new value,
and return the value it had before.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
</code></pre>


Expand All @@ -60,7 +60,7 @@ and return the value it had before.
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T {
<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T {
<a href="mem.md#0x1_mem_swap">swap</a>(ref, &<b>mut</b> new);
new
}
Expand All @@ -80,7 +80,7 @@ and return the value it had before.
### Function `swap`


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
</code></pre>


Expand All @@ -99,7 +99,7 @@ and return the value it had before.
### Function `replace`


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
</code></pre>


Expand Down
7 changes: 1 addition & 6 deletions aptos-move/framework/move-stdlib/sources/cmp.move
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ module std::cmp {
Greater,
}

// TODO - functions here are `public(friend)` here for one release,
// and to be changed to `public` one release later.
#[test_only]
friend std::bcs_tests;

/// Compares two values with the natural ordering:
/// - native types are compared identically to `<` and other operators
/// - complex types
/// - Structs and vectors - are compared lexicographically - first field/element is compared first,
/// and if equal we proceed to the next.
/// - enum's are compared first by their variant, and if equal - they are compared as structs are.
native public(friend) fun compare<T>(first: &T, second: &T): Ordering;
native public fun compare<T>(first: &T, second: &T): Ordering;

public fun is_eq(self: &Ordering): bool {
self is Ordering::Equal
Expand Down
10 changes: 2 additions & 8 deletions aptos-move/framework/move-stdlib/sources/mem.move
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
/// Module with methods for safe memory manipulation.
module std::mem {
// TODO - functions here are `public(friend)` here for one release,
// and to be changed to `public` one release later.
friend std::vector;
#[test_only]
friend std::mem_tests;

/// Swap contents of two passed mutable references.
///
/// Move prevents from having two mutable references to the same value,
/// so `left` and `right` references are always distinct.
public(friend) native fun swap<T>(left: &mut T, right: &mut T);
public native fun swap<T>(left: &mut T, right: &mut T);

/// Replace the value reference points to with the given new value,
/// and return the value it had before.
public(friend) fun replace<T>(ref: &mut T, new: T): T {
public fun replace<T>(ref: &mut T, new: T): T {
swap(ref, &mut new);
new
}
Expand Down
14 changes: 5 additions & 9 deletions crates/transaction-generator-lib/src/publishing/module_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,11 @@ impl EntryPoints {
len,
repeats,
use_simple_map,
} => get_payload(
module_id,
ident_str!("test_split_off_append").to_owned(),
vec![
bcs::to_bytes(len).unwrap(),
bcs::to_bytes(repeats).unwrap(),
bcs::to_bytes(use_simple_map).unwrap(),
],
),
} => get_payload(module_id, ident_str!("test_add_remove").to_owned(), vec![
bcs::to_bytes(len).unwrap(),
bcs::to_bytes(repeats).unwrap(),
bcs::to_bytes(use_simple_map).unwrap(),
]),
EntryPoints::TokenV1InitializeCollection => get_payload_void(
module_id,
ident_str!("token_v1_initialize_collection").to_owned(),
Expand Down
104 changes: 77 additions & 27 deletions crates/transaction-generator-lib/src/publishing/raw_module_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,12 @@ pub static PACKAGE_SIMPLE_METADATA: Lazy<Vec<u8>> = Lazy::new(|| {

#[rustfmt::skip]
pub static SCRIPT_SIMPLE: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
161, 28, 235, 11, 7, 0, 0, 10, 2, 5, 0, 4, 6, 4, 34, 1, 6, 12,
0, 5, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 1, 3, 11, 0, 1, 2,
]
vec![
161, 28, 235, 11, 7, 0, 0, 10, 2, 5, 0, 4, 6, 4, 34, 1, 6, 12,
0, 5, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 1, 3, 11, 0, 1, 2,
]
});

#[rustfmt::skip]
Expand Down Expand Up @@ -984,11 +984,11 @@ pub static MODULES_SIMPLE: Lazy<Vec<Vec<u8>>> = Lazy::new(|| { vec![
pub static PACKAGE_FRAMEWORK_USECASES_METADATA: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
17, 70, 114, 97, 109, 101, 119, 111, 114, 107, 85, 115, 101, 99, 97, 115, 101, 115,
1, 0, 0, 0, 0, 0, 0, 0, 0, 64, 66, 67, 69, 48, 54, 67, 49, 52,
57, 67, 52, 51, 66, 56, 50, 53, 55, 53, 48, 54, 67, 65, 65, 57, 66, 66,
70, 65, 51, 52, 51, 66, 69, 55, 56, 57, 57, 55, 67, 50, 56, 52, 70, 53,
49, 56, 67, 70, 65, 55, 66, 57, 49, 54, 67, 50, 53, 69, 55, 56, 68, 55,
55, 69, 215, 1, 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 165, 144, 187, 142,
1, 0, 0, 0, 0, 0, 0, 0, 0, 64, 68, 65, 68, 69, 51, 69, 49, 70,
54, 54, 52, 70, 65, 54, 67, 69, 66, 52, 68, 68, 48, 49, 67, 65, 53, 50,
55, 68, 70, 51, 50, 55, 70, 51, 52, 51, 68, 49, 50, 48, 68, 66, 51, 49,
51, 53, 56, 69, 57, 67, 68, 54, 57, 55, 51, 57, 57, 57, 50, 51, 57, 57,
51, 70, 215, 1, 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 165, 144, 187, 142,
194, 64, 12, 69, 251, 249, 10, 107, 182, 38, 236, 15, 108, 193, 238, 138, 150, 6,
170, 8, 33, 51, 49, 33, 100, 176, 163, 241, 240, 144, 16, 255, 78, 44, 30, 130,
22, 100, 23, 215, 246, 189, 167, 112, 217, 97, 104, 177, 166, 185, 99, 220, 18, 252,
Expand All @@ -1000,27 +1000,28 @@ pub static PACKAGE_FRAMEWORK_USECASES_METADATA: Lazy<Vec<u8>> = Lazy::new(|| {
134, 107, 160, 99, 88, 35, 215, 38, 101, 5, 65, 88, 51, 114, 6, 172, 170, 68,
170, 96, 20, 5, 236, 5, 197, 88, 184, 242, 182, 183, 231, 117, 187, 101, 108, 116,
77, 105, 113, 55, 219, 163, 143, 163, 223, 191, 127, 239, 46, 112, 10, 188, 112, 161,
1, 0, 0, 7, 18, 97, 103, 103, 114, 101, 103, 97, 116, 111, 114, 95, 101, 120,
1, 0, 0, 8, 18, 97, 103, 103, 114, 101, 103, 97, 116, 111, 114, 95, 101, 120,
97, 109, 112, 108, 101, 0, 0, 0, 12, 99, 111, 105, 110, 95, 101, 120, 97, 109,
112, 108, 101, 0, 0, 0, 22, 102, 117, 110, 103, 105, 98, 108, 101, 95, 97, 115,
115, 101, 116, 95, 101, 120, 97, 109, 112, 108, 101, 0, 0, 0, 7, 111, 98, 106,
101, 99, 116, 115, 0, 0, 0, 23, 114, 101, 115, 111, 117, 114, 99, 101, 95, 103,
114, 111, 117, 112, 115, 95, 101, 120, 97, 109, 112, 108, 101, 0, 0, 0, 8, 116,
111, 107, 101, 110, 95, 118, 49, 0, 0, 0, 14, 118, 101, 99, 116, 111, 114, 95,
101, 120, 97, 109, 112, 108, 101, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
115, 101, 116, 95, 101, 120, 97, 109, 112, 108, 101, 0, 0, 0, 12, 109, 97, 112,
115, 95, 101, 120, 97, 109, 112, 108, 101, 0, 0, 0, 7, 111, 98, 106, 101, 99,
116, 115, 0, 0, 0, 23, 114, 101, 115, 111, 117, 114, 99, 101, 95, 103, 114, 111,
117, 112, 115, 95, 101, 120, 97, 109, 112, 108, 101, 0, 0, 0, 8, 116, 111, 107,
101, 110, 95, 118, 49, 0, 0, 0, 14, 118, 101, 99, 116, 111, 114, 95, 101, 120,
97, 109, 112, 108, 101, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 14, 65, 112, 116, 111, 115, 70, 114, 97, 109, 101,
119, 111, 114, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
11, 65, 112, 116, 111, 115, 83, 116, 100, 108, 105, 98, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 14, 65, 112, 116, 111, 115, 70, 114, 97, 109, 101, 119, 111,
114, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, 65,
112, 116, 111, 115, 83, 116, 100, 108, 105, 98, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 10, 77, 111, 118, 101, 83, 116, 100, 108, 105,
98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 10, 65, 112,
116, 111, 115, 84, 111, 107, 101, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 10, 77, 111, 118, 101, 83, 116, 100, 108, 105, 98, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 4, 17, 65, 112, 116, 111, 115, 84, 111, 107, 101, 110, 79, 98, 106,
101, 99, 116, 115, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 10, 65, 112, 116, 111,
115, 84, 111, 107, 101, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 4, 17, 65, 112, 116, 111, 115, 84, 111, 107, 101, 110, 79, 98, 106, 101, 99,
116, 115, 0,
]
});

Expand Down Expand Up @@ -1223,6 +1224,54 @@ pub static MODULE_FRAMEWORK_USECASES_FUNGIBLE_ASSET_EXAMPLE: Lazy<Vec<u8>> = Laz
]
});

#[rustfmt::skip]
pub static MODULE_FRAMEWORK_USECASES_MAPS_EXAMPLE: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
161, 28, 235, 11, 7, 0, 0, 10, 9, 1, 0, 6, 2, 6, 16, 3, 22, 54,
4, 76, 12, 5, 88, 102, 7, 190, 1, 88, 8, 150, 2, 64, 16, 214, 2, 31,
12, 245, 2, 208, 2, 0, 0, 1, 2, 1, 5, 1, 4, 7, 2, 0, 0, 0,
0, 2, 6, 7, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 3, 1,
3, 2, 4, 4, 1, 2, 3, 1, 4, 2, 0, 0, 1, 1, 7, 5, 1, 2,
4, 4, 1, 2, 7, 6, 1, 2, 0, 0, 1, 1, 8, 7, 8, 2, 4, 4,
1, 2, 8, 9, 10, 2, 2, 0, 1, 1, 2, 2, 2, 3, 2, 4, 2, 5,
2, 6, 2, 3, 3, 3, 1, 0, 2, 3, 3, 1, 11, 0, 2, 9, 0, 9,
1, 1, 11, 1, 2, 9, 0, 9, 1, 3, 7, 11, 0, 2, 9, 0, 9, 1,
9, 0, 9, 1, 3, 7, 11, 1, 2, 9, 0, 9, 1, 9, 0, 9, 1, 2,
7, 11, 0, 2, 9, 0, 9, 1, 6, 9, 0, 2, 9, 0, 9, 1, 2, 7,
11, 1, 2, 9, 0, 9, 1, 6, 9, 0, 1, 9, 1, 11, 3, 3, 11, 0,
2, 3, 3, 11, 1, 2, 3, 3, 3, 1, 3, 1, 3, 3, 3, 12, 109, 97,
112, 115, 95, 101, 120, 97, 109, 112, 108, 101, 15, 116, 101, 115, 116, 95, 97, 100,
100, 95, 114, 101, 109, 111, 118, 101, 10, 115, 105, 109, 112, 108, 101, 95, 109, 97,
112, 3, 110, 101, 119, 9, 83, 105, 109, 112, 108, 101, 77, 97, 112, 11, 111, 114,
100, 101, 114, 101, 100, 95, 109, 97, 112, 10, 79, 114, 100, 101, 114, 101, 100, 77,
97, 112, 3, 97, 100, 100, 6, 114, 101, 109, 111, 118, 101, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 171, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 20, 99, 111, 109, 112, 105, 108, 97, 116, 105, 111, 110, 95,
109, 101, 116, 97, 100, 97, 116, 97, 9, 0, 3, 50, 46, 48, 3, 50, 46, 49,
0, 1, 4, 0, 11, 123, 6, 210, 4, 0, 0, 0, 0, 0, 0, 12, 3, 6,
210, 4, 0, 0, 0, 0, 0, 0, 12, 4, 56, 0, 12, 5, 56, 1, 12, 6,
6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 7, 9, 12, 8, 5, 14, 5, 50,
10, 8, 4, 120, 11, 7, 6, 1, 0, 0, 0, 0, 0, 0, 0, 22, 12, 7,
10, 7, 10, 0, 35, 3, 25, 5, 50, 10, 2, 4, 45, 13, 5, 10, 3, 10,
3, 56, 2, 11, 3, 6, 177, 30, 4, 0, 0, 0, 0, 0, 22, 12, 3, 10,
3, 6, 64, 66, 15, 0, 0, 0, 0, 0, 36, 3, 40, 5, 12, 11, 3, 6,
64, 66, 15, 0, 0, 0, 0, 0, 23, 12, 3, 5, 12, 13, 6, 10, 3, 10,
3, 56, 3, 5, 31, 6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 9, 9, 12,
10, 11, 1, 12, 11, 5, 58, 5, 116, 10, 10, 4, 117, 11, 9, 6, 1, 0,
0, 0, 0, 0, 0, 0, 22, 12, 9, 10, 9, 10, 11, 35, 3, 69, 5, 116,
10, 2, 4, 107, 13, 5, 10, 3, 10, 3, 56, 2, 13, 5, 14, 4, 56, 4,
1, 1, 11, 3, 6, 177, 30, 4, 0, 0, 0, 0, 0, 22, 12, 3, 10, 3,
6, 64, 66, 15, 0, 0, 0, 0, 0, 36, 3, 89, 5, 93, 11, 3, 6, 64,
66, 15, 0, 0, 0, 0, 0, 23, 12, 3, 11, 4, 6, 177, 30, 4, 0, 0,
0, 0, 0, 22, 12, 4, 10, 4, 6, 64, 66, 15, 0, 0, 0, 0, 0, 36,
3, 102, 5, 56, 11, 4, 6, 64, 66, 15, 0, 0, 0, 0, 0, 23, 12, 4,
5, 56, 13, 6, 10, 3, 10, 3, 56, 3, 13, 6, 14, 4, 56, 5, 1, 5,
80, 2, 8, 12, 10, 5, 64, 8, 12, 8, 5, 20, 0,
]
});

#[rustfmt::skip]
pub static MODULE_FRAMEWORK_USECASES_OBJECTS: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
Expand Down Expand Up @@ -1649,6 +1698,7 @@ pub static MODULES_FRAMEWORK_USECASES: Lazy<Vec<Vec<u8>>> = Lazy::new(|| { vec![
MODULE_FRAMEWORK_USECASES_AGGREGATOR_EXAMPLE.to_vec(),
MODULE_FRAMEWORK_USECASES_COIN_EXAMPLE.to_vec(),
MODULE_FRAMEWORK_USECASES_FUNGIBLE_ASSET_EXAMPLE.to_vec(),
MODULE_FRAMEWORK_USECASES_MAPS_EXAMPLE.to_vec(),
MODULE_FRAMEWORK_USECASES_OBJECTS.to_vec(),
MODULE_FRAMEWORK_USECASES_RESOURCE_GROUPS_EXAMPLE.to_vec(),
MODULE_FRAMEWORK_USECASES_TOKEN_V1.to_vec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module 0xABCD::maps_example {
const OFFSET: u64 = 270001;
const MOD: u64 = 1000000;

public entry fun test_split_off_append(len: u64, repeats: u64, use_simple_map: bool) {
public entry fun test_add_remove(len: u64, repeats: u64, use_simple_map: bool) {
// y is same sequence of values as x, just lagging len behind
// so that map always has len elements.
let x = 1234;
Expand Down

0 comments on commit 16b6fa3

Please sign in to comment.