ppt中的例子(1, 2, 3, ...)依次对应 contracts
, migrations
, test
中的(2, 3, 4, ...)
contracts
中的其他未标识数字的文件对应一本ERC20的依赖文件,其migration文件,对应其内序号10_deploy_mytoken.js
, 其测试文件为test
下的mytoken1.js
与mytoken2.js
.
truffle compile
truffle migrate
truffle test .\test\mytoken1.js
The difference between mytoken1.js
and mytoken2.js
is almost nothing.
mytoken1.js
is the official recommended style.
mytoken2.js
is a better way to adjust if different test cases are independent.
let instance = await MetaCoin.deployed()
0x133739AB03b9be2b885cC11e3B9292FDFf45440E
,
we can use let instance = await MyToken.at("0x133739AB03b9be2b885cC11e3B9292FDFf45440E")
to obtain the instance.instance.name() / await instance.name()
isntance.symobl()
(await instance.totalSupply()).toNumber()
let result = await instance.transfer(accounts[1], 100)
the returned structure is the following:
result = {
"tx": ..,
"receipt": ..,
"logs": []
}
await instance.approve(accounts[2], 100)
(await instance.allowance(accounts[0], accounts[2])).toNumber()
let result1 = await instance.transferFrom(accounts[0], accounts[2], 1, {from:accounts[2]})
({from: ***} to indicate the msg.sender of this transaction)
Note: in truffle console, accounts
by default means eth.web3.accounts
query balance : web3.eth.getBalance(accounts[0])
send ether: web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: web3.utils.toWei('1', "ether")})
From 7 on, we follow the test script styple giving OpenZeppelin.
npm install --save-dev @openzeppelin/test-helpers
For 14 npm install ethereumjs-abi --save
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。