Skip to content

Commit e18f380

Browse files
authored
Merge pull request #15 from AntonAndell/master
Apply changes from issue #14
2 parents f10ab03 + 5b7a568 commit e18f380

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

unittest/src/main/java/score/Context.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public static Object call(BigInteger value,
9595

9696
public static<T> T call(Class<T> cls,
9797
Address targetAddress, String method, Object... params) {
98-
return cls.cast(call(targetAddress, method, params));
98+
var caller = stackWalker.getCallerClass();
99+
return cls.cast(sm.call(caller, BigInteger.ZERO, targetAddress, method, params));
99100
}
100101

101102
public static Object call(Address targetAddress, String method, Object... params) {

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
class ContextTest extends TestBase {
3131
private static final ServiceManager sm = getServiceManager();
3232
private static final Account owner = sm.createAccount();
33+
private static Score echoScore;
3334
private static Score helloScore;
3435

3536
@BeforeEach
3637
void setUp() throws Exception {
37-
helloScore = sm.deploy(owner, HelloWorld.class, "Alice");
38+
echoScore = sm.deploy(owner, Echo.class);
39+
helloScore = sm.deploy(owner, HelloWorld.class, "Alice", echoScore.getAddress());
3840
}
3941

4042
@Test
@@ -61,4 +63,16 @@ void hash() {
6163
assertArrayEquals(Crypto.hash("sha3-256", data),
6264
(byte[]) helloScore.call("computeHash", "sha3-256", data));
6365
}
66+
67+
@Test
68+
void callCasted() {
69+
String echoMessage = "test";
70+
assertEquals(echoMessage, helloScore.call("castedEcho", echoMessage));
71+
}
72+
73+
@Test
74+
void callTyped() {
75+
String echoMessage = "test";
76+
assertEquals(echoMessage, helloScore.call("typedEcho", echoMessage));
77+
}
6478
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package score;
2+
3+
import java.lang.String;
4+
import score.annotation.External;
5+
6+
public class Echo {
7+
8+
@External(readonly=true)
9+
public String echo(String message) {
10+
return message;
11+
}
12+
}

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

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

2121
public class HelloWorld {
2222
private final String name;
23+
private final Address echoAddress;
2324

24-
public HelloWorld(String name) {
25+
public HelloWorld(String name, Address echoAddress) {
2526
this.name = name;
27+
this.echoAddress = echoAddress;
2628
}
2729

2830
@External(readonly=true)
@@ -52,4 +54,14 @@ public byte[] computeHash(String algorithm, byte[] data) {
5254
}
5355
return null;
5456
}
57+
58+
@External(readonly=true)
59+
public String castedEcho(String message) {
60+
return (String) Context.call(echoAddress, "echo", message);
61+
}
62+
63+
@External(readonly=true)
64+
public String typedEcho(String message) {
65+
return Context.call(String.class, echoAddress, "echo", message);
66+
}
5567
}

0 commit comments

Comments
 (0)