首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ERC20 RefundableCrowdsale

ERC20 RefundableCrowdsale
EN

Ethereum用户
提问于 2019-05-29 21:41:35
回答 1查看 119关注 0票数 1

我有一份从OpenZeppelin继承OpenZeppelin的众包合同。我最初使用的是他们的v1.10.0,但现在用v1.12.0对其进行了修改。

contract TestTokenCrowdsale is Crowdsale, MintedCrowdsale, CappedCrowdsale, TimedCrowdsale, WhitelistedCrowdsale, RefundableCrowdsale { ... }

并编写了一个测试脚本来测试退款。

在1.10.0版中,这种方法奏效了:

代码语言:javascript
复制
const RefundVault = artifacts.require('./RefundVault');

contract('TestTokenCrowdsale', function(accounts) {
    beforeEach(async function () {
        ...
        this.goal = ether(50);

        this.crowdsale = await TestTokenCrowdsale.new(
            ...
            this.goal
        );

        // Track refund vault
        this.vaultAddress = await this.crowdsale.vault();
        this.vault = RefundVault.at(this.vaultAddress);
    )};

    describe('during crowdsale', function() {
      it('prevents other accounts from claiming refund', async function() {
        await this.vault.refund(accounts[2], { from: accounts[2]}).should.be.rejectedWith(EVMRevert);
      });
    });    
}

但在1.12.0版中,RefundVault.sol已改为RefundEscrow.sol

在此之前,我可以追踪beforeEach的退款金库。

代码语言:javascript
复制
this.vaultAddress = await this.crowdsale.vault();
this.vault = RefundVault.at(this.vaultAddress); 

这是可能的,因为this.crowdsale.vault()是v1.10.0中的公共的。但是,由于在1.12.0版本中,escrow变成了私有,所以我不知道如何相应地修改它。

this.vault.refund也不能工作,因为它们在1.12.0版本中也删除了refund

如何在1.12.0版本中更改为测试prevents other accounts from claiming refund

EN

回答 1

Ethereum用户

回答已采纳

发布于 2019-05-30 06:48:27

建议您查看OpenZeppelin v1.12对RefundableCrowdsale的测试,以了解如何测试退款被拒绝。RefundableCrowdsale.test.js

代码语言:javascript
复制
  it('should deny refunds before end', async function () {
    await expectThrow(this.crowdsale.claimRefund({ from: investor }), EVMRevert);
    await increaseTimeTo(this.openingTime);
    await expectThrow(this.crowdsale.claimRefund({ from: investor }), EVMRevert);
  });

  it('should deny refunds after end if goal was reached', async function () {
    await increaseTimeTo(this.openingTime);
    await this.crowdsale.sendTransaction({ value: goal, from: investor });
    await increaseTimeTo(this.afterClosingTime);
    await expectThrow(this.crowdsale.claimRefund({ from: investor }), EVMRevert);
  });

您可能想看看搬到OpenZeppelin 2.2

也是OpenZeppelin 2.3 RC3

如果您有更多关于OpenZeppelin的问题,可以在论坛中询问。

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

https://ethereum.stackexchange.com/questions/71250

复制
相关文章

相似问题

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