我正在使用Corda V2(Java)并且有一份合同迫切需要进行单元测试。但很快就陷入了试图对MyContract
的创建进行逆向工程的兔子洞。是否有任何框架支持来测试verify()
方法public class MyContract implements Contract {
// This is used to identify our contract when building a transaction.
public static final String MY_CONTRACT_ID = "com.exchange.data.address.MyContract";
// Our Create command.
public static class Create implements CommandData {
}
@Override
public void verify(LedgerTransaction tx) {
final CommandWithParties<MyContract.Create> command = requireSingleCommand(tx.getCommands(), MyContract.Create.class);
requireThat(check -> {
// Constraints on the shape of the transaction.
check.using("No inputs should be consumed when exchanging data.", tx.getInputs().isEmpty());
check.using("There should be one output state of type MyState.", tx.getOutputs().size() == 1);
final MyState out = tx.outputsOfType(MyState.class).get(0);
final Party sender = out.getSender();
final Party receiver = out.getReceiver();
check.using("The sender and the receiver cannot be the same entity.", !sender.getName().equals(receiver.getName()));
// Constraints on the signers.
final List<PublicKey> signers = command.getSigners();
check.using("There must be two signers.", signers.size() == 2);
check.using("The sender and receiver must be signers.", signers.containsAll(
ImmutableList.of(sender.getOwningKey(), receiver.getOwningKey())));
return null;
});
}
?
type alias Model = { position : { x : Int, y : Int} }
update : Msg -> Model -> (Model,Cmd.Cmd Msg)
update (MouseMsg pos) model = ({ position = {x = model.position.x + pos.x, y = model.position.y + pos.y} },Cmd.none)
view : Model -> Html.Html Msg
view model = let
posX = toString model.position.x
posY = toString model.position.y
in
svg [width "600",height "600"] [circle [cx "300",cy "300", r "50", fill "blue", x posX, y posY] []]
答案 0 :(得分:1)
是的,您可以使用Corda的合同测试框架。
API文档位于:https://docs.corda.net/api-testing.html#contract-testing(请注意,这些是针对V3的。这些文档对于V2不存在。)
您可以在此处查看一些示例用法:https://github.com/corda/cordapp-example/blob/release-V2/java-source/src/test/java/com/example/contract/IOUContractTests.java。