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; 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 + '")', ); }); });