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 9, 2024
1 parent 4bd732b commit 3fab948
Show file tree
Hide file tree
Showing 10 changed files with 2,488 additions and 1,877 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 @@ -25,7 +25,7 @@ I.e. swapping/replacing non-copyable/non-droppable types.
Swap contents of two passed mutable references.


<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 @@ -34,7 +34,7 @@ Swap contents of two passed mutable references.
<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>native</b> <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 @@ -49,7 +49,7 @@ Replace value reference points to with the given new value,
and return 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 @@ -58,7 +58,7 @@ and return 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 @@ -78,7 +78,7 @@ and return 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 @@ -97,7 +97,7 @@ and return 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,18 +1,12 @@
/// Module with methods for safe memory manipulation.
/// I.e. swapping/replacing non-copyable/non-droppable types.
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.
public(friend) native fun swap<T>(left: &mut T, right: &mut T);
native public fun swap<T>(left: &mut T, right: &mut T);

/// Replace value reference points to with the given new value,
/// and return 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
7 changes: 1 addition & 6 deletions aptos-move/framework/move-stdlib/sources/vector.move
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,14 @@ module std::vector {
/// Aborts if `i` or `j` is out of bounds.
native public fun swap<Element>(self: &mut vector<Element>, i: u64, j: u64);

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

/// Moves range of elements `[removal_position, removal_position + length)` from vector `from`,
/// to vector `to`, inserting them starting at the `insert_position`.
/// In the `from` vector, elements after the selected range are moved left to fill the hole
/// (i.e. range is removed, while the order of the rest of the elements is kept)
/// In the `to` vector, elements after the `insert_position` are moved the the right to make space for new elements
/// (i.e. range is inserted, while the order of the rest of the elements is kept).
/// Move prevents from having two mutable references to the same value, so `from` and `to` vectors are always distinct.
native public(friend) fun move_range<T>(from: &mut vector<T>, removal_position: u64, length: u64, to: &mut vector<T>, insert_position: u64);
native public fun move_range<T>(from: &mut vector<T>, removal_position: u64, length: u64, to: &mut vector<T>, insert_position: u64);

/// Return an vector of size one containing element `e`.
public fun singleton<Element>(e: Element): vector<Element> {
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
Loading

0 comments on commit 3fab948

Please sign in to comment.