generated from NomicFoundation/hardhat-ts-plugin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add import cloned contract tests and fix bugs
- Loading branch information
Showing
9 changed files
with
185 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { cloneContract, createTestFixture, TIMEOUT } from './helpers'; | ||
Check failure on line 1 in test/import.e2e.test.ts GitHub Actions / build (16.x)
Check failure on line 1 in test/import.e2e.test.ts GitHub Actions / build (18.x)
|
||
import child_process from 'node:child_process'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
describe('Import cloned contracts as dependency', () => { | ||
it('import Kyber Meta Aggregation Rounter V2', async () => { | ||
const tmp = await createTestFixture(); | ||
|
||
await cloneContract( | ||
tmp, | ||
'0x6131B5fae19EA4f9D964eAc0408E4408b66337b5', | ||
'kyber', | ||
); | ||
|
||
const contract = ` | ||
import 'kyber/contracts/MetaAggregationRouterV2.sol'; | ||
contract C { MetaAggregationRouterV2 router; } | ||
`; | ||
const file = path.join(tmp, 'contracts', 'contract.sol'); | ||
await fs.promises.mkdir(path.dirname(file), { recursive: true }); | ||
await fs.promises.writeFile(file, contract); | ||
|
||
child_process.execSync(`pnpm hardhat compile --force`, { | ||
encoding: 'utf-8', | ||
stdio: ['inherit', 'ignore', 'ignore'], | ||
cwd: tmp, | ||
}); | ||
expect( | ||
fs.existsSync(path.join(tmp, 'artifacts', 'contracts', 'contract.sol')), | ||
).toBeTruthy(); | ||
|
||
await fs.promises.rm(tmp, { recursive: true, force: true }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { cloneContract, createTestFixture, TIMEOUT } from './helpers'; | ||
import child_process from 'node:child_process'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
describe('hardhat-clone clones multiple contracts', () => { | ||
it.concurrent.each([ | ||
[ | ||
[ | ||
['0xdAC17F958D2ee523a2206206994597C13D831ec7', 'Tether'], | ||
['0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'USDC Proxy'], | ||
], | ||
], | ||
[ | ||
[ | ||
['0x43506849D7C04F9138D1A2050bbF3A0c054402dd', 'USDC'], | ||
['0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 'WETH'], | ||
['0xDb53f47aC61FE54F456A4eb3E09832D08Dd7BEec', 'withlibraries'], | ||
], | ||
], | ||
])( | ||
`should clone %j`, | ||
async ( | ||
contracts: string[][], | ||
opts?: { | ||
etherscanApiKey?: string; | ||
debug?: boolean; // whether to print logs and preserve the temp project for debugging | ||
}, | ||
) => { | ||
const tmp = await createTestFixture(opts); | ||
|
||
for (const [contractAddress, contractName] of contracts) { | ||
await cloneContract(tmp, contractAddress, contractName, opts); | ||
} | ||
|
||
const output = child_process.execSync( | ||
`pnpm hardhat compile --force ${opts?.debug ? '' : '--quiet'}`, | ||
{ | ||
encoding: 'utf-8', | ||
stdio: [ | ||
'inherit', | ||
opts?.debug ? 'inherit' : 'ignore', | ||
opts?.debug ? 'inherit' : 'ignore', | ||
], | ||
cwd: tmp, | ||
}, | ||
); | ||
if (opts?.debug) console.log('Compilation output:\n', output); | ||
for (const [_, contractName] of contracts) { | ||
Check failure on line 49 in test/multiple.e2e.test.ts GitHub Actions / build (16.x)
Check failure on line 49 in test/multiple.e2e.test.ts GitHub Actions / build (18.x)
|
||
expect( | ||
fs.existsSync(path.join(tmp, 'artifacts', contractName)), | ||
).toBeTruthy(); | ||
} | ||
|
||
if (!opts?.debug) | ||
await fs.promises.rm(tmp, { recursive: true, force: true }); | ||
}, | ||
TIMEOUT, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { cloneContract, createTestFixture, TIMEOUT } from './helpers'; | ||
import fs from 'node:fs'; | ||
|
||
describe('hardhat-clone clones unverified contracts', () => { | ||
it.concurrent.each([ | ||
['0x123', 'Invalid address'], | ||
['0x4675C7e5BaAFBFFbca748158bEcBA61ef3b0a263', 'NotVerified'], | ||
['0xFf23e40ac05D30Df46c250Dd4d784f6496A79CE9', 'Vyper contracts'], | ||
])( | ||
`should clone %s (%s)`, | ||
async ( | ||
contractAddress: string, | ||
errorMsg: string, | ||
opts?: { | ||
etherscanApiKey?: string; | ||
debug?: boolean; // whether to print logs and preserve the temp project for debugging | ||
}, | ||
) => { | ||
const tmp = await createTestFixture(opts); | ||
const task = cloneContract(tmp, contractAddress, 'unverified', opts); | ||
await expect(task).rejects.toThrow(errorMsg); | ||
|
||
if (!opts?.debug) | ||
await fs.promises.rm(tmp, { recursive: true, force: true }); | ||
}, | ||
TIMEOUT, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters