【发布时间】:2022-07-09 05:46:29
【问题描述】:
我的智能合约中有这种情况:
address[] public allowedUsers;
function allowUser(address _newUser) public onlyOwner {
allowedUser.push(_newUser);
}
我正在使用 truffle 和他的测试套件,然后我写了这个案例,失败可能是因为我没有以正确的方式使用唯一的所有者方法:
const MyContract = artifacts.require("../contracts/MyContract.sol");
contract("MyContract", accounts => {
it("should deploy the contract and allow the user", async () => {
const contract = await MyContract.deployed();
const account = accounts[0];
const owner = await contract.owner.call()
await contract.allowUser(account).call({ from: owner });
const allowedUser = contract.allowedUser.call(0);
assert.equal(whitelistedUser, account, 'new user is not allowed');
})
});
有人可以帮我吗?
【问题讨论】:
标签: javascript unit-testing solidity truffle