Testing zos contracts with a Truffle-like style

Do any of you know of any good tutorials on getting a reference to the proxy contract interface from within a Truffle test suite? In the most minimal, Truffle-like way, not via the zos test helpers like Contracts and TestHelper. Thanks!

If so I can make a PR to add this to the Truffle migrate example, because then it’s a more complete example for someone who’s already bought into the Truffle ecosystem for their contract project but wants to add in zos.

I would want to get a reference to the latest implementation in order to use the Truffle Contract abstraction for calling methods (but then I’d want to change the address for that abstraction to point to the proxy). I should be able to look up the deployed implementation contract by doing .deployed() with the name of the contract so that it uses the Truffle artifact package to find a deployed contract locally matching that Truffle-style ABI.

Next I would want to get a reference to the proxy to find its address, and then I would use the .at() command to use a contract abstraction around the implementation ABI but found at the proxy address.

I would want to get a reference to the proxy instance by using .deployed() with the name of the proxy, again using the Truffle artifact package. It’s hard to do since we don’t have the proxy abi locally in /build/contracts/ in the Truffle-style json format, so first I’d have to know to look for the particular proxy .sol file AdminUpgradeabilityProxy as opposed to the other proxy-related files from the zos repo in the proxy inheritance tree, clone the zos example project, and compile the AdminUpgradeabilityProxy.sol file. Since the zos project itself isn’t using Truffle, the compiled artifact wouldn’t be the Truffle-style artifact (I’m pretty sure of this, anyway). I tried pasting in the .sol file into the legacy project I’m working on adding zos to and compiling it that way, but it’s on a different solc version, so to get the Truffle-style artifact of AdminUpgradeabilityProxy.sol I would have to spin up a new Truffle project with the right solc version and compile the artifact for AdminUpgradeabilityProxy.sol from there.

I think an example project where are few of these things are done would go a long way towards making users not have to grok too much of this and make the steps to set up a Truffle-style test of a zos contract pretty easy to follow, though.

After inspecting some recent PRs to zos, I know TestHelper and Contracts - which are used in the other zos examples - have been moving over to a web3-1.0-style of testing contracts away from Truffle - a perfectly sensible choice. But I think the user base of Truffle is large enough that having an example where you use zos but stick to the Truffle-y way of doing things would help with growing the ZeppelinOS community.

Thanks! Looking forward to hearing people’s thoughts.

1 Like

Nope! zOS takes care of setting the proxy deployment address (and not that of the logic contract) on the truffle artifact. This means that MyContract.deployed() will return a reference to the proxy with MyContract's ABI, not to the logic contract. So half of what you want to do has been already taken care of.

Actually, the zos-lib package ships with a precompiled proxy artifact. So you can get the JSON artifact file from node_modules/lib/zos-lib/build/contracts/....

Sorry to go against your expectations, but yes - zOS artifacts are generated with a format compatible with truffle. Actually, we are still using truffle internally (though this may change in the near future), so they are exactly the same.

Let us know if this helps in setting up a testing suite truffle-style! And I think it'd be a great addition to the truffle-migrate sample project in zOS. Thanks Paul!!

2 Likes

Thanks for the thoughtful response, @spalladino! Good to know on all three counts.

I’ll play around a bit based on this info and hopefully get a PR opened soon with Truffle-style tests for the Truffle migrate sample project.

1 Like

Housekeeping, marking @spalladino reply as the solution.

@pcowgill look forward to seeing the example updated :smile:

@abcoathup It could be worth leaving this as unsolved, since there are still a few more steps needed to produce a reference example - even though @spalladino ’s response was a major, helpful step in that direction. And if there’s already a blog post about it out there, I’m all ears. :grinning:

2 Likes

@pcowgill I have changed back to unsolved. :smile:

2 Likes