From dfb800a8e09565ae508ca18aa52c858edb44d299 Mon Sep 17 00:00:00 2001 From: "Brian R. Murphy" <132495859+brmataptos@users.noreply.github.com> Date: Fri, 4 Aug 2023 17:15:37 -0700 Subject: [PATCH] [aptos stdlib] Now that we have verified that the move-compiler Aptos 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. --- .../framework/aptos-stdlib/doc/math128.md | 34 ------------------- .../framework/aptos-stdlib/doc/math64.md | 34 ------------------- .../framework/aptos-stdlib/doc/math_fixed.md | 34 ------------------- .../aptos-stdlib/doc/math_fixed64.md | 34 ------------------- .../aptos-stdlib/sources/math128.move | 2 +- .../aptos-stdlib/sources/math64.move | 2 +- .../aptos-stdlib/sources/math_fixed.move | 2 +- .../aptos-stdlib/sources/math_fixed64.move | 2 +- 8 files changed, 4 insertions(+), 140 deletions(-) diff --git a/aptos-move/framework/aptos-stdlib/doc/math128.md b/aptos-move/framework/aptos-stdlib/doc/math128.md index be26558d63967f..b3a271c2e918bd 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math128.md +++ b/aptos-move/framework/aptos-stdlib/doc/math128.md @@ -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) @@ -414,39 +413,6 @@ Returns square root of x, precisely floor(sqrt(x)) - - - - -## 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 - - -
#[testonly]
-fun assert_approx_the_same(x: u128, y: u128, precission: u128)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u128, y: u128, precission: u128) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = pow(10, precission);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/doc/math64.md b/aptos-move/framework/aptos-stdlib/doc/math64.md index bc6436435a49e5..cce24aa3e9515d 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math64.md +++ b/aptos-move/framework/aptos-stdlib/doc/math64.md @@ -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) @@ -369,39 +368,6 @@ Returns square root of x, precisely floor(sqrt(x)) - - - - -## 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 - - -
#[testonly]
-fun assert_approx_the_same(x: u128, y: u128, precission: u64)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u128, y: u128, precission: u64) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = (pow(10, precission) as u128);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/doc/math_fixed.md b/aptos-move/framework/aptos-stdlib/doc/math_fixed.md index e00553a0d52031..936d1ee6120904 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math_fixed.md +++ b/aptos-move/framework/aptos-stdlib/doc/math_fixed.md @@ -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)
use 0x1::error;
@@ -294,39 +293,6 @@ Specialized function for x * y / z that omits intermediate shifting
 
 
 
-
-
-
-
-## 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
-
-
-
#[testonly]
-fun assert_approx_the_same(x: u128, y: u128, precission: u128)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u128, y: u128, precission: u128) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = math128::pow(10, precission);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md b/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md index a436af50f9bd54..7dcaa1dda440c8 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md +++ b/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md @@ -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)
use 0x1::error;
@@ -289,39 +288,6 @@ Specialized function for x * y / z that omits intermediate shifting
 
 
 
-
-
-
-
-## 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
-
-
-
#[testonly]
-fun assert_approx_the_same(x: u256, y: u256, precission: u128)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u256, y: u256, precission: u128) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = (math128::pow(10, precission) as u256);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/sources/math128.move b/aptos-move/framework/aptos-stdlib/sources/math128.move index a37cbe094d4f1f..8f4dee3fb9ad7d 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math128.move +++ b/aptos-move/framework/aptos-stdlib/sources/math128.move @@ -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) { diff --git a/aptos-move/framework/aptos-stdlib/sources/math64.move b/aptos-move/framework/aptos-stdlib/sources/math64.move index 6aa733ed7fca6b..9cf086c36182df 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math64.move +++ b/aptos-move/framework/aptos-stdlib/sources/math64.move @@ -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) { diff --git a/aptos-move/framework/aptos-stdlib/sources/math_fixed.move b/aptos-move/framework/aptos-stdlib/sources/math_fixed.move index 8046246da6f04c..b7993a5f13bf42 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math_fixed.move +++ b/aptos-move/framework/aptos-stdlib/sources/math_fixed.move @@ -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) { diff --git a/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move b/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move index 34cf37ca37a667..2369b6afebc3e0 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move +++ b/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move @@ -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) {