我正在尝试测试这个智能契约,但我似乎无法克服这个错误,我使用的是最新的松露套件v5.1.16和web3 v1.2.6。
KTokenSale.test.js
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const KToken = artifacts.require('KToken');
const KTokenCrowdsale = artifacts.require('KTokenCrowdsale');
contract('KTokenCrowdsale', function([_, wallet, investor1, investor2]) {
beforeEach(async function () {
this.name = 'TestToken';
this.symbol = 'TT';
this.decimals = 16;
this.token = await KToken.new(
this.name,
this.symbol,
this.decimals
);
this.rate = 850;
this.wallet = wallet;
this.crowdsale = await KToken.new(
this.rate,
this.wallet,
this.token.address
);
});
});
contract('crowdsale', function() {
it('tracks the rate', async function() {
const rate = await this.crowdsale.rate();
rate.should.be.bignumber.equal(this.rate);
});
it('tracks the wallet', async function() {
const wallet = await this.crowdsale.wallet();
wallet.should.equal(this.wallet);
});
it('tracks the token', async function() {
const token = await this.crowdsale.token();
token.should.equal(this.token.address);
});
});正在测试的智能合同代码:
pragma solidity ^0.5.11;
import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/CappedCrowdsale.sol";
contract KTokenCrowdsale is Crowdsale, CappedCrowdsale {
uint256 public investorMinCap = 7000000000000000000;
uint256 public investorMaxCap = 350000000000000000000;
mapping(address => uint256) public contributions;
constructor(
uint256 _rate,
address payable _wallet,
IERC20 _token,
uint256 _cap
)
Crowdsale(_rate, _wallet, _token)
CappedCrowdsale(_cap) public {}
}发布于 2020-03-10 23:56:01
web3.BigNumber on web3.js v0.x,web3.utils.BN on web3.js v1.x。
请注意,bignumber.js处理非整数值,这意味着它可以:
Number类型或String类型)这一点,虽然bn.js不处理非整数值,正如明确指出的那样:
注意:这个库不支持小数。
由于Solidity不支持非整数值,web3.js开发团队最终决定用BigNumber代替BN,而不是截断web3用户传递给web3函数的每个非整数值(从而使用户不知道代码中的潜在错误)。
https://ethereum.stackexchange.com/questions/80508
复制相似问题