我在试验我的合同。我启用了合同来接收ERC721令牌:
function onERC721Received(address, address _from, uint256 _tokenId, bytes calldata) external override returns(bytes4) {
nftContract = ERC721(msg.sender);
tokenId = _tokenId;
tokenAdded = true;
return 0x150b7a02;
}是否有一种方法可以模拟使用Mocha和Chai发送到此合同的令牌?
发布于 2021-07-07 19:04:23
在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);
});
});医生:
发布于 2022-01-19 17:52:59
在我的测试中,我也使用一个ERC721模拟合同来测试这一点。因此,我部署这两个契约并为它们创建新实例,然后从ERC721调用mint函数到测试地址下的契约。然后用以下方法检查ERC721的余额:
ERC721.balanceOf(underTest.address, 1)https://stackoverflow.com/questions/68289692
复制相似问题