Skip to content

Commit

Permalink
[aptos stdlib] Now that we have verified that the move-compiler Aptos…
Browse files Browse the repository at this point in the history
… stdlib hack works, fix stdlib to use #[test_only] on test helper functions instead of #[testonly]. Leave struct attributes since it's a deployment problem to make it disappear.
  • Loading branch information
brmataptos committed Aug 5, 2023
1 parent 31d69ee commit dfb800a
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 140 deletions.
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math128.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Standard math utilities missing in the Move Language.
- [Function `log2_64`](#0x1_math128_log2_64)
- [Function `sqrt`](#0x1_math128_sqrt)
- [Function `ceil_div`](#0x1_math128_ceil_div)
- [Function `assert_approx_the_same`](#0x1_math128_assert_approx_the_same)
- [Specification](#@Specification_1)
- [Function `max`](#@Specification_1_max)
- [Function `min`](#@Specification_1_min)
Expand Down Expand Up @@ -414,39 +413,6 @@ Returns square root of x, precisely floor(sqrt(x))



</details>

<a name="0x1_math128_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math128.md#0x1_math128_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math128.md#0x1_math128_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = <a href="math128.md#0x1_math128_pow">pow</a>(10, precission);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>

<a name="@Specification_1"></a>
Expand Down
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math64.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Standard math utilities missing in the Move Language.
- [Function `log2`](#0x1_math64_log2)
- [Function `sqrt`](#0x1_math64_sqrt)
- [Function `ceil_div`](#0x1_math64_ceil_div)
- [Function `assert_approx_the_same`](#0x1_math64_assert_approx_the_same)
- [Specification](#@Specification_1)
- [Function `max`](#@Specification_1_max)
- [Function `min`](#@Specification_1_min)
Expand Down Expand Up @@ -369,39 +368,6 @@ Returns square root of x, precisely floor(sqrt(x))



</details>

<a name="0x1_math64_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math64.md#0x1_math64_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math64.md#0x1_math64_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u64) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = (<a href="math64.md#0x1_math64_pow">pow</a>(10, precission) <b>as</b> u128);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>

<a name="@Specification_1"></a>
Expand Down
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math_fixed.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Standard math utilities missing in the Move Language.
- [Function `mul_div`](#0x1_math_fixed_mul_div)
- [Function `exp_raw`](#0x1_math_fixed_exp_raw)
- [Function `pow_raw`](#0x1_math_fixed_pow_raw)
- [Function `assert_approx_the_same`](#0x1_math_fixed_assert_approx_the_same)


<pre><code><b>use</b> <a href="../../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
Expand Down Expand Up @@ -294,39 +293,6 @@ Specialized function for x * y / z that omits intermediate shifting



</details>

<a name="0x1_math_fixed_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math_fixed.md#0x1_math_fixed_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math_fixed.md#0x1_math_fixed_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = <a href="math128.md#0x1_math128_pow">math128::pow</a>(10, precission);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>


Expand Down
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math_fixed64.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Standard math utilities missing in the Move Language.
- [Function `mul_div`](#0x1_math_fixed64_mul_div)
- [Function `exp_raw`](#0x1_math_fixed64_exp_raw)
- [Function `pow_raw`](#0x1_math_fixed64_pow_raw)
- [Function `assert_approx_the_same`](#0x1_math_fixed64_assert_approx_the_same)


<pre><code><b>use</b> <a href="../../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
Expand Down Expand Up @@ -289,39 +288,6 @@ Specialized function for x * y / z that omits intermediate shifting



</details>

<a name="0x1_math_fixed64_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math_fixed64.md#0x1_math_fixed64_assert_approx_the_same">assert_approx_the_same</a>(x: u256, y: u256, precission: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math_fixed64.md#0x1_math_fixed64_assert_approx_the_same">assert_approx_the_same</a>(x: u256, y: u256, precission: u128) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = (<a href="math128.md#0x1_math128_pow">math128::pow</a>(10, precission) <b>as</b> u256);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>


Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/aptos-stdlib/sources/math128.move
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ module aptos_std::math128 {
assert!(result == 13043817825332782212, 0);
}

#[testonly]
#[test_only]
/// For functions that approximate a value it's useful to test a value is close
/// to the most correct value up to last digit
fun assert_approx_the_same(x: u128, y: u128, precission: u128) {
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/aptos-stdlib/sources/math64.move
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ module aptos_std::math64 {
assert!(result == 3037000499, 0);
}

#[testonly]
#[test_only]
/// For functions that approximate a value it's useful to test a value is close
/// to the most correct value up to last digit
fun assert_approx_the_same(x: u128, y: u128, precission: u64) {
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/aptos-stdlib/sources/math_fixed.move
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module aptos_std::math_fixed {
assert_approx_the_same(result, 1 << 33, 6);
}

#[testonly]
#[test_only]
/// For functions that approximate a value it's useful to test a value is close
/// to the most correct value up to last digit
fun assert_approx_the_same(x: u128, y: u128, precission: u128) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module aptos_std::math_fixed64 {
assert_approx_the_same(result, 1 << 65, 16);
}

#[testonly]
#[test_only]
/// For functions that approximate a value it's useful to test a value is close
/// to the most correct value up to last digit
fun assert_approx_the_same(x: u256, y: u256, precission: u128) {
Expand Down

0 comments on commit dfb800a

Please sign in to comment.