Skip to content

Commit 59a05bf

Browse files
committed
Refactor CallTest
1 parent 801817c commit 59a05bf

File tree

4 files changed

+72
-42
lines changed

4 files changed

+72
-42
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2022 ICONLOOP Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package score;
18+
19+
import com.iconloop.score.test.Account;
20+
import com.iconloop.score.test.Score;
21+
import com.iconloop.score.test.ServiceManager;
22+
import com.iconloop.score.test.TestBase;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.junit.jupiter.api.Test;
25+
import score.annotation.External;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
29+
public class CallTest extends TestBase {
30+
private static final ServiceManager sm = getServiceManager();
31+
private static final Account owner = sm.createAccount();
32+
private static Score echoScore;
33+
34+
public static class Echo {
35+
@External(readonly=true)
36+
public String echo(String message) {
37+
return message;
38+
}
39+
40+
@External(readonly=true)
41+
public String castedEcho(String message) {
42+
return (String) Context.call(Context.getAddress(), "echo", message);
43+
}
44+
45+
@External(readonly=true)
46+
public String typedEcho(String message) {
47+
return Context.call(String.class, Context.getAddress(), "echo", message);
48+
}
49+
}
50+
51+
@BeforeAll
52+
static void setUp() throws Exception {
53+
echoScore = sm.deploy(owner, Echo.class);
54+
}
55+
56+
@Test
57+
void callCasted() {
58+
String echoMessage = "test";
59+
assertEquals(echoMessage, echoScore.call("castedEcho", echoMessage));
60+
}
61+
62+
@Test
63+
void callTyped() {
64+
String echoMessage = "test";
65+
assertEquals(echoMessage, echoScore.call("typedEcho", echoMessage));
66+
}
67+
}

unittest/src/test/java/score/ContextTest.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.iconloop.score.test.Score;
2121
import com.iconloop.score.test.ServiceManager;
2222
import com.iconloop.score.test.TestBase;
23-
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.BeforeAll;
2424
import org.junit.jupiter.api.Test;
2525
import score.impl.Crypto;
2626

@@ -32,10 +32,9 @@ class ContextTest extends TestBase {
3232
private static final Account owner = sm.createAccount();
3333
private static Score helloScore;
3434

35-
@BeforeEach
36-
void setUp() throws Exception {
37-
Score echoScore = sm.deploy(owner, Echo.class);
38-
helloScore = sm.deploy(owner, HelloWorld.class, "Alice", echoScore.getAddress());
35+
@BeforeAll
36+
static void setUp() throws Exception {
37+
helloScore = sm.deploy(owner, HelloWorld.class, "Alice");
3938
}
4039

4140
@Test
@@ -65,16 +64,4 @@ void hash() {
6564
(byte[]) helloScore.call("computeHash", algo, data));
6665
}
6766
}
68-
69-
@Test
70-
void callCasted() {
71-
String echoMessage = "test";
72-
assertEquals(echoMessage, helloScore.call("castedEcho", echoMessage));
73-
}
74-
75-
@Test
76-
void callTyped() {
77-
String echoMessage = "test";
78-
assertEquals(echoMessage, helloScore.call("typedEcho", echoMessage));
79-
}
8067
}

unittest/src/test/java/score/Echo.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

unittest/src/test/java/score/HelloWorld.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020

2121
public class HelloWorld {
2222
private final String name;
23-
private final Address echoAddress;
2423

25-
public HelloWorld(String name, Address echoAddress) {
24+
public HelloWorld(String name) {
2625
this.name = name;
27-
this.echoAddress = echoAddress;
2826
}
2927

3028
@External(readonly=true)
@@ -51,14 +49,4 @@ public long getBlockTimestamp() {
5149
public byte[] computeHash(String algorithm, byte[] data) {
5250
return Context.hash(algorithm, data);
5351
}
54-
55-
@External(readonly=true)
56-
public String castedEcho(String message) {
57-
return (String) Context.call(echoAddress, "echo", message);
58-
}
59-
60-
@External(readonly=true)
61-
public String typedEcho(String message) {
62-
return Context.call(String.class, echoAddress, "echo", message);
63-
}
6452
}

0 commit comments

Comments
 (0)