I’m running into an issue where the ‘deployer is the owner’ test fails when using the: @openzeppelin/contracts-ethereum-package
Environment
@openzeppelin/contracts-ethereum-package@2.4.0
(also tested with @openzeppelin/contracts-ethereum-package@2.2.3
after reading this thread.)
@openzeppelin/cli@2.7.1
@openzeppelin/test-environment@0.1.2
mocha@7.0.1
chai@4.2.0
I ran this to link:
npx oz link @openzeppelin/contracts-ethereum-package
Details
If i’m understanding the failure correctly it seems like a false positive as when I deploy the contract it initializes with the deployer address as the owner as expected.
Test command:
oz compile && mocha --exit --recursive test
In an attempt to identify the root of the issue I simplified down to a basic contract that I found posted in the forums. I created two separate projects, one that uses contracts-ethereum-package
and one that uses @openzeppelin/contracts@2.5.0
. The contract using the latter package passes the test without issue. The former fails.
Code to reproduce
// MyContract.sol - Fails test
pragma solidity ^0.5.0;
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
contract MyContract is Ownable {
function normalThing() public {
// anyone can call this normalThing()
}
function specialThing() public onlyOwner {
// only the owner can call specialThing()!
}
}
//MyContract.sol - Passes test
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/ownership/Ownable.sol";
contract MyContract is Ownable {
function normalThing() public {
// anyone can call this normalThing()
}
function specialThing() public onlyOwner {
// only the owner can call specialThing()!
}
}
Using the same test script for both:
// test/MyContract.test.js -
const { accounts, contract } = require("@openzeppelin/test-environment");
const { expect } = require("chai");
const MyContract = contract.fromArtifact("MyContract");
describe("MyContract", function() {
const [owner] = accounts;
beforeEach(async function() {
this.myContract = await MyContract.new({ from: owner });
});
it("the deployer is the owner", async function() {
expect(await this.myContract.owner()).to.equal(owner);
});
});
Any insights or assistance would be most appreciated. I’m new ish to Solidity so it seems likely that i’m missing something basic.
Thanks!