You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using `expectRevert()`, the passing the string: "Ownable: Caller is not the owner", instead of "Ownable: caller is not the owner" will trigger an error.
The distinction is in the capitalized C in caller.
I find it strange that passing a capitalized letter in a string parameter would trigger an error.
Error:
Caller is capitalized causing unexpected error.
it("non owner cannot store a value",asyncfunction(){// Test a transaction revertsawaitexpectRevert(this.box.setter(value,{from: other}),// note using Caller instead of caller will trigger error"Ownable: Caller is not the owner");});
Solution:
Caller is not capitalized. No error.
it("non owner cannot store a value",asyncfunction(){// Test a transaction revertsawaitexpectRevert(this.box.setter(value,{from: other}),// note using Caller insted of caller will trigger error"Ownable: caller is not the owner");});
Error message:
Using network 'development'.Compiling your contracts...===========================
> Everything is up to date, there is nothing to compile. Contract: Box ✓ getter returns a value previously stored ✓ setter emits an event 1) non owner cannot store a value Events emitted during test: --------------------------- Box.OwnershipTransferred( previousOwner: <indexed> 0x0000000000000000000000000000000000000000 (type: address), newOwner: <indexed> 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1 (type: address) ) --------------------------- 2 passing (267ms) 1 failing 1) Contract: Box non owner cannot store a value: Wrong kind of exception received + expected - actual -Transaction: 0x07151ccfcbc657daafc2c553c0b7c068a40d3cc31f699c793e65d1f4db18feef exited with an error (status 0). Reason given: Ownable: caller is not the owner. - Please check that the transaction: - - satisfies all conditions set by Solidity `require` statements. - - does not trigger a Solidity `revert` statement. +Ownable: Caller is not the owner at expectException (/Users/devrel/Desktop/Code/OZTutorial/node_modules/@openzeppelin/test-helpers/src/expectRevert.js:20:30) at processTicksAndRejections (node:internal/process/task_queues:96:5) at expectRevert (/Users/devrel/Desktop/Code/OZTutorial/node_modules/@openzeppelin/test-helpers/src/expectRevert.js:75:3) at Context.<anonymous> (Box.test.js:50:5)
Steps to reproduce error:
Have smart contract and testing code from Learn section. Small note:retrieve() is named getter, store() is named setter(), reciept variable is named setterReciept.
run truffle test npx truffle test
Become a bug enjoyer.
Entire code code context
Box.test.js
// test/Box.test.js// Load dependenciesconst{ expect }=require("chai");// Import utilities from openzepplin/test-helpersconst{BN, expectEvent, expectRevert }=require("@openzeppelin/test-helpers");// Load compiled artifactsconstBox=artifacts.require("Box");// Start test block// passing addresses: owner, othercontract("Box",function([owner,other]){// Make available in large integers ('big numbers) in all tests// since at top of scopeconstvalue=newBN("42");beforeEach(asyncfunction(){// Deploy a new Box contract for each test// from owner addressthis.box=awaitBox.new({from: owner});});// Test casesit("getter returns a value previously stored",asyncfunction(){// Store a value sent by ownerawaitthis.box.setter(value,{from: owner});// check bignumber equality of number stored vs set// not not needing to use strings to compare 256bit integers like belowexpect(awaitthis.box.getter()).to.be.bignumber.equal(value);// old assertion// expect((await this.box.getter()).toString()).to.equal("42");});it("setter emits an event",asyncfunction(){// set value from owner address and save recieptconstsetterReciept=awaitthis.box.setter(value,{from: owner});// test ValueChanged event was emitted on setter() call// note key-value pair: key = value, value = value// just a coicidence they are named the same// key will always be value.expectEvent(setterReciept,"ValueChanged",{value: value});});it("non owner cannot store a value",asyncfunction(){// Test a transaction revertsawaitexpectRevert(this.box.setter(value,{from: other}),// note using Caller instead of caller will trigger error"Ownable: Caller is not the owner");});});
Box.sol
// SPDX-License-Identifier: MITpragma solidity^0.8.13;
// Import Auth from access control sub-directory// import "./access-control/Auth.sol";// Import Ownable from the OpenZeppelin Contractsimport"@openzeppelin/contracts/access/Ownable.sol";
// Make Box inherit from the Ownable contractcontractBoxisOwnable {
uint256private _value; // private value, statically typed// Emit event when stored value changesevent ValueChanged(uint256value);
// old Auth.sol contract// constructor() {// _auth = new Auth(msg.sender);// }// uses onlyOwner function modifier from Ownablefunction setter(uint256value) public onlyOwner {
// old Auth.sol contract// // Require caller be registered as administrator in Auth // require(_auth.isAdministrator(msg.sender), "Unauthorized");
_value = value;
emitValueChanged(value);
}
function getter() publicviewreturns(uint256) {
return _value;
}
}
The text was updated successfully, but these errors were encountered:
Summary:
When using `expectRevert()`, the passing the string: "Ownable: Caller is not the owner", instead of "Ownable: caller is not the owner" will trigger an error.
The distinction is in the capitalized C in caller.
Context:
While doing Learn section in OpenZeppelin tutorial, stumbled upon error in performing-complex-assertions section of writing-automated-tests.
I find it strange that passing a capitalized letter in a string parameter would trigger an error.
Error:
Caller is capitalized causing unexpected error.
Solution:
Caller is not capitalized. No error.
Error message:
Steps to reproduce error:
Have smart contract and testing code from Learn section. Small note:
retrieve()
is namedgetter
,store()
is namedsetter()
,reciept
variable is namedsetterReciept
.run truffle test
npx truffle test
Become a bug enjoyer.
Entire code code context
Box.test.js
Box.sol
The text was updated successfully, but these errors were encountered: