Przeglądaj źródła

Move rational tests into its own module

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 4 lat temu
rodzic
commit
b7aa8b0c02
4 zmienionych plików z 191 dodań i 157 usunięć
  1. 1 0
      CHANGELOG.md
  2. 1 0
      tests/solana_tests/mod.rs
  3. 189 0
      tests/solana_tests/rational.rs
  4. 0 157
      tests/solana_tests/simple.rs

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ will be documented here.
 - Added supported for Events on Solana
 - `msg.value`, `block.number`, and `block.slot` are implemented for Solana
 - Verify ed25519 signatures with `signatureVerify()` on Solana
+- Added support for Rational numbers
 
 ### Changed
 - On Solana, the return data is now provided in the program log. As a result,

+ 1 - 0
tests/solana_tests/mod.rs

@@ -13,6 +13,7 @@ mod expressions;
 mod hash;
 mod mappings;
 mod primitives;
+mod rational;
 mod returns;
 mod signature_verify;
 mod simple;

+ 189 - 0
tests/solana_tests/rational.rs

@@ -0,0 +1,189 @@
+use crate::{build_solidity, first_error, parse_and_resolve};
+
+#[test]
+fn rational() {
+    let ns = parse_and_resolve(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                uint y = 0.1;
+                return y;
+            }
+        }"#,
+        crate::Target::Solana,
+    );
+
+    assert_eq!(
+        first_error(ns.diagnostics),
+        "conversion to uint256 from rational not allowed"
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                uint x = .5 * 8;
+                return x;
+            }
+
+            function test2() public returns (uint) {
+                uint x = .4 * 8 + 0.8;
+                return x;
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function("test", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(4))]
+    );
+
+    let returns = vm.function("test2", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(4))]
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                uint x = 4.8 + 0.2;
+                return x;
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function("test", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(5))]
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                uint x = 4.8 / 0.2;
+                return x;
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function("test", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(24))]
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                uint x = 4.8 % 0.2;
+                return x;
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function("test", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(0))]
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                uint x = 5.2 - 1.2;
+                return x;
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function("test", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(4))]
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                return 1.4 + 1.6;
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function("test", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(3))]
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test() public returns (uint) {
+                return 1.4e4 + 1.6e3;
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function("test", &[], &[], 0);
+
+    assert_eq!(
+        returns,
+        vec![ethabi::Token::Uint(ethereum_types::U256::from(15600))]
+    );
+
+    let mut vm = build_solidity(
+        r#"
+        contract foo {
+            function test(uint64 x) public returns (uint64, uint) {
+                return (x * 961748941, 2.5 + 3.5 - 1);
+            }
+        }"#,
+    );
+
+    vm.constructor("foo", &[], 0);
+
+    let returns = vm.function(
+        "test",
+        &[ethabi::Token::Uint(ethereum_types::U256::from(982451653))],
+        &[],
+        0,
+    );
+
+    assert_eq!(
+        returns,
+        vec![
+            ethabi::Token::Uint(ethereum_types::U256::from(961748941u64 * 982451653u64)),
+            ethabi::Token::Uint(ethereum_types::U256::from(5))
+        ]
+    );
+}

+ 0 - 157
tests/solana_tests/simple.rs

@@ -144,163 +144,6 @@ fn returns() {
             ethabi::Token::Uint(ethereum_types::U256::from(961748941u64 * 982451653u64))
         ]
     );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test() public returns (uint) {
-                uint x = .5 * 8;
-                return x;
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function("test", &[], &[], 0);
-
-    assert_eq!(
-        returns,
-        vec![ethabi::Token::Uint(ethereum_types::U256::from(4))]
-    );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test() public returns (uint) {
-                uint x = 4.8 + 0.2;
-                return x;
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function("test", &[], &[], 0);
-
-    assert_eq!(
-        returns,
-        vec![ethabi::Token::Uint(ethereum_types::U256::from(5))]
-    );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test() public returns (uint) {
-                uint x = 4.8 / 0.2;
-                return x;
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function("test", &[], &[], 0);
-
-    assert_eq!(
-        returns,
-        vec![ethabi::Token::Uint(ethereum_types::U256::from(24))]
-    );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test() public returns (uint) {
-                uint x = 4.8 % 0.2;
-                return x;
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function("test", &[], &[], 0);
-
-    assert_eq!(
-        returns,
-        vec![ethabi::Token::Uint(ethereum_types::U256::from(0))]
-    );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test() public returns (uint) {
-                uint x = 5.2 - 1.2;
-                return x;
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function("test", &[], &[], 0);
-
-    assert_eq!(
-        returns,
-        vec![ethabi::Token::Uint(ethereum_types::U256::from(4))]
-    );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test() public returns (uint) {
-                return 1.4 + 1.6;
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function("test", &[], &[], 0);
-
-    assert_eq!(
-        returns,
-        vec![ethabi::Token::Uint(ethereum_types::U256::from(3))]
-    );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test() public returns (uint) {
-                return 1.4e4 + 1.6e3;
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function("test", &[], &[], 0);
-
-    assert_eq!(
-        returns,
-        vec![ethabi::Token::Uint(ethereum_types::U256::from(15600))]
-    );
-
-    let mut vm = build_solidity(
-        r#"
-        contract foo {
-            function test(uint64 x) public returns (uint64, uint) {
-                return (x * 961748941, 2.5 + 3.5 - 1);
-            }
-        }"#,
-    );
-
-    vm.constructor("foo", &[], 0);
-
-    let returns = vm.function(
-        "test",
-        &[ethabi::Token::Uint(ethereum_types::U256::from(982451653))],
-        &[],
-        0,
-    );
-
-    assert_eq!(
-        returns,
-        vec![
-            ethabi::Token::Uint(ethereum_types::U256::from(961748941u64 * 982451653u64)),
-            ethabi::Token::Uint(ethereum_types::U256::from(5))
-        ]
-    );
 }
 
 #[test]