Trouble with testing when a contract has a selfdestruct operation

Hello. We use openzeppelin extensively in our project, and currently have 2 contracts in our project.json.
I’m attempting to add a third contract (PublicLock.sol) to the project. Running openzeppelin add PublicLock works as expected, adding it to the project.json. I’m also able to successfully run openzeppelin push --network development --force, as there is a selfdestruct operation in PublicLock.sol(I’m aware of the risks of this)
However, testing is not working.
We run our tests with truffle, via an npm script “test” (cross-env NODE_ENV=test truffle test --network development), but as soon as I add the new contract to the oz project, I can’t run tests anymore. The error is:

Error: One or more contracts have validation errors. Please review the items listed above and fix them, or run this command again with the --force option.
    at NetworkController.<anonymous> (/Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/src/models/network/NetworkController.ts:135:13)
    at (<anonymous>)
    at /Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/lib/models/network/NetworkController.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/lib/models/network/NetworkController.js:4:12)
    at NetworkController.push (/Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/lib/models/network/NetworkController.js:93:16)
    at /Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/src/scripts/push.ts:21:22
    at (<anonymous>)
    at /Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/lib/scripts/push.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/lib/scripts/push.js:4:12)
    at push (/Users/overlord/DAPPS/unlock/smart-contracts/node_modules/@openzeppelin/cli/lib/scripts/push.js:18:12)
    at zosDeploy (/Users/overlord/DAPPS/unlock/smart-contracts/migrations/2_deploy_unlock.js:12:9)
    at deployUnlock (/Users/overlord/DAPPS/unlock/smart-contracts/migrations/2_deploy_unlock.js:24:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.8 (core: 5.1.8)
Node v10.15.0
error Command failed with exit code 1.

Using the --force flag changes nothing.
Any thoughts on how I can proceed here?
Thanks in advance.

1 Like

Hi @n44o,

I created a simple contract and was able to test using both Truffle and OpenZeppelin Test Environment.

Though I am not using push, only doing a create.

I assume that you are doing more in your test than my simple setup. If the following doesn’t work for you, if you could provide your test (or a cutdown version) and I can attempt to reproduce.


// contracts/Destroy.sol
pragma solidity ^0.5.0;

contract Destroy {
    function destroy() public {

Destroy.test.js (Truffle)

A similar test also works in OpenZeppelin Test Environment

const { expect } = require('chai');

const { TestHelper } = require('@openzeppelin/cli');
const { Contracts, ZWeb3 } = require('@openzeppelin/upgrades');


const Destroy = Contracts.getFromLocal('Destroy');

contract('Destroy', function (accounts) {
  const [ owner, other ] = accounts;

  beforeEach(async function () {
    this.project = await TestHelper();
    this.proxy = await this.project.createProxy(Destroy);

  it('destroy', async function () {
    await this.proxy.methods.destroy().send({ from: owner });

oz create

OpenZeppelin CLI allows for contracts to be created (without intermediate steps)
A warning will be given for the selfdestruct (compared with a push which requires --force)

$ npx oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate Destroy
? Pick a network development
✓ Added contract Destroy
- Contract Destroy or one of its ancestors has a potentially unsafe selfdestruct operation. See
✓ Contract Destroy deployed
All contracts have been deployed
? Call a function to initialize the instance after creating it? No
✓ Setting everything up to create contract instances
✓ Instance created at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601

Hi @n44o,

I wanted to check how you got on with this?

Hi @abcoathup
Thanks for looking at this for me. I wasn’t able to resolve it, but the team decided to go a different route and use a custom script for deploying this contract, rather than the oz-cli.
That said, if others have an similar issue, I would be happy to help out, give more details, etc to help figure this out if it would help out the community.
Otherwise, we can consider it resolved for now.

1 Like

Hi @n44o,

Thanks. Sorry that you couldn’t resolve.

We will wait to see if anyone in the community runs into this issue.