question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support resetting accounts after each test

See original GitHub issue

Issue

Good tests should always start from a clean slate, and not depend on the results of previous tests. Currently the test network is reset before each Contract suite, and it seems there is no way to reset programmatically in tests or with some configuration.

Steps to Reproduce

  • Create a test file with a Contract block
  • Add multiple It(...) tests which assume a blank slate and make changes to accounts ether balances (etc)
  • Observe that all but the first test will fail, as the state is not blank anymore

Expected Behavior

A setting or globally available function would allow for resetting of accounts, when the developer needs to start from a blank slate more regularly

Potential solution

I’ve had a read of how truffle works, and played with a solution like the following:

https://github.com/trufflesuite/truffle-core/blob/develop/lib/test.js#L218

	  global.resetState = function() {
		runner.resetState(function() { console.log("State Reset By Test")  })
	  }
          // OR
	  global.resetState = function() {
		runner.initialize(function(err) { 
			err 
			? console.log('Failed Resetting State') 
			: console.log("State Reset By Test")  }
		)
	  }

Unfortunately this doesn’t seem to actually work, but providing a working reset method or helpers class in the global scope would open up a lot of doors for developers.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
cgeweckecommented, Apr 9, 2018

@Nick-Lucas Thanks, this makes sense and is nicely expressed. In practice what people often do is manage their own contract instantiation in a beforeEach block. Example:

contract('SimpleContract', function(accounts){
   let simpleContract;

   beforeEach(async function(){
     simpleContract = await SimpleContract.new();
   });

Are there use cases where the strategy above isn’t adequate?

1reaction
gnidancommented, Jun 28, 2019

Hey @ejwessel, nope, no progress yet on this specifically. Cursèd Stalebot is now disabled so we won’t risk this issue getting lost to history again.

As for position on this: I’d say no, Tim probably feels the same way as he used to, and I agree with him. But! Definitely we could support this as a configuration option.

Not sure about team bandwidth to work on this in the near-term, so I’m going to slap the “help wanted” label on this issue. If anyone wants to work on a PR, I’d love to see the addition of configuration options to customize this revert behavior. Might be worth syncing up before starting work, though. If anyone’s interested, let me know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset user progress in tests and surveys
3. Go to the page of the test you want to reset user progress for. 4. Locate your preferred user and click the...
Read more >
Truffle tests not resetting account states
Surprisingly the state of the accounts (especially the balances) are not reset between test cases. Meaning tests that test balance transfers ...
Read more >
Q&A: Resetting password & Resending email - PractiTest
Resetting a password or Resending email. Q: How can I reset the password of a user or resent mail to a user with...
Read more >
Return iPhone settings to their defaults - Apple Support
Reset All Settings: All settings—including network settings, the keyboard ... This also removes other settings and accounts provided by the profile.
Read more >
Tips to complete account recovery steps - Google Account Help
(You might not see all the questions described here.) If you already tried to recover your account and got a "Google couldn't verify...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found