Error Handling for Proxy Contracts in web3 using .error

Hi @cjd9s,

I am not familiar with error handling in web3.

I recommend creating a simple example that demonstrates the problem such as modifying the following (from: OpenZeppelin Upgrades: Step by Step Tutorial for Truffle).

Box.sol

// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
 
contract Box {
    uint256 private value;
 
    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);
 
    // Stores a new value in the contract
    function store(uint256 newValue) public {
        require(newValue > 0, "Box: store non-zero numbers");
        value = newValue;
        emit ValueChanged(newValue);
    }
 
    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

Box.test.js

// test/Box.test.js
// Load dependencies
const { expect } = require('chai');

const {
    BN,           // Big Number support
    constants,    // Common constants, like the zero address and largest integers
    expectEvent,  // Assertions for emitted events
    expectRevert, // Assertions for transactions that should fail
  } = require('@openzeppelin/test-helpers');
 
// Load compiled artifacts
const Box = artifacts.require('Box');
 
// Start test block
contract('Box', function () {
  beforeEach(async function () {
    // Deploy a new Box contract for each test
    this.box = await Box.new();
  });

  it('non-zero number cannot be stored', async function () {
    // Store an invalid value
    await expectRevert(this.box.store(0), 'Box: store non-zero numbers');
  });
});

Box.proxy.test.js

// test/Box.proxy.test.js
// Load dependencies
const { expect } = require('chai');

const {
    BN,           // Big Number support
    constants,    // Common constants, like the zero address and largest integers
    expectEvent,  // Assertions for emitted events
    expectRevert, // Assertions for transactions that should fail
  } = require('@openzeppelin/test-helpers');

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
 
// Load compiled artifacts
const Box = artifacts.require('Box');
 
// Start test block
contract('Box (proxy)', function () {
  beforeEach(async function () {
    // Deploy a new Box contract for each test
    this.box = await deployProxy(Box, [42], {initializer: 'store'});
  });
 
  // Test case
  it('non-zero number cannot be stored', async function () {
    // Store an invalid value
    await expectRevert(this.box.store(0), 'Box: store non-zero numbers');
  });
});
$ npx truffle test

Compiling your contracts...
===========================
> Compiling ./contracts/Box.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--9290-Ur5S92vRB2B2
> Compiled successfully using:
   - solc: 0.7.3+commit.9bfce1f6.Emscripten.clang



  Contract: Box (proxy)
    ✓ non-zero number cannot be stored (67ms)

  Contract: Box
    ✓ non-zero number cannot be stored (54ms)


  2 passing (3s)