首页 > 解决方案 > 处理事务时出现 VM 异常:恢复 TimedCrowdsale:未打开 --

问题描述

我遇到的问题与在部署后获得时间人群销售有关。我曾尝试使用 open Zepplin 的测试助手来解决此问题,但由于某种原因,我不断再次遇到此错误。请我已经为此工作了很长时间。

迁移文件

const Token = artifacts.require("./Token.sol");
const TokenSale = artifacts.require("./TokenCrowdsale.sol");
const KycContract = artifacts.require("./KycContract.sol");
const TestingTime = artifacts.require('TestingTime')
require('dotenv').config({ path: '../.env' });

module.exports = async function (deployer) {
  let startTime = Date.now() + 10;
  let endTime = startTime + 84000;
  let addr = await web3.eth.getAccounts();
  await deployer.deploy(TestingTime, startTime, endTime);
  await deployer.deploy(Token, process.env.INITIAL_TOKENS);
  await deployer.deploy(KycContract);
  await deployer.deploy(TokenSale, 500, addr[0], Token.address, 1000000000,
    startTime, endTime, KycContract.address);
  let Instance = await Token.deployed();
  await Instance.transfer(TokenSale.address, process.env.INITIAL_TOKENS);
};

测试文件松露测试

const TokenSale = artifacts.require("./TokenCrowdsale.sol");
const Token = artifacts.require("./Token.sol");
const KycContract = artifacts.require("./KycContract.sol");
const TestingTime = artifacts.require('./TestingTime.sol')


const time = require('@openzeppelin/test-helpers/src/time');
const chai = require("./chaisetup.js");
const BN = web3.utils.BN;
const expect = chai.expect;

require('dotenv').config({ path: '../.env' });

contract('TokenSale Test', async (accounts) => {

    const [deployerAccount, recipient, anotherAccount] = accounts;

    beforeEach(async () => {
        let address = await web3.eth.getAccounts();
        let startTime = (await time.latest()).add(time.duration.minutes(30))
        let endTime = (await time.latest()).add(time.duration.days(1))
        this.testingSale = await TokenSale.new(500, address[0], Token.address, 1000000000,
            startTime, endTime, KycContract.address)
    });

    it("there shouldnt be any coins in my account", async () => {
        let instance = await Token.deployed();
        return expect(instance.balanceOf.call(deployerAccount)).to.eventually.be.a.bignumber.equal(new BN(0));
    });


    it("all coins should be in the tokensale smart contract", async () => {
        await TestingTime.deployed()
        let instance = await Token.deployed();
        let balance = await instance.balanceOf.call(deployerAccount.address);
        let totalSupply = await instance.totalSupply.call();
        return expect(balance).to.be.a.bignumber.equal(totalSupply);
    });

    it("should be possible to buy one token by simply sending ether to the smart contract", async () => {
        await TestingTime.deployed()
        let tokenInstance = await Token.deployed();
        let tokenSaleInstance = await this.testingSale;
        let balanceBeforeAccount = await tokenInstance.balanceOf.call(recipient);

        expect(tokenSaleInstance.sendTransaction({ from: recipient, value: web3.utils.toWei("1", "wei") })).to.be.rejected;
        expect(balanceBeforeAccount).to.be.bignumber.equal(await tokenInstance.balanceOf.call(recipient));

        let kycInstance = await KycContract.deployed();
        await kycInstance.setKycCompleted(recipient);

        expect(tokenSaleInstance.sendTransaction({ from: recipient, value: web3.utils.toWei("1", "ether") })).to.be.fulfilled;
        return expect(balanceBeforeAccount + 1).to.be.bignumber.equal(await tokenInstance.balanceOf.call(recipient));
    });
});

标签: ethereumweb3truffleganache

解决方案


推荐阅读