From a09d035a45a19c747b6b51fd031f32b4e11ee064 Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Mon, 22 Nov 2021 19:15:32 +0100 Subject: [PATCH] Add basic test scaffolding --- contracts/l2/L2DAIWormholeBridge.sol | 2 +- test/l2/L2DAIWormholeBridge.ts | 50 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/l2/L2DAIWormholeBridge.ts diff --git a/contracts/l2/L2DAIWormholeBridge.sol b/contracts/l2/L2DAIWormholeBridge.sol index 99b405f9..8490c757 100644 --- a/contracts/l2/L2DAIWormholeBridge.sol +++ b/contracts/l2/L2DAIWormholeBridge.sol @@ -28,7 +28,7 @@ interface Mintable { function burn(address usr, uint256 wad) external; } -contract L2DAIWormholeTokenBridge is OVM_CrossDomainEnabled { +contract L2DAIWormholeBridge is OVM_CrossDomainEnabled { using WormholeLib for WormholeGUID; // --- Auth --- diff --git a/test/l2/L2DAIWormholeBridge.ts b/test/l2/L2DAIWormholeBridge.ts new file mode 100644 index 00000000..e740d760 --- /dev/null +++ b/test/l2/L2DAIWormholeBridge.ts @@ -0,0 +1,50 @@ +import { simpleDeploy } from '@makerdao/hardhat-utils' +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address' +import { expect } from 'chai' +import { ethers } from 'hardhat' + +import { Dai__factory, L2DAIWormholeBridge__factory } from '../../typechain' +import { deployMock, deployOptimismContractMock } from '../helpers' + +const INITIAL_TOTAL_L2_SUPPLY = 3000 +const WORMHOLE_AMOUNT = 100 +const SOURCE_DOMAIN_NAME = ethers.utils.formatBytes32String('optimism-a') +const TARGET_DOMAIN_NAME = ethers.utils.formatBytes32String('arbitrum-a') + +describe('L2DAIWormholeBridge', () => { + describe('initiateWormhole()', () => { + it('should burn DAI immediately and mark it for future flush', async () => { + const [_, l2MessengerImpersonator, user1] = await ethers.getSigners() + const { l2Dai, l2DAIWormholeBridge } = await setupTest({ l2MessengerImpersonator, user1 }) + + await l2DAIWormholeBridge + .connect(user1) + .initiateWormhole(TARGET_DOMAIN_NAME, user1.address, WORMHOLE_AMOUNT, user1.address) + + expect(await l2Dai.balanceOf(user1.address)).to.eq(INITIAL_TOTAL_L2_SUPPLY - WORMHOLE_AMOUNT) + expect(await l2DAIWormholeBridge.batchedDaiToFlush(TARGET_DOMAIN_NAME)).to.eq(WORMHOLE_AMOUNT) + }) + }) +}) + +async function setupTest(signers: { l2MessengerImpersonator: SignerWithAddress; user1: SignerWithAddress }) { + const l2CrossDomainMessengerMock = await deployOptimismContractMock( + 'OVM_L2CrossDomainMessenger', + { address: await signers.l2MessengerImpersonator.getAddress() }, // This allows us to use an ethers override {from: Mock__OVM_L2CrossDomainMessenger.address} to mock calls + ) + const l1Dai = await simpleDeploy('Dai', []) + const l2Dai = await simpleDeploy('Dai', []) + const l1DAIWormholeBridgeMock = await deployMock('L1DAIWormholeBridge') + const l2DAIWormholeBridge = await simpleDeploy('L2DAIWormholeBridge', [ + l2CrossDomainMessengerMock.address, + l2Dai.address, + l1Dai.address, + l1DAIWormholeBridgeMock.address, + SOURCE_DOMAIN_NAME, + ]) + + await l2Dai.rely(l2DAIWormholeBridge.address) + await l2Dai.mint(signers.user1.address, INITIAL_TOTAL_L2_SUPPLY) + + return { l2Dai, l1DAIWormholeBridgeMock, l2CrossDomainMessengerMock, l2DAIWormholeBridge, l1Dai } +}