Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixture Error Bug #6456

Open
petdomaa100 opened this issue Mar 8, 2025 · 2 comments
Open

Fixture Error Bug #6456

petdomaa100 opened this issue Mar 8, 2025 · 2 comments
Assignees

Comments

@petdomaa100
Copy link

petdomaa100 commented Mar 8, 2025

Version of Hardhat

2.22.5

What happened?

Hey, thanks for looking over my issue.

I have a few contracts in my protocol. Two of them are token contracts that have a shared interface and some unique functions. The shared functions have different implementations but the logic for testing them is the same. Because of this, I set up tests that can be ran for both tokens.

Unfortunately, I ran into an odd FixtureSnapshotError even though I am not using any beforeEach or nested fixtures.

Minimal reproduction steps

https://github.com/petdomaa100/hardhat-fixture-error-minimal-reproducible-example

Search terms

fixture, FixtureSnapshotError

@galargh
Copy link
Member

galargh commented Mar 10, 2025

That's because the deployed contracts differ from the ones returned by the fixture set up function. What you could do instead is to move the call to the loadFixture to your helper functions.

So your baseTokenFixture would become something like:

async function loadBaseTokenFixture(whichOne: 'ONE' | 'TWO') {
	const fixture = await loadFixture(deployFixture); // Note the call to load fixture here
...

And then your shared test could just await that instead:

...
	it('Test 1', async () => {
		const {
			contracts: { Token }
		} = await loadBaseTokenFixture(whichOne);

		// [...] Some test
	});
...

@petdomaa100
Copy link
Author

Hey, thanks for your suggestion it worked perfectly. :)

Could you give a quick explanation of why the error is thrown if the fixture returns different values?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants