【发布时间】:2022-06-10 22:27:38
【问题描述】:
我是 Solidity 新手,在使用开放式 Zepplin 插件之前尝试自己编写代码。
这是合同
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.5;
contract LeagueWinners {
struct Winner {
bool exists;
bool claimed;
uint256 reward;
}
mapping(address=>Winner) public winners;
mapping (address => bool) private AuthAccounts;
modifier onlyAuthAccounts() {
require(AuthAccounts[msg.sender], "Auth: caller is not the authorized");
_;
}
constructor () {
AuthAccounts[_addr_1] = true;
AuthAccounts[_addr_2] = true;
}
function addWinner(address _address, uint256 _amount ) public {
Winner storage winner = winners[_address];
winner.exists = true;
winner.reward = _amount;
}
}
我知道我们有来自 openzepplin 的 Ownable 插件。但只是尝试使用我自己的修饰符,因为我希望 2 个用户添加获胜者。
合同运作良好。但是我在编写测试用例时遇到了问题。
const { expect } = require("chai");
const { ethers } = require("hardhat");
const hre = require("hardhat");
describe("LeagueWinners", function () {
before(async () => {
LeagueWinners = await ethers.getContractFactory("LeagueWinners");
leagueWiners = await LeagueWinners.deploy();
await leagueWiners.deployed();
[owner] = await ethers.getSigners();
});
it("Claim Tokens to be deployed and verify owner", async function () {
expect(await leagueWiners.owner()).to.equal(owner.address);
});
it("Add Winner", async function () {
winner = await leagueWiners
.connect(owner)
.addWinner(
"_addr",
"50000000000000000000"
);
});
});
添加获胜者失败,不确定如何通过 AuthAccounts。任何指导都会有很大帮助
错误
Error: VM Exception while processing transaction: reverted with reason string 'Auth: caller is not the authorized'
【问题讨论】: