我要开始编程了。我想完成我的第一份合同,于是我把totalSupply分配给了1000000。
pragma solidity ^0.5.8;
/**
* The DappToken
contract Constructor
Set the total number of tokens
Read the total number of tokens
*/
contract DappToken {
uint256 public totalSupply;
function Supply () public {
totalSupply = 1000000;
}
}当我运行测试时,它不会通过。它说实际的totalSupply设置为零。以下是代码:
var DappToken = artifacts.require ("DappToken");
contract("DappToken", function(accounts) {
var tokenInstance;
it("sets the total supply upon deployment", function() {
return DappToken.deployed().then(function(instance) {
tokenInstance = instance;
return tokenInstance.totalSupply();
}) .then(function(totalSupply) {
assert.equal(totalSupply.toNumber(), 1000000, "sets the total supply to 1000000")
});
});
})运行松露迁移时的结果是
Contract:DappToken
1) sets the total supply upon deployment
> No events were emitted而且没有通过预期的1000000实际0
发布于 2019-07-05 01:00:26
目前,您的代码只有一个公共状态变量totalSupply。若要设置值,需要执行Supply函数(根据收到的注释)。
建议阅读关于令牌的OpenZeppelin指南,https://docs.openzeppelin.org/v2.3.0/tokens
https://ethereum.stackexchange.com/questions/72561
复制相似问题