Package com.iconloop.score.test
Class ServiceManager
- java.lang.Object
-
- com.iconloop.score.test.ServiceManager
-
public abstract class ServiceManager extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ServiceManager.Block
-
Constructor Summary
Constructors Constructor Description ServiceManager()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.Object
call(Account from, java.math.BigInteger value, Address targetAddress, java.lang.String method, java.lang.Object... params)
Call specified method.abstract <T> T
call(java.lang.Class<T> cls, Address targetAddress, java.lang.String method, java.lang.Object... params)
Call specified method for read.abstract java.lang.Object
call(Address targetAddress, java.lang.String method, java.lang.Object... params)
Call specified method for read.abstract Account
createAccount()
Create new EoA account.abstract Account
createAccount(int initialIcx)
Create new EoA account with specified balance.abstract Account
createScoreAccount()
Create new dummy smart contract account.abstract Score
deploy(Account caller, java.lang.Class<?> mainClass, java.lang.Object... params)
Deploy contractabstract Score
deploy(Address addr, Account owner, java.lang.Object instance)
Deploy SCORE on specified address.abstract Account
getAccount(Address addr)
Get account.abstract ServiceManager.Block
getBlock()
Get last block information.static ServiceManager
getInstance()
Get singleton instance.abstract java.util.List<Event>
getLastEventLogs()
Get event logs of the last transaction.abstract <T> T
getValue(java.lang.Class<T> cls, Address address, java.lang.String key)
Get value of the storage of the contract.abstract void
invoke(Account from, java.math.BigInteger value, Address targetAddress, java.lang.String method, java.lang.Object... params)
Invoke specified method for write.abstract void
setValue(Address address, java.lang.String key, java.lang.Object value)
Set value of the storage of the contract.abstract void
transfer(Account from, Address targetAddress, java.math.BigInteger value)
Transfer native coin It simulates icx_sendTransaction with no dataType.
-
-
-
Method Detail
-
deploy
public abstract Score deploy(Account caller, java.lang.Class<?> mainClass, java.lang.Object... params) throws java.lang.Exception
Deploy contractIt simulates icx_sendTransaction with "deploy" dataType.
- Parameters:
caller
- Transaction sendermainClass
- Smart contract main class to be deployedparams
- Parameters used for constructor.- Returns:
- Score to manipulate others.
- Throws:
java.lang.Exception
- when it fails to deploy it.
-
createAccount
public abstract Account createAccount()
Create new EoA account.- Returns:
- created account
-
createAccount
public abstract Account createAccount(int initialIcx)
Create new EoA account with specified balance.- Parameters:
initialIcx
- Initial balance of the account- Returns:
- created account
-
getAccount
public abstract Account getAccount(Address addr)
Get account.- Parameters:
addr
- Address of the account- Returns:
- If it's already created, then it returns otherwise, it would be created.
-
createScoreAccount
public abstract Account createScoreAccount()
Create new dummy smart contract account.- Returns:
- created smart contract account.
-
deploy
public abstract Score deploy(Address addr, Account owner, java.lang.Object instance)
Deploy SCORE on specified address.It may overwrite already deployed one. But the data will be kept. It can be used for simulating system contract.
- Parameters:
addr
- Address of the SCOREowner
- Owner of the SCOREinstance
- Instance of smart contract- Returns:
- Created SCORE
-
invoke
public abstract void invoke(Account from, java.math.BigInteger value, Address targetAddress, java.lang.String method, java.lang.Object... params)
Invoke specified method for write. It simulates icx_sendTransaction with dataType "call".- Parameters:
from
- Sendervalue
- Value to transfer on calltargetAddress
- Receiver of the callmethod
- Name of the methodparams
- Parameters for the method
-
call
public abstract java.lang.Object call(Account from, java.math.BigInteger value, Address targetAddress, java.lang.String method, java.lang.Object... params)
Call specified method. It simulates inter-call(or external-call). Useinvoke(Account, BigInteger, Address, String, Object...)
for external call.- Parameters:
from
- Contract account for inter-call (EoA account for external-call)value
- Value to transfer on the calltargetAddress
- Receiver of the callmethod
- Name of the methodparams
- Parameters for the method- Returns:
- Returned value
-
call
public abstract java.lang.Object call(Address targetAddress, java.lang.String method, java.lang.Object... params)
Call specified method for read. It simulates icx_call.- Parameters:
targetAddress
- Receiver of the callmethod
- Name of the methodparams
- Parameters for the method- Returns:
- Return value of the method as it is
-
call
public abstract <T> T call(java.lang.Class<T> cls, Address targetAddress, java.lang.String method, java.lang.Object... params)
Call specified method for read. It simulates icx_call.- Type Parameters:
T
- Return type It will throw exception on prohibited types.- Parameters:
cls
- Return object typetargetAddress
- Receiver of the callmethod
- Name of the methodparams
- Parameters for the method- Returns:
- Return value of the method converted to the specified type.
-
transfer
public abstract void transfer(Account from, Address targetAddress, java.math.BigInteger value)
Transfer native coin It simulates icx_sendTransaction with no dataType.- Parameters:
from
- SendertargetAddress
- Receiver of the callvalue
- Amount to transfer
-
getValue
public abstract <T> T getValue(java.lang.Class<T> cls, Address address, java.lang.String key)
Get value of the storage of the contract.- Type Parameters:
T
- Output return type- Parameters:
cls
- Output object classaddress
- Contract addresskey
- Key for the storage- Returns:
- Deserialized value
-
setValue
public abstract void setValue(Address address, java.lang.String key, java.lang.Object value)
Set value of the storage of the contract.- Parameters:
address
- Contract addresskey
- Key for the storagevalue
- Value to be stored
-
getBlock
public abstract ServiceManager.Block getBlock()
Get last block information.- Returns:
- last block information
-
getLastEventLogs
public abstract java.util.List<Event> getLastEventLogs()
Get event logs of the last transaction.- Returns:
- list of events
- See Also:
GenerateTScore
-
getInstance
public static ServiceManager getInstance()
Get singleton instance.- Returns:
- singleton instance of it
-
-