diff --git a/dao-contracts/contracts/Languages.sol b/dao-contracts/contracts/Languages.sol index 2ee1a2b..2f66c45 100644 --- a/dao-contracts/contracts/Languages.sol +++ b/dao-contracts/contracts/Languages.sol @@ -5,15 +5,35 @@ import { ILanguages } from "@elimu-ai/dao-contracts/ILanguages.sol"; /// @notice This smart contract stores the languages currently supported by the Ξlimu DAO (see https://github.com/elimu-ai/model). contract Languages is ILanguages { + address public owner; + /// @notice The ISO 639-2 language code of each language, in upper-case letters. E.g. "ENG" for English. mapping(string => bool) private languageCodes; + event OwnerUpdated(address); + event LanguageCodeAdded(string); + event LanguageCodeRemoved(string); + + constructor() { + owner = msg.sender; + } + + function updateOwner(address owner_) public { + require(msg.sender == owner, "Only the current owner can set a new owner"); + owner = owner_; + emit OwnerUpdated(owner_); + } + function addSupportedLanguage(string calldata languageCode) external { + require(msg.sender == owner, "Only the current owner can add a language"); languageCodes[languageCode] = true; + emit LanguageCodeAdded(languageCode); } function removeSupportedLanguage(string calldata languageCode) external { + require(msg.sender == owner, "Only the current owner can remove a language"); languageCodes[languageCode] = false; + emit LanguageCodeRemoved(languageCode); } function isSupportedLanguage(string calldata languageCode) external view returns (bool) { diff --git a/dao-contracts/hardhat-gas-report.md b/dao-contracts/hardhat-gas-report.md index 8c62234..07d29fd 100644 --- a/dao-contracts/hardhat-gas-report.md +++ b/dao-contracts/hardhat-gas-report.md @@ -13,9 +13,11 @@ ································|·················|···············|·················|················|··············· | Languages · │ ································|·················|···············|·················|················|··············· -| addSupportedLanguage · - · - · 44,216 · 3 · - │ +| addSupportedLanguage · - · - · 48,062 · 3 · - │ ································|·················|···············|·················|················|··············· -| removeSupportedLanguage · - · - · 22,338 · 1 · - │ +| removeSupportedLanguage · - · - · 26,228 · 1 · - │ +································|·················|···············|·················|················|··············· +| updateOwner · - · - · 27,983 · 1 · - │ ································|·················|···············|·················|················|··············· | Lock · │ ································|·················|···············|·················|················|··············· @@ -23,9 +25,9 @@ ································|·················|···············|·················|················|··············· | Deployments · · % of limit · │ ································|·················|···············|·················|················|··············· -| DummyERC20 · 558,532 · 558,676 · 558,604 · 1.9 % · - │ +| DummyERC20 · 558,540 · 558,684 · 558,612 · 1.9 % · - │ ································|·················|···············|·················|················|··············· -| Languages · - · - · 151,721 · 0.5 % · - │ +| Languages · - · - · 332,730 · 1.1 % · - │ ································|·················|···············|·················|················|··············· | Lock · - · - · 204,541 · 0.7 % · - │ ································|·················|···············|·················|················|··············· diff --git a/dao-contracts/test/Languages.ts b/dao-contracts/test/Languages.ts index bcc196b..9869f74 100644 --- a/dao-contracts/test/Languages.ts +++ b/dao-contracts/test/Languages.ts @@ -19,6 +19,12 @@ describe("Languages", function () { } describe("Deployment", function () { + it("Should set the right owner", async function () { + const { languages, owner } = await loadFixture(deployFixture); + + expect(await languages.owner()).to.equal(owner.address); + }); + it("Should not set any supported languages", async function () { const { languages } = await loadFixture(deployFixture); @@ -30,6 +36,16 @@ describe("Languages", function () { }); }); + describe("Update owner address", function () { + it("Should change the owner", async function () { + const { languages, owner, otherAccount } = await loadFixture(deployFixture); + + expect(await languages.owner()).to.equal(owner.address); + await languages.updateOwner(otherAccount.address); + expect(await languages.owner()).to.equal(otherAccount.address); + }); + }); + describe("Add supported language", function () { it("Newly set supported language should return `true`", async function () { const { languages } = await loadFixture(deployFixture);