1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { expect } from '../../setup'
/* External Imports */
import { ethers } from 'hardhat'
import { Contract, BigNumber } from 'ethers'
const bigNumberify = (arr) => {
return arr.map((el: any) => {
if (typeof el === 'number') {
return BigNumber.from(el)
} else if (Array.isArray(el)) {
return bigNumberify(el)
} else {
return el
}
})
}
export const runJsonTest = (contractName: string, json: any): void => {
let contract: Contract
before(async () => {
contract = await (await ethers.getContractFactory(contractName)).deploy()
})
for (const [functionName, functionTests] of Object.entries(json)) {
describe(functionName, () => {
for (const [key, test] of Object.entries(functionTests)) {
it(`should run test: ${key}`, async () => {
if (test.revert) {
await expect(contract.functions[functionName](...test.in)).to.be
.reverted
} else {
expect(
await contract.functions[functionName](...test.in)
).to.deep.equal(bigNumberify(test.out))
}
})
}
})
}
}