We have been working away writing our test suite for our smart contracts which are using ZeppelinOS for upgradeability.
We have mostly been following a lot of the patterns that are shown by example in the Centre Token repo:
While we now have more than 100 tests correctly running I am still having some issues getting a few of the test cases working due to the difference between ZOS and the previous method of testing using the older Zeppelin framework.
Specifically I have the following questions I hope someone can help with. Specifically I am trying to understand how to convert the line in bold to something that is compatible with the current version of ZeppelinOS:
How can I capture the ‘Upgraded’ event in a test? The centre repo has the following code:
it(‘et008 should check Upgraded event’, async function () {
var upgradedToken = await UpgradedFiatTokenNewFields.new();
const initializeData = encodeCall(‘initV2’, [‘bool’, ‘address’, ‘uint256’], [true, pauserAccount, 12]); let upgrade = await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount });
checkUpgradeEvent(upgrade, upgradedToken.address);
});
How do I capture the AdminChanged event? Again, centre code:
it(‘et009 should check AdminChanged event’, async function () { let adminChanged = await proxy.changeAdmin(arbitraryAccount, {from: proxyOwnerAccount});
checkAdminChangedEvent(adminChanged, proxyOwnerAccount, arbitraryAccount);
});
@abcoathup - not quite got it working… so currently all my test files have been using the TestHelper to run contract functions and check events as below::
So the above approach is fine when testing and checking for events on my own contracts but I think I cannot use the TestHelper to help me with checking events at the Proxy level? ie. ‘upgrading’, ‘changing proxy admin’, etc?
However, when I try a similar pattern for running the ‘changeAdmin’ function on the Proxy then I get a transaction revert but without any error message? The code I have is:
Regards testing changing the admin, my suggestion is to have a look at the tests to see how it works there. I was searching for changeAdmin in the repository.
TestHelper (zos-lib Project under the covers) returns the object already setup and doesn't keep the transaction that created it. So it doesn't look to be possible to use TestHelper to test for these type of events unfortunately.
Thanks @abcoathup. So I guess I am heading in the right path by using a reference to the AdminUpgradeabilityProxy directly to test the functions and events at the Proxy level (eg, Upgraded event or changeAdmin function).
I’ll try and come back to this today as I left the problem alone for a couple of days to focus on some other tasks and also hope that my background brain processes might figure something out