Testing upgrade with non-authorized address

with UUPS proxies we can restrict upgrading to owners or users with a particular role using access controls

function _authorizeUpgrade(address) internal override onlyAdmin {}

Looking at the docs

I'm trying to write a test for upgrading from a non-authorized address (and capture the failure of course)? Not immediately clear how to do this...


You can use different test accounts to set up your roles (see Access Control docs) and then run the upgrade and catch the error.

To get different test accounts:
If using Hardhat, see https://hardhat.org/tutorial/testing-contracts
If using Truffle, see https://trufflesuite.com/docs/truffle/testing/writing-tests-in-javascript/

To expect an error in tests, see these for example:
Hardhat - https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/a3fcaa440f292ecbfe34fa3185b3d317e551e3db/packages/plugin-hardhat/test/uups-upgrade-storage.js#L13
Truffle - https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/a3fcaa440f292ecbfe34fa3185b3d317e551e3db/packages/plugin-truffle/test/test/uups-upgrade-storage.js#L10

@ericglau thank you for the tips!