From fa01d8932c680d36120a2cc920b0fcd4e3c5e4d0 Mon Sep 17 00:00:00 2001 From: SevenLM361 <42933171+SevenLM361@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:09:37 +0800 Subject: [PATCH 1/2] Update developing-smart-contracts.adoc Ownable add initialOwner --- .../learn/modules/ROOT/pages/developing-smart-contracts.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/learn/modules/ROOT/pages/developing-smart-contracts.adoc b/components/learn/modules/ROOT/pages/developing-smart-contracts.adoc index 86bc4567..9e498cc7 100644 --- a/components/learn/modules/ROOT/pages/developing-smart-contracts.adoc +++ b/components/learn/modules/ROOT/pages/developing-smart-contracts.adoc @@ -316,6 +316,8 @@ contract Box is Ownable { event ValueChanged(uint256 value); + constructor(address initialOwner) Ownable(initialOwner) {} + // The onlyOwner modifier restricts who can call the store function function store(uint256 value) public onlyOwner { _value = value; From 937d849e298c71acdc35d57cd261cabd16bee907 Mon Sep 17 00:00:00 2001 From: SevenLM361 <42933171+SevenLM361@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:13:43 +0800 Subject: [PATCH 2/2] Update writing-automated-tests.adoc adapt the version 5.x.x --- .../modules/ROOT/pages/writing-automated-tests.adoc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/learn/modules/ROOT/pages/writing-automated-tests.adoc b/components/learn/modules/ROOT/pages/writing-automated-tests.adoc index bfbe3ef0..f04b810b 100644 --- a/components/learn/modules/ROOT/pages/writing-automated-tests.adoc +++ b/components/learn/modules/ROOT/pages/writing-automated-tests.adoc @@ -81,12 +81,15 @@ const { expect } = require('chai'); // Start test block describe('Box', function () { + let owner; + before(async function () { this.Box = await ethers.getContractFactory('Box'); }); beforeEach(async function () { - this.box = await this.Box.deploy(); + [owner] = await ethers.getSigners() + this.box = await this.Box.deploy(owner.address); await this.box.deployed(); }); @@ -192,14 +195,14 @@ contract('Box', function ([ owner, other ]) { const value = new BN('42'); beforeEach(async function () { - this.box = await Box.new({ from: owner }); + this.box = await Box.new(owner, { from: owner }); }); it('retrieve returns a value previously stored', async function () { await this.box.store(value, { from: owner }); // Use large integer comparisons - expect(await this.box.retrieve()).to.be.bignumber.equal(value); + expect((await this.box.retrieve()).toString()).to.equal(value.toString()); }); it('store emits an event', async function () { @@ -213,7 +216,7 @@ contract('Box', function ([ owner, other ]) { // Test a transaction reverts await expectRevert( this.box.store(value, { from: other }), - 'Ownable: caller is not the owner', + 'OwnableUnauthorizedAccount("' + other + '")', ); }); });