我正在 Truffle 中测试我的合同。我启用了合约以接收 ERC721 代币:
chrome is not defined
有没有办法使用 Mocha 和 Chai 模拟将令牌发送到此合约?
答案 0 :(得分:1)
在 EVM 之外(例如在 JS 测试中),无法检查交易的返回值。只有它的状态(成功/恢复)、发出的事件(在你的情况下是非)和其他一些元数据。您还可以检查调用的返回值,如 assert.equal
语句。
contract('MyContract', () => {
it('receives a token', async () => {
const tx = await myContract.onERC721Received(
'0x123', // address
'0x456', // address _from
1, // uint256 _tokenId
[0x01, 0x02] // bytes calldata
);
assert.equal(tx.receipt.status, true); // tx succeeded
assert.equal(await contract.nftContract, '0x123');
assert.equal((await contract.tokenId).toNumber(), 1);
assert.equal(await contract.tokenAdded, true);
});
});
文档: