我有一份从OpenZeppelin继承OpenZeppelin的众包合同。我最初使用的是他们的v1.10.0,但现在用v1.12.0对其进行了修改。
contract TestTokenCrowdsale is Crowdsale, MintedCrowdsale, CappedCrowdsale, TimedCrowdsale, WhitelistedCrowdsale, RefundableCrowdsale { ... }
并编写了一个测试脚本来测试退款。
在1.10.0版中,这种方法奏效了:
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的退款金库。
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?
发布于 2019-05-30 06:48:27
建议您查看OpenZeppelin v1.12对RefundableCrowdsale的测试,以了解如何测试退款被拒绝。RefundableCrowdsale.test.js
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的问题,可以在论坛中询问。
https://ethereum.stackexchange.com/questions/71250
复制相似问题