How to test contracts that require a new colony without creating a persistent colony?


Hi. I am writing a contract that is layered on top of and depends on Colony.

In writing my tests, what I would like to do is to create a new colony only for the duration of the test. So once the test is complete, the colony would cease to exist. I am using Truffle for my testing.

Right now, every time I run my tests I end up creating a colony that persists and clutters up the “real” colonies. I haven’t figured out how to avoid this yet.

Thanks for any suggestions how to handle this. Sample code is appreciated.



Hi Brendan!

It is not possible to create a new colony only for the duration of the test. Once a colony is written to the network, there is no way to remove it from the network.

What you could do is spin up a separate test network using Ganache that you use when running tests, so that it does not interfere with the network you are currently using.

If you are using ganache-cli and already running a test network, you would use the -p or --port flag to specify a separate port to run a second test network. If you are following the examples from the docs or the colonyStarter, you would then need to make sure that when you are running tests, you are connecting to the intended test network when instantiating the provider:

const provider = new providers.JsonRpcProvider('http://localhost:8545/');

In summary, it is not possible to create a new colony only for the duration of the test, but it is possible to use a separate test network for running tests. I hope this answers your question!


Thanks, Ryan. That could work, to create a separate Ganache chain I use for testing only.

PS - I am getting back into the dApp I mentioned to you and hope to have an alpha to share with you before the end of the year.



No problem! Excited to see what you’ve been working on!

Feel free to post your project in #projects if you are looking for ideas, collaborators, or you just want to share your project idea and any updates you make.