-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.sw
80 lines (61 loc) · 2.81 KB
/
main.sw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
contract;
use std::constants::ZERO_B256;
// Report entry should be created:
// L7: The `X` constant contains a large literal: `1000000000`. Consider refactoring it to be more readable: `1_000_000_000`
pub const X: u64 = 1000000000;
// Report entry should not be created
pub const Y: u64 = 10000;
configurable {
// Report entry should be created:
// L15: Configurable contains a large literal: `1000000000`. Consider refactoring it to be more readable: `1_000_000_000`
C_CONST: u64 = 1000000000,
// Report entry should not be created
D_CONST: u64 = 10000,
}
abi TestLargeLiteral {
fn test_large_literal_1();
fn test_large_literal_2();
fn test_large_literal_3();
}
trait HasValue {
const VALUE: u64;
const VALUE2: u64;
}
struct Error {}
impl HasValue for Error {
// Report entry should be created:
// L37: The `Error::VALUE` constant contains a large literal: `25000000`. Consider refactoring it to be more readable: `25_000_000`
const VALUE: u64 = 25000000;
// Report entry should not be created
const VALUE2: u64 = 1000;
}
fn function_call_single_large_literal(_amount: u64) {}
fn function_call_double_large_literal(_amount: u64, _to: Address) {}
impl TestLargeLiteral for Contract {
fn test_large_literal_1() {
// Report entry should be created:
// L50: The `Z` constant in the `const_func_large_literals` function contains a large literal: `1000000000000`. Consider refactoring it to be more readable: `1_000_000_000_000`
const Z = 1000000000000;
// Report entry should not be created
const L = 100000;
}
fn test_large_literal_2() {
// Report entry should be created:
// L59: The `Contract::let_func_large_literals` function contains a large literal: `20000000000`. Consider refactoring it to be more readable: `20_000_000_000`
let _big_a = 20000000000;
// Report entry should not be created
let _not_big_a = 200000;
}
fn test_large_literal_3() {
// Report entry should be created:
// L69: The `Contract::large_literals_fn_calls` function contains a large literal: `3000000000`. Consider refactoring it to be more readable: `3_000_000_000`
function_call_single_large_literal(3000000000);
// Report entry should not be created
function_call_single_large_literal(30000);
// Report entry should be created:
// L76: The `Contract::large_literals_fn_calls` function contains a large literal: `400000000000`. Consider refactoring it to be more readable: `400_000_000_000`
function_call_double_large_literal(400000000000, Address::from(0x0000000000000000000000000000000000000000000000000000000000000000));
// Report entry should not be created
function_call_double_large_literal(400000, Address::from(ZERO_B256));
}
}