Initial commit

This commit is contained in:
2025-02-18 21:56:51 +03:00
commit b56e6b5e46
19 changed files with 6998 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("MyContract", function () {
let myContract;
let owner;
let addr1;
let addr2;
beforeEach(async function () {
// Получаем аккаунты из Hardhat
[owner, addr1, addr2] = await ethers.getSigners();
// Деплоим контракт
const MyContract = await ethers.getContractFactory("MyContract");
myContract = await MyContract.deploy();
await myContract.deployed();
});
describe("Deployment", function () {
it("Should set the right owner", async function () {
expect(await myContract.owner()).to.equal(owner.address);
});
});
describe("Transactions", function () {
it("Should allow owner to set new owner", async function () {
await myContract.setOwner(addr1.address);
expect(await myContract.owner()).to.equal(addr1.address);
});
it("Should fail if non-owner tries to set new owner", async function () {
// Подключаемся к контракту от имени addr1
const contractConnectedToAddr1 = myContract.connect(addr1);
// Ожидаем, что транзакция будет отменена
await expect(
contractConnectedToAddr1.setOwner(addr2.address)
).to.be.revertedWith("Only owner can call this function");
});
});
});