AutoTask for CI Testing

:computer: Environment

Autotask, I would like to integrate Truffle or Hardhat. maybe I need to do a truffle teams style api call unless there is native support for ci testing?


I am trying to make an admin feature in Defender where, before a proposal to upgrade a contract, the contract has to pass a testing autotask to prove the logic of functions holds. Is there an example of this being done? Is this too much for autotask to handle?

:1234: Code to reproduce

N/A yet

1 Like

Hey @jp4g! That’s a great use case. To be honest, it’s not something we had pictured for autotasks. The way I see it, you’d need to trigger an Autotask whenever you push your code, have it checkout the contract, run tests, and then report back. You could use Autotask webhooks for triggering the Autotask, and we can add new libraries to the Autotask environment that you may need for running the tests.

However, this would be effectively trying to build a CI manually out of an Autotask. I’m thinking it may be best to rely on a CI for doing this (github actions, circle, travis, etc), and have the CI create the proposal for upgrade in Defender.

We recently opened up an API for Defender Admin which you can use for creating upgrade proposals. You can run your tests on the CI, deploy the new logic contract if they pass, and then use the defender-admin-client package for creating an upgrade within Defender:

const newImplementation = '0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9';
const contract = { network: 'rinkeby', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' }
await client.proposeUpgrade({ newImplementation }, contract);

And if you’re using Hardhat, you can handle the validation and deployment of the implementation contract and the upgrade proposal in a single call using defender.proposeUpgrade:

const factory  = await ethers.getContractFactory('MyContractV2');
const newProposal = await defender.proposeUpgrade(address, factory);

You can customize the text of the proposal in Defender Admin from the API as well, so you can even include a link to the CI run so signers can go to it to see the tests passing.

Do you think something like this work for you?