Commit 34f9be41 authored by Mark Tyneway's avatar Mark Tyneway

contracts: fix broken contracts tests

The `contracts` tests included a test that did a deep equality check
against two bignumbers. This check stopped working due to changes
in the bignumber implementations used, two bignumbers of the same number
no longer were considered equal. This commit fixes that problem by
using the same version of ethers as `hardhat` and also stringifying
the results so that strings are compared instead of objects. This
fixes the broken tests.
parent e0b89fcd
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Contract, BigNumber } from 'ethers' import { Contract } from 'ethers'
import { expect } from '../../setup' import { expect } from '../../setup'
const bigNumberify = (arr: any[]) => { const bigNumberify = (arr: any[]) => {
return arr.map((el: any) => { return arr.map((el: any) => {
if (typeof el === 'number') { if (typeof el === 'number') {
return BigNumber.from(el) return ethers.BigNumber.from(el)
} else if (typeof el === 'string' && /^\d+n$/gm.test(el)) { } else if (typeof el === 'string' && /^\d+n$/gm.test(el)) {
return BigNumber.from(el.slice(0, el.length - 1)) return ethers.BigNumber.from(el.slice(0, el.length - 1))
} else if (typeof el === 'string' && el.length > 2 && el.startsWith('0x')) { } else if (typeof el === 'string' && el.length > 2 && el.startsWith('0x')) {
return BigNumber.from(el.toLowerCase()) return ethers.BigNumber.from(el.toLowerCase())
} else if (Array.isArray(el)) { } else if (Array.isArray(el)) {
return bigNumberify(el) return bigNumberify(el)
} else { } else {
...@@ -34,9 +34,10 @@ export const runJsonTest = (contractName: string, json: any): void => { ...@@ -34,9 +34,10 @@ export const runJsonTest = (contractName: string, json: any): void => {
await expect(contract.functions[functionName](...test.in)).to.be await expect(contract.functions[functionName](...test.in)).to.be
.reverted .reverted
} else { } else {
expect( const result = await contract.functions[functionName](...test.in)
bigNumberify(await contract.functions[functionName](...test.in)) expect(JSON.stringify(bigNumberify(result))).to.deep.equal(
).to.deep.equal(bigNumberify(test.out)) JSON.stringify(bigNumberify(test.out))
)
} }
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment