-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.sw
76 lines (63 loc) · 2.15 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
contract;
abi TestDiscardedAssignment {
fn test_discarded_assignment_1();
fn test_discarded_assignment_2();
fn test_discarded_assignment_3();
fn test_discarded_assignment_4();
#[storage(read)]
fn test_discarded_assignment_5();
#[storage(read, write)]
fn test_discarded_assignment_6();
}
struct Counter {
value: u64,
}
storage {
counter: Counter = Counter {
value: 0,
},
}
impl TestDiscardedAssignment for Contract {
fn test_discarded_assignment_1() {
// Report entry should be created:
// L28: The `Contract::test_discarded_assignment_1` function makes an assignment to `x` which is discarded.
let x = 1;
}
fn test_discarded_assignment_2() {
// Report entry should not be created
let x = 1;
log(x);
}
fn test_discarded_assignment_3() {
// Report entry should be created:
// L40: The `Contract::test_discarded_assignment_3` function makes an assignment to `x` which is discarded by the assignment made on L44.
let mut x = 2;
// Report entry should be created:
// L44: The `Contract::test_discarded_assignment_3` function makes an assignment to `x` which is discarded.
x = 1;
}
fn test_discarded_assignment_4() {
// Report entry should not be created
let mut x = 2;
log(x);
// Report entry should not be created
x = 1;
log(x);
}
#[storage(read)]
fn test_discarded_assignment_5() {
// Report entry should be created:
// L61: The `Contract::test_discarded_assignment_5` function makes an assignment to `counter` which is discarded.
let mut counter = storage.counter.read();
// Report entry should be created:
// L65: The `Contract::test_discarded_assignment_5` function makes an assignment to `counter.value` which is discarded.
counter.value += 1;
}
#[storage(read, write)]
fn test_discarded_assignment_6() {
let mut counter = storage.counter.read();
counter.value += 1;
// Report entry should not be created
storage.counter.write(counter);
}
}