tasitlabs / tasit-sdk

A JavaScript / TypeScript SDK for making native mobile Ethereum dapps using React Native
https://tasit.dev
MIT License
97 stars 10 forks source link

Improve isolation between test suites #221

Open marcelomorgado opened 5 years ago

marcelomorgado commented 5 years ago

Our main test script runs npm test scripts of all packages against the same instance of ganache-cli (with contracts deployed after start). If some test suite doesn't manage snapshot correctly, another test suite can fail since the blockchain state isn't the expected one. Another problem that can occur is related to the accounts that are shared between test suites: Nonce issues can occur if some test case doesn't handle that correctly. An idea that could help to solve this issue is to start a ganache instance for each test suite, but it'll slow the test script a lot. @pcowgill any idea?

marcelomorgado commented 5 years ago

Another idea: Try to force snapshot / nonce management thru mochaSetup.js using global hooks at all packages.

pcowgill commented 5 years ago

@marcelomorgado This is a good idea.

Haha I was just typing what I think is the same idea you just posted!

"Are there any commands to restore ganache to its default starting state at the start of any test suite? That might be faster than starting a new ganache instance"

marcelomorgado commented 5 years ago

A fix to be made: Ensure that blockchain will be reverted to the correct snapshot beforeEach test case. Now, when an exception occurs inside a hook and before revertFromSnapshot it's breaking the test suite and demands ganache-cli restarting.

Refs: https://github.com/tasitlabs/TasitSDK/issues/149#issuecomment-457336552

pcowgill commented 5 years ago

@marcelomorgado What's that quote from?

marcelomorgado commented 5 years ago

Oh, sorry I've just edited the comment above with the reference.