2
2
3
3
import static convex .test .Assertions .assertCVMEquals ;
4
4
import static org .junit .jupiter .api .Assertions .assertEquals ;
5
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
5
6
import static org .junit .jupiter .api .Assertions .assertNull ;
6
7
import static org .junit .jupiter .api .Assertions .assertSame ;
7
8
import static org .junit .jupiter .api .Assertions .assertTrue ;
8
9
9
10
import java .io .IOException ;
10
11
11
12
import org .junit .jupiter .api .Test ;
13
+ import org .junit .jupiter .api .TestInstance ;
14
+ import org .junit .jupiter .api .TestInstance .Lifecycle ;
12
15
13
16
import convex .core .Constants ;
14
17
import convex .core .data .Address ;
20
23
import convex .core .lang .ops .Lookup ;
21
24
import convex .core .lang .ops .Special ;
22
25
26
+ @ TestInstance (Lifecycle .PER_CLASS )
23
27
public class SpecialTest extends ACVMTest {
24
28
25
29
@@ -46,22 +50,75 @@ public void testSpecialOrigin() {
46
50
// Hero should be *origin* in initial context
47
51
assertEquals (InitTest .HERO , eval ("*origin*" ));
48
52
53
+ // Origin should be preserved across query-as?
54
+ assertEquals (InitTest .HERO , eval ("(query-as #8 '*origin*)" ));
55
+
49
56
// *origin* MUST return original address within actor call
50
57
Context ctx =step ("(def act (deploy `(do (defn origin ^{:callable true} [] *origin*))))" );
51
58
assertEquals (InitTest .HERO , eval (ctx ,"(call act (origin))" ));
52
59
53
60
// *origin* MUST be original address in library call
54
61
assertEquals (InitTest .HERO , eval (ctx ,"(act/origin)" ));
55
62
}
63
+
64
+ @ Test
65
+ public void testSpecialKey () {
66
+ assertEquals (InitTest .HERO_KEYPAIR .getAccountKey (), eval ("*key*" ));
67
+ }
68
+
69
+ @ Test
70
+ public void testSpecialJuice () {
71
+ // TODO: semantics of returning juice before lookup complete is OK?
72
+ // seems sensible, represents "juice left at this position".
73
+ assertCVMEquals (0 , eval (Special .forSymbol (Symbols .STAR_JUICE )));
74
+
75
+ // juice gets consumed before returning a value
76
+ assertCVMEquals (Juice .DO + Juice .CONSTANT , eval (comp ("(do 1 *juice*)" )));
77
+ }
78
+
79
+ @ Test
80
+ public void testSpecialJuiceLimit () {
81
+ Special <CVMLong > spec =Special .forSymbol (Symbols .STAR_JUICE_LIMIT );
82
+
83
+ // Juice limit at start of transaction
84
+ assertCVMEquals (Constants .MAX_TRANSACTION_JUICE , eval (spec ));
85
+
86
+ // Consuming a small amount of juice shouldn't change limit
87
+ Context ctx =step ("1" );
88
+ assertCVMEquals (Constants .MAX_TRANSACTION_JUICE , eval (ctx ,"*juice-limit*" ));
89
+ }
90
+
91
+ @ Test
92
+ public void testSpecialJuicePrice () {
93
+ Special <?> jp =Special .forSymbol (Symbols .STAR_JUICE_PRICE );
94
+ assertNotNull (jp );
95
+ assertCVMEquals (Constants .INITIAL_JUICE_PRICE , eval (jp ));
96
+
97
+ assertCVMEquals (Constants .INITIAL_JUICE_PRICE , eval ("*juice-price*" ));
98
+
99
+ assertSame (context ().getState ().getJuicePrice (),eval ("*juice-price*" ));
100
+ }
101
+
102
+ @ Test
103
+ public void testSpecialPeer () {
104
+ assertNull (eval ("*peer*" ));
105
+ }
106
+
107
+ @ Test
108
+ public void testSpecialSigned () {
109
+ assertNull (eval ("*signer*" ));
110
+ }
56
111
57
112
@ Test
58
113
public void testSpecialAllowance () {
59
114
// Should have initial allowance at start
60
115
assertEquals (Constants .INITIAL_ACCOUNT_ALLOWANCE , evalL ("*memory*" ));
61
116
62
117
// Buy some memory
63
- assertEquals (Constants .INITIAL_ACCOUNT_ALLOWANCE , evalL ("*memory*" ));
118
+ assertEquals (Constants .INITIAL_ACCOUNT_ALLOWANCE + 1 , evalL ("(do (set-memory (inc *memory*)) *memory*) " ));
64
119
120
+ // Sell all memory
121
+ assertEquals (0 , evalL ("(do (set-memory 0) *memory*)" ));
65
122
}
66
123
67
124
@ Test
@@ -74,6 +131,9 @@ public void testSpecialMemoryPrice() {
74
131
// Buy some memory, should increase price
75
132
c =exec (c ,"(set-memory (+ *memory* 10))" );
76
133
assertTrue (price <evalD (c ,"*memory-price*" ));
134
+
135
+ // Check memory went down
136
+ assertTrue (evalL (c ,"*balance*" )<HERO_BALANCE );
77
137
}
78
138
79
139
@@ -166,8 +226,9 @@ public void testSpecialScope() {
166
226
@ Test
167
227
public void testSpecialEdgeCases () {
168
228
169
- // TODO: consider this
170
- //assertEquals(Init.HERO,eval(Init.CORE_ADDRESS+"/*balance*"));
229
+ // query-as interactions with *balance*
230
+ assertEquals (0 ,evalL ("(query-as #8 '*balance*)" ));
231
+ assertEquals (HERO_BALANCE ,evalL ("(query-as #8 '(query-as *caller* '*balance*))" ));
171
232
172
233
// Lookup in core environment of special returns the corresponding Special Op
173
234
assertSame (Special .get ("*juice*" ),eval ("(lookup *juice*)" ));
0 commit comments