I have some kind of solution, its dirty as F***, but I will post it anyway, maybe some1 will find if helpful...
My Makefile:
.PHONY: node-test local-node-mumbai copy-mumbai-deployments node-mumbai
node-test:
npx hardhat test --network localhost
local-node-mumbai:
screen -dmS local-node npx hardhat node --no-deploy --fork ${MUMBAI_ARCHIVE_NODE_URL}
sleep 15
copy-mumbai-deployments:
rm -Rf ./deployments/localhost
mkdir ./deployments/localhost
cp -r ./deployments/mumbai/* ./deployments/localhost
echo "31337" > ./deployments/localhost/.chainId
node-mumbai: local-node-mumbai copy-mumbai-deployments
My hardhat-deploy
deployment script:
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer, proxyAdminOwner } = await getNamedAccounts();
const DataTypes = await deploy('DataTypes', {
from: deployer,
});
const Errors = await deploy('Errors', {
from: deployer,
});
const MintingLogic = await deploy('MintingLogic', {
from: deployer,
});
const ValidationLogic = await deploy('ValidationLogic', {
from: deployer,
});
await deploy('ContractName', {
from: deployer,
contract: 'ContractName',
log: true,
proxy: {
owner: proxyAdminOwner,
proxyContract: 'OptimizedTransparentProxy',
execute: {
init: {
methodName: 'initialize',
args: [],
},
onUpgrade: {
methodName: 'postUpgrade',
args: [],
},
},
},
libraries: {
Errors: Errors.address,
DataTypes: DataTypes.address,
ValidationLogic: ValidationLogic.address,
MintingLogic: MintingLogic.address,
},
});
};
export default func;
func.tags = ['ContractName'];
Simple tests to prove a change (in this case introducing totalSupply
function):
import { expect } from 'chai';
import { ethers, deployments } from 'hardhat';
import { ContractName } from '../../typechain-types';
describe('ContractName: postUpgrade', function () {
let ContractName: ContractName;
let ContractNameAddress: string;
beforeEach(async () => {
ContractName = await ethers.getContract('ContractName');
ContractNameAddress = ContractName.address;
});
it('pre-updated contract does not have total supply function', async () => {
let message: string = '';
try {
await ContractName.totalSupply();
} catch (e: any) {
message = e.message;
}
expect(message).to.eq('ContractName.totalSupply is not a function');
});
describe('after deployment', () => {
beforeEach(async () => {
await deployments.fixture(['ContractName'], {
keepExistingDeployments: true,
});
ContractName = await ethers.getContract('ContractName');
});
it('does have total supply function', async () => {
const totalSupply = await ContractName.totalSupply();
expect(totalSupply).to.gt(0);
});
it('address of the contract stays the same', async () => {
expect(ContractNameAddress).to.be.eq(
ContractName.address
);
});
});
});
⚠️ This solution doesn't solve all my problems, but its a good start to test against latest deployment
@edit:
localhost accounts needs to be the same in hardhat.config.ts
under networks
:
(…)
localhost: {
accounts: accounts('mumbai'),
},
(…)