Skip to content

Commit 10c6c06

Browse files
authored
Support inter-call simulation (#22)
1 parent ded6bda commit 10c6c06

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

unittest/src/main/java/com/iconloop/score/test/ServiceManager.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,18 @@ public abstract class ServiceManager {
8686
*/
8787
public abstract void invoke(Account from, BigInteger value, Address targetAddress, String method, Object... params);
8888

89-
@Deprecated
90-
public void call(Account from, BigInteger value, Address targetAddress, String method, Object... params) {
91-
this.invoke(from, value, targetAddress, method, params);
92-
}
89+
/**
90+
* Call specified method.
91+
* It simulates inter-call(or external-call).
92+
* Use {@link #invoke(Account, BigInteger, Address, String, Object...)} for external call.
93+
* @param from Contract account for inter-call (EoA account for external-call)
94+
* @param value Value to transfer on the call
95+
* @param targetAddress Receiver of the call
96+
* @param method Name of the method
97+
* @param params Parameters for the method
98+
* @return Returned value
99+
*/
100+
public abstract Object call(Account from, BigInteger value, Address targetAddress, String method, Object... params);
93101

94102
/**
95103
* Call specified method for read.

unittest/src/main/java/score/ServiceManagerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ public void invoke(Account from, BigInteger value, Address targetAddress, String
244244
}
245245
}
246246

247+
@Override
248+
public Object call(Account from, BigInteger value, Address targetAddress, String method, Object... params) {
249+
if (from == null) {
250+
throw new NullPointerException("from is null");
251+
}
252+
try (var scope = setupTransactionInfo(true)) {
253+
return handleCall(from, value, true, false, targetAddress, method, params);
254+
}
255+
}
247256

248257
@Override
249258
public Object call(Address targetAddress, String method, Object... params) {

0 commit comments

Comments
 (0)