How to interact with proxy contract, after deploying a TransparentProxy?

I'm writing tests for my proxy contract using OpenZeppelin's truffle-upgrades, TransparentProxy.

I wrote this test:

 it("can transfer ownership", async () => {
      const admin = await proxy.admin();
      const newAdmin = await proxy.changeAdmin(accounts[1]);

      assert.ok(newAdmin !== admin)
    });

And this is the beforeEach hook:

 beforeEach(async () => {
proxy = await deployProxy(
  Blackjack,
  [
    1000,
    "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311",
    web3.utils.toWei("0.1", "ether"),
    "0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B",
    "0x01BE23585060835E02B77ef475b0Cc51aA1e0709",
  ],
  { kind: "transparent" }
);

});

But I kept getting an error saying the admin function doesn't exist. It made me realize that even calls to admin functions are delegated directly to the implementation contract. So, how can I access the admin functions on a proxy contract? I'm assuming I need some way to get the ProxyAdmin and Proxy addresses, but I couldn't find a way to do that either.

Any help is much appreciated - thank you in advance!

You can use the admin module from the Truffle Upgrades plugin, then use getInstance().getProxyAdmin(...) and changeProxyAdmin(...). See https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/master/packages/plugin-truffle/test/test/transparent-admin-happy-path.js for examples.

1 Like