Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Fix test code
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaki committed Nov 4, 2021
1 parent 3357fe2 commit b7f42f4
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 1,588 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ library BLS {
uint256 private constant MASK24 = 0xffffffffffffffffffffffffffffffffffffffffffffffff;

// estimator address
address private constant COST_ESTIMATOR_ADDRESS = 0x1068C5206f2a61473ec5d2aE68FF7358AF3a0D75;
address private constant COST_ESTIMATOR_ADDRESS = 0x28D80eadB668952bC7a39a56c807b189c1F30b74;

function verifySingle(
uint256[2] memory signature,
Expand Down
1 change: 0 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^2.1.3",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@openzeppelin/test-helpers": "^0.5.15",
"@typechain/ethers-v5": "^7.0.1",
"@typechain/hardhat": "^2.3.0",
"@types/chai": "^4.2.21",
Expand Down
28 changes: 28 additions & 0 deletions contracts/shared/helpers/expectRevert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from "chai";


export default async function expectRevert(
throwingPromise: Promise<any>,
expectedErrorMsg?: string
) {
let failedToThrow = false;
try {
await throwingPromise;
failedToThrow = true;
}
catch(e) {
if (expectedErrorMsg != undefined) {
let errMsg = (e as Error).message;
expect(errMsg).to.contain(expectedErrorMsg);
}
}
finally {
if (failedToThrow) {
let failMsg = `No error received`;
if (expectedErrorMsg != undefined) {
failMsg += `, expected: ${expectedErrorMsg}`
};
expect.fail(failMsg);
}
}
}
23 changes: 11 additions & 12 deletions contracts/test/deploy-test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import * as dotenv from "dotenv";

import { expect, assert } from "chai";
import { expectEvent, expectRevert } from "@openzeppelin/test-helpers";
import expectRevert from "../shared/helpers/expectRevert";

import { BigNumber } from "@ethersproject/bignumber";
import { ethers } from "hardhat";
import deployerContract, { defaultDeployerAddress, defaultDeployerWallet } from "../shared/helpers/deployDeployer";
import { Create2Deployer, Create2Deployer__factory } from "../typechain";
import { ContractFactory } from "@ethersproject/contracts";

dotenv.config();

describe.only('Deployer', async function () {
describe('Deployer', async function () {
let deployerSigner;
let eoaAddress;
let Create2Deployer: ContractFactory;
Expand All @@ -25,7 +22,7 @@ describe.only('Deployer', async function () {
// fund deployer wallet address
let fundedSigner = (await ethers.getSigners())[0];
await (await fundedSigner.sendTransaction({
to: defaultDeployerWallet().address,
to: defaultDeployerAddress(),
value: ethers.utils.parseEther("1")
})).wait();

Expand Down Expand Up @@ -75,13 +72,15 @@ describe.only('Deployer', async function () {
it('should fail deployment with same salt', async function () {
let testSalt = BigNumber.from(1);
// two identical deployment promises, ie, same create2 address
let deployerPromise1, deployerPromise2 = create2Deployer.deploy(
await create2Deployer.deploy(
testSalt,
Create2Deployer.bytecode
);

await deployerPromise1;

expectRevert.unspecified(deployerPromise2);
})
await expectRevert(
create2Deployer.deploy(
testSalt,
Create2Deployer.bytecode
)
);
});
});
2 changes: 0 additions & 2 deletions contracts/test/tokenPayment-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { ethers, network } from "hardhat";

import { expect, assert, should } from "chai";

// import { expectEvent, expectRevert } from "@openzeppelin/test-helpers";

import Fixture from "../shared/helpers/Fixture";
import { FullTxData, TxData } from "../shared/helpers/Fixture";
import TokenHelper from "../shared/helpers/TokenHelper";
Expand Down
17 changes: 5 additions & 12 deletions contracts/test/walletAction-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, assert } from "chai";

import { expectEvent, expectRevert } from "@openzeppelin/test-helpers";
import expectRevert from "../shared/helpers/expectRevert";

import { ethers, network } from "hardhat";
const utils = ethers.utils;
Expand Down Expand Up @@ -28,19 +27,13 @@ describe('WalletActions', async function () {
this.beforeAll(async function () {
// deploy the deployer contract for the transient hardhat network
if (network.name === "hardhat") {
let address = defaultDeployerAddress();
console.log("eaoAddress:", address);

// fund deployer wallet address
let fundedSigner = (await ethers.getSigners())[0];
await (await fundedSigner.sendTransaction({
to: address,
to: defaultDeployerAddress(),
value: utils.parseEther("1")
})).wait();

let create2Deployer = await deployerContract();
console.log("create2Deployer:", create2Deployer.address);

// deploy the precompile contract (via deployer)
console.log("PCE:", await deployAndRunPrecompileCostEstimator());
}
Expand Down Expand Up @@ -76,7 +69,7 @@ describe('WalletActions', async function () {
.to.equal(keyPart)));

// Check revert when adding same wallet twice
// await expectRevert.unspecified(fx.createBLSWallet(blsSigner));
// await expectRevert(fx.createBLSWallet(blsSigner));

});

Expand Down Expand Up @@ -187,7 +180,7 @@ describe('WalletActions', async function () {
);

txData.ethValue = parseEther("1");
await expectRevert.unspecified(
await expectRevert(
fx.verificationGateway.callStatic.verifySignatures(
[blsSigner.pubkey],
signature,
Expand Down Expand Up @@ -351,7 +344,7 @@ describe('WalletActions', async function () {
expect(rewardIncrease).to.equal(rewardAmountToSend);

// exception when required more than rewarded
await expectRevert.unspecified(fx.blsExpander.callStatic.blsCallMultiCheckRewardIncrease(
await expectRevert(fx.blsExpander.callStatic.blsCallMultiCheckRewardIncrease(
rewardRecipient,
rewardTokenAddress,
rewardAmountToSend.add(1), //require more than amount sent
Expand Down
Loading

0 comments on commit b7f42f4

Please sign in to comment.