首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决- NotSerializableException在bootcamp-cordapp.测试合同

如何解决- NotSerializableException在bootcamp-cordapp.测试合同
EN

Stack Overflow用户
提问于 2019-09-20 18:07:26
回答 1查看 152关注 0票数 1

我正试着为合同运行corda-bootcamp测试用例。我按照视频中给出的,但是当我试图运行合同测试-我得到错误。

代码语言:javascript
复制
java.io.NotSerializableException: data(net.corda.core.contracts.ContractState) -> Trying to build an object serializer for bootcamp.TokenState, but it is not constructible from its public properties, and so requires a custom serialiser.

有人能帮忙吗,怎么解决这个问题?我发现了一个类似的问题-- here,但这不起作用。

下面是使用的Tokenstate,

代码语言:javascript
复制
package bootcamp;

import com.google.common.collect.ImmutableList;
import net.corda.core.contracts.BelongsToContract;
import net.corda.core.contracts.ContractState;
import net.corda.core.identity.AbstractParty;
import net.corda.core.identity.Party;

import java.util.ArrayList;
import java.util.List;

/* Our state, defining a shared fact on the ledger.
 * See src/main/java/examples/ArtState.java for an example. */
@BelongsToContract(TokenContract.class)
public class TokenState implements ContractState {

    private Party issuer;
    private Party owner;
    private int amount;

    public TokenState(Party issuer, Party owner, int amount) {
        this.issuer = issuer;
        this.owner = owner;
        this.amount = amount;
    }

    public Party getIssuer() {
        return issuer;
    }

    public Party getOwner() {
        return owner;
    }

    public int getAmount() {
        return amount;
    }

    public List<AbstractParty> getParticipants() {
        List<AbstractParty> participants = new ArrayList<>();
        participants.add(issuer);
        participants.add(owner);
        return participants;
    }
}

抛出错误的测试用例,

代码语言:javascript
复制
private final TestIdentity alice = new TestIdentity(new CordaX500Name("Alice", "", "GB"));
    private final TestIdentity bob = new TestIdentity(new CordaX500Name("Bob", "", "GB"));
    private MockServices ledgerServices = new MockServices(new TestIdentity(new CordaX500Name("TestId", "", "GB")));

    private TokenState tokenState = new TokenState(alice.getParty(), bob.getParty(), 1);

@Test
public void tokenContractRequiresZeroInputsInTheTransaction() {
        transaction(ledgerServices, tx -> {
            // Has an input, will fail.
            tx.input(TokenContract.ID, tokenState);
            tx.output(TokenContract.ID, tokenState);
            tx.command(Arrays.asList(alice.getPublicKey(), bob.getPublicKey()), new TokenContract.Commands.Issue());
            tx.fails();
            return null;
        });

        transaction(ledgerServices, tx -> {
            // Has no input, will verify.
            tx.output(TokenContract.ID, tokenState);
            tx.command(Arrays.asList(alice.getPublicKey(), bob.getPublicKey()), new TokenContract.Commands.Issue());
            tx.verifies();
            return null;
        });
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-22 04:36:29

Corda使用自己的序列化框架,该框架要求Java编译器在生成字节码时保留参数名,以便以后能够正确地重新创建对象。

要使它与IntelliJ一起工作,请执行以下操作:

打开设置:

代码语言:javascript
复制
- Windows: File -> Settings
- osX/ Ubuntu: IntelliJ IDEA -> Preferences

  1. 到构建、执行、部署->编译器-> ->编译器在附加命令行参数字段

中写入-parameters

  1. 完全重建项目(构建->重建项目)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58033294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档