wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.17k stars 283 forks source link

Use deployments.fixture repeatedly #528

Open cody6299 opened 3 months ago

cody6299 commented 3 months ago

Here is my question for simple: I have two deploy script, let's say deployA and deployB, to deploy two contracts, let's say contractA, and contractB. and the deployB.js will use contractA. and a test script, use deployments.fixture respectively to test the deploy scripts.

deployA.js:

module.exports = async function ({ ethers, getNamedAccounts, deployments, getChainId, getUnnamedAccounts }) {
    const { deploy, get, log } = deployments;
    const { deployer } = await getNamedAccounts();
    await deploy('contractA', {
        from: deployer, args: [], log: true, skipIfAlreadyDeployed: true,
    });
};

module.exports.tags = ['deployA', '1'];
module.exports.dependencies = [];

deployB.js

module.exports = async function ({ ethers, getNamedAccounts, deployments, getChainId, getUnnamedAccounts }) {
    const { deploy, get, log } = deployments;
    const { deployer } = await getNamedAccounts();
    let contractA = await deployments.getOrNull('contractA');
     console.log('here we get contractA  ' + (contrtactA != null));
    await deploy('contractB', {
        from: deployer, args: [], log: true, skipIfAlreadyDeployed: true,
    });
};

module.exports.tags = ['deployB, '1'];
module.exports.dependencies = [];

test.js

describe("Test", () => {
    before(async function () {
    });

    beforeEach(async function () {
    });

    it("DeployA", async function() {
        await deployments.fixture(["deployA"]);
    });
    it("DeployB", async function() {
        let contractA = await deployments.getOrNull('contractA');
        console.log('here we get contractA  ' + (contrtactA != null));
        await deployments.fixture(["deployB"]);
    });
});

The question is:

the output of test.js is:

the output of deployB.js is:

I'm just curious, why I can't get contractA in deployB.js. what's internal mechanism.

Of course, this is just a test, deploy work correctly when I deploy it.

wighawag commented 3 months ago

deployments.fixture revert back and execute the deploy script so whatever was available before is reset