0

I am doing smart contract testing with hardat and mocha framework. Suppose I have two following it blocks testing contract A.

it('test1', () => {
  contractA.updateValue(val);
  // some other testing code
});
it('test2', () => {
  contractA.useUpdatedValue();
  // some other testing code
}); 

Here, contracA is defined in the global scope. Is there a way to persist the smart contract state in test1 and then do test2 to use the updated state of the smart contract?

1 Answer 1

2

You need to wrap them in a one describe block and inside put a before block and inside that deploy those contracts.

Here is one of my repos to show how I do it: https://github.com/Kuly14/DJED/blob/main/test/unit/StableCoin.test.ts#L8

I hope this helps.

1
  • Thanks! This is what I was looking for.
    – Tahlil
    Jul 14, 2022 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.