Skip to content

Commit

Permalink
🚧 Use fixtures when deploying test contracts (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Jan 10, 2024
1 parent 949a5fd commit b894116
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 30 deletions.
26 changes: 26 additions & 0 deletions tests/devtools-evm-hardhat-test/deploy/001_Thrower.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { type DeployFunction } from 'hardhat-deploy/types'
import assert from 'assert'

/**
* This deploy function will deploy and configure the Thrower contract
*
* @param env `HardhatRuntimeEnvironment`
*/
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }) => {
const [deployer] = await getUnnamedAccounts()
assert(deployer, 'Missing deployer')

await deployments.delete('Thrower')
const throwerDeployment = await deployments.deploy('Thrower', {
from: deployer,
})

console.table({
Network: `${network.name}`,
Thrower: throwerDeployment.address,
})
}

deploy.tags = ['Thrower']

export default deploy
36 changes: 36 additions & 0 deletions tests/devtools-evm-hardhat-test/deploy/002_TestProxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { type DeployFunction } from 'hardhat-deploy/types'
import assert from 'assert'

/**
* This deploy function will deploy and configure the TestProxy contract
*
* @param env `HardhatRuntimeEnvironment`
*/
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }) => {
const [deployer] = await getUnnamedAccounts()
assert(deployer, 'Missing deployer')

await deployments.delete('TestProxy')
const testProxyDeployment = await deployments.deploy('TestProxy', {
from: deployer,
proxy: {
owner: deployer,
proxyContract: 'OptimizedTransparentProxy',
execute: {
init: {
methodName: 'initialize',
args: [],
},
},
},
})

console.table({
Network: `${network.name}`,
TestProxy: testProxyDeployment.address,
})
}

deploy.tags = ['TestProxy']

export default deploy
18 changes: 7 additions & 11 deletions tests/devtools-evm-hardhat-test/test/errors/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import 'hardhat'
import { BigNumber } from '@ethersproject/bignumber/lib/bignumber'
import { Contract } from '@ethersproject/contracts'
import { CustomError, UnknownError } from '@layerzerolabs/devtools-evm'
import { createErrorParser, createSignerFactory } from '@layerzerolabs/devtools-evm-hardhat'
import { createConnectedContractFactory, createErrorParser } from '@layerzerolabs/devtools-evm-hardhat'
import { OmniError } from '@layerzerolabs/devtools'
import { pointArbitrary } from '@layerzerolabs/test-devtools'
import { getHreByNetworkName, getEidForNetworkName } from '@layerzerolabs/devtools-evm-hardhat'
import assert from 'assert'

describe('errors/parser', () => {
describe('createErrorParser', () => {
Expand Down Expand Up @@ -35,18 +34,15 @@ describe('errors/parser', () => {
// Get the environment
const env = await getHreByNetworkName('britney')
const eid = getEidForNetworkName('britney')
const { signer } = await createSignerFactory()(eid)

// Get the deployer account
const [deployer] = await env.getUnnamedAccounts()
assert(deployer, 'Missing deployer account')
// Deploy a fixture
await env.deployments.fixture(['Thrower'])

// Deploy the Thrower contract
const deployment = await env.deployments.deploy('Thrower', {
from: deployer,
})
// And get the contract
const contractFactory = createConnectedContractFactory()
const omniContract = await contractFactory({ contractName: 'Thrower', eid })

contract = new Contract(deployment.address, deployment.abi, signer)
contract = omniContract.contract
})

it('should parse a custom an error with no arguments coming from the contract itself', async () => {
Expand Down
21 changes: 2 additions & 19 deletions tests/devtools-evm-hardhat-test/test/omnigraph/coordinates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,15 @@ import {
getEidForNetworkName,
getHreByNetworkName,
} from '@layerzerolabs/devtools-evm-hardhat'
import assert from 'assert'

describe('omnigraph/coordinates', () => {
describe('createContractFactory', () => {
it('should have all contract methods for proxy deployments', async () => {
const env = await getHreByNetworkName('britney')
const eid = getEidForNetworkName('britney')

// Get the deployer account
const [deployer] = await env.getUnnamedAccounts()
assert(deployer, 'Missing deployer account')

// Deploy the TestProxy contract
await env.deployments.deploy('TestProxy', {
from: deployer,
proxy: {
owner: deployer,
proxyContract: 'OptimizedTransparentProxy',
execute: {
init: {
methodName: 'initialize',
args: [],
},
},
},
})
// Deploy a fixture
await env.deployments.fixture(['TestProxy'])

// Now we create a contract factory and observe that the resulting contract has all the contract methods
const contractFactory = createContractFactory()
Expand Down

0 comments on commit b894116

Please sign in to comment.