私が抱えている問題は、展開後にタイム クラウド セールを初期化することに関連しています。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);
};
テスト ファイル Truffle テスト
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));
});
});