ethereum - 处理事务时出现 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));
});
});
解决方案
推荐阅读
- c# - AWS RabbitMQ 没有一个端点是可访问的 C#
- python - 按索引访问数据框的列以进行验证
- python - Python 输出到 CSV 文件作业
- sql - 在 ORACLE SQL 中使用 distinct 时如何避免在列中出现重复
- node.js - 如何使用 JOI Validator 对嵌套 JSON 执行条件检查
- python - 为什么 tensorflow/keras 与训练和验证指标相距甚远?
- bash - 在 bash 脚本中,我有一组参数要传递给另一个 bash 脚本。我该怎么做?
- typescript - 如何从 Jest 中的超测试请求中检索 cookie?
- javascript - 如何使用 css 一张一张地展示我的幻灯片
- ffmpeg - 如何将多个 RTSP 的 FFMPEG 命令组合到 HLS