generated from proofoftom/buidler-waffle-typechain-quasar
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #723 from clrfund/feat/maci-v1-bundle-size
Merge fixes from latest MACI
- Loading branch information
Showing
173 changed files
with
6,533 additions
and
6,002 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
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,5 @@ | ||
{ | ||
"extension": ["ts"], | ||
"spec": "src/**/*.spec.ts", | ||
"require": "ts-node/register" | ||
} |
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,47 @@ | ||
import { expect } from 'chai' | ||
import { bnSqrt } from '../index' | ||
import { toBigInt } from 'ethers' | ||
|
||
const UNIT = BigInt(10) ** BigInt(18) | ||
const cases = [ | ||
[0n, 0n], | ||
[1n, 1n], | ||
[4n, 2n], | ||
[100n, 10n], | ||
] | ||
|
||
/** | ||
* Get a random number in range | ||
* @param min minimum number | ||
* @param max maximum number | ||
* @returns random number | ||
*/ | ||
function getRandom(min: number, max: number) { | ||
return Math.floor(Math.random() * (max - min) + min) | ||
} | ||
|
||
describe('bnSqrt', function () { | ||
it('should throw if value less than 0', function () { | ||
expect(bnSqrt.bind(bnSqrt, -1n)).to.throw('Complex numbers not support') | ||
}) | ||
|
||
for (const test of cases) { | ||
const [val, expected] = test | ||
it(`bnSqrt(${val}) === ${expected}`, function () { | ||
expect(bnSqrt(val)).to.eq(expected) | ||
}) | ||
} | ||
|
||
it('Sqrt(8) throws as it took too long to calculate', function () { | ||
expect(bnSqrt.bind(bnSqrt, 8n)).to.throw('Sqrt took too long to calculate') | ||
}) | ||
|
||
it('testing random bigints', function () { | ||
for (let i = 0; i < 100; i++) { | ||
const rand = toBigInt(getRandom(5, 200)) * UNIT | ||
const sqrtVal = bnSqrt(rand) | ||
const val = sqrtVal * sqrtVal | ||
expect(bnSqrt(val)).to.eq(sqrtVal) | ||
} | ||
}) | ||
}) |
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,36 @@ | ||
import { Contract, TransactionResponse } from 'ethers' | ||
|
||
/** | ||
* Get event log argument value | ||
* @param transactionReceipt transaction | ||
* @param contract Contract handle | ||
* @param eventName event name | ||
* @param argumentName argument name | ||
* @returns event argument value | ||
*/ | ||
export async function getEventArg( | ||
transaction: TransactionResponse, | ||
contract: Contract, | ||
eventName: string, | ||
argumentName: string | ||
): Promise<any> { | ||
const transactionReceipt = await transaction.wait() | ||
const contractAddress = await contract.getAddress() | ||
// eslint-disable-next-line | ||
for (const log of transactionReceipt?.logs || []) { | ||
if (log.address !== contractAddress) { | ||
continue | ||
} | ||
const event = contract.interface.parseLog({ | ||
data: log.data, | ||
topics: [...log.topics], | ||
}) | ||
// eslint-disable-next-line | ||
if (event && event.name === eventName) { | ||
return event.args[argumentName] | ||
} | ||
} | ||
throw new Error( | ||
`Event ${eventName} from contract ${contractAddress} not found in transaction ${transaction.hash}` | ||
) | ||
} |
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
Oops, something went wrong.