问题描述
是否可以模拟CordaRPCops,以便在项目中执行流而无需创建独立节点或内存中节点(例如在模拟网络中)?请让我知道.
Is it possible to mock CordaRPCops so as to execute a flow in project without creating a standalone node or in-memory node (like in a mock network) ? Kindly let me know.
我还添加了一个链接,我从github问题QA中找到了有关此内容的信息
推荐答案
在 TestDSL
中没有可用的特定类模拟 CordaRPCops
.如果您指的是在cordapp测试中模拟节点的某些功能,则应使用MockNode.
There is no specific class available mock CordaRPCops
in the TestDSL
. If you referring to mock some of the fuctionality of the node for cordapp testing, you should use the MockNode.
如果要在客户端应用程序中模拟 CordaRPCops
,则可以使用Mockito进行操作,例如以下示例:
If you want to Mock CordaRPCops
in the client app, you could use mockito to do so, example below:
测试:
@Test
public void testGetStateList(){
CordaRPCOps cordaRPCOps = Mockito.mock(CordaRPCOps.class);
Service service = new Service(cordaRPCOps);
Vault.Page<MyState> myStatePage =
new Vault.Page<>(Collections.EMPTY_LIST, Collections.EMPTY_LIST, 0L, Vault.StateStatus.ALL, Collections.EMPTY_LIST);
Mockito.when(cordaRPCOps.vaultQuery(MyState.class)).thenReturn(myStatePage);
service.getStateList();
}
服务:
public class Service {
CordaRPCOps cordaRPCOps;
public Service(CordaRPCOps cordaRPCOps) {
this.cordaRPCOps = cordaRPCOps;
}
public List<StateAndRef<MyState>> getStateList() {
return cordaRPCOps.vaultQuery(MyState.class).getStates();
}
}
这篇关于我们可以模拟"CordaRPCops"吗?在Cordapp中进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!