Skip to content

Commit

Permalink
chore: update test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
dutterbutter committed Dec 12, 2023
1 parent 1e4ba0a commit 4600fc9
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 78 deletions.
5 changes: 4 additions & 1 deletion contracts/deploy/allowListPaymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Provider, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HttpNetworkUserConfig } from "hardhat/types";

// load env file
import dotenv from "dotenv";
Expand All @@ -16,7 +17,9 @@ if (!PRIVATE_KEY)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the AllowlistPaymaster contract...`);
const provider = new Provider("https://sepolia.era.zksync.dev");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);

// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
Expand Down
1 change: 0 additions & 1 deletion contracts/deploy/erc20.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ethers from "ethers";

import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Wallet } from "zksync-web3";
Expand Down
12 changes: 8 additions & 4 deletions contracts/deploy/erc20fixedPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as ethers from "ethers";

import { Provider, Wallet } from "zksync-web3";

import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";

// load env file
import dotenv from "dotenv";

Expand All @@ -22,7 +24,9 @@ if (!TOKEN_ADDRESS)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the ERC20fixedPaymaster contract...`);
const provider = new Provider("https://sepolia.era.zksync.dev/");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);
// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
const wallet = new Wallet(PRIVATE_KEY);
Expand Down
4 changes: 1 addition & 3 deletions contracts/deploy/erc721.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Provider, Wallet } from "zksync-web3";

import { Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HardhatRuntimeEnvironment } from "hardhat/types";
// load env file
Expand All @@ -20,7 +19,6 @@ if (!RECIPIENT_ADDRESS)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the MyNFT contract...`);
const provider = new Provider("https://sepolia.era.zksync.dev/");

// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
Expand Down
11 changes: 7 additions & 4 deletions contracts/deploy/erc721gatedPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as ethers from "ethers";

import { Provider, Wallet } from "zksync-web3";

import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";
// load env file
import dotenv from "dotenv";

Expand All @@ -22,7 +23,9 @@ if (!NFT_COLLECTION_ADDRESS)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the ERC721gatedPaymaster contract...`);
const provider = new Provider("https://sepolia.era.zksync.dev/");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);

// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
Expand Down
12 changes: 7 additions & 5 deletions contracts/deploy/gaslessPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as ethers from "ethers";

import { Provider, Wallet } from "zksync-web3";

import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";
// load env file
import dotenv from "dotenv";

Expand All @@ -17,8 +18,9 @@ if (!PRIVATE_KEY)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the GaslessPaymaster contract...`);
const provider = new Provider("https://sepolia.era.zksync.dev/");

// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);
// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
const wallet = new Wallet(PRIVATE_KEY);
Expand Down
2 changes: 1 addition & 1 deletion contracts/deploy/greeter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Wallet, utils } from "zksync-web3";
import { Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
Expand Down
11 changes: 7 additions & 4 deletions contracts/deploy/timeBasedPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as ethers from "ethers";

import { Provider, Wallet } from "zksync-web3";

import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";
// load env file
import dotenv from "dotenv";

Expand All @@ -17,7 +18,9 @@ if (!PRIVATE_KEY)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the TimeBasedPaymaster contract...`);
const provider = new Provider("https://sepolia.era.zksync.dev/");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);

const wallet = new Wallet(PRIVATE_KEY);
const deployer = new Deployer(hre, wallet);
Expand Down
50 changes: 18 additions & 32 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,6 @@ import "@nomiclabs/hardhat-etherscan";

import { HardhatUserConfig } from "hardhat/config";

const getNetworkConfig = () => {
const env = process.env.DEPLOY_ENV || "local";
switch (env) {
case "local":
return {
url: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
zksync: true,
};
case "ci":
return {
url: "http://127.0.0.1:8011",
ethNetwork: "sepolia",
zksync: true,
};
case "testnet":
return {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
// Verification endpoint for Sepolia
verifyURL:
"https://explorer.sepolia.era.zksync.dev/contract_verification",
};
default:
throw new Error(`Unsupported DEPLOY_ENV: ${env}`);
}
};

const networkConfig = getNetworkConfig();

const config: HardhatUserConfig = {
zksolc: {
version: "latest",
Expand All @@ -46,7 +15,24 @@ const config: HardhatUserConfig = {
hardhat: {
zksync: false,
},
zkSyncTestnet: networkConfig,
zkSyncInMemory: {
url: "http://127.0.0.1:8011",
ethNetwork: "sepolia",
zksync: true,
},
zkSyncLocal: {
url: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
zksync: true,
},
zkSyncTestnet: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
// Verification endpoint for Sepolia
verifyURL:
"https://explorer.sepolia.era.zksync.dev/contract_verification",
},
},
solidity: {
version: "0.8.17",
Expand Down
4 changes: 2 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"zksync-web3": "^0.14.3"
},
"scripts": {
"test": "NODE_ENV=local hardhat test --network zkSyncTestnet",
"ci:tests": "DEPLOY_ENV=ci hardhat test --network zkSyncTestnet --show-stack-traces",
"test": "hardhat test --network zkSyncInMemory",
"ci:tests": "hardhat test --network zkSyncInMemory --show-stack-traces",
"deploy": "hardhat deploy-zksync",
"greeter": "hardhat deploy-zksync --script greeter.ts",
"gasless": "hardhat deploy-zksync --script gaslessPaymaster.ts",
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/allowlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("AllowlistPaymaster", function () {
let greeter: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/erc20fixed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("ERC20fixedPaymaster", function () {
let token: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/erc721gated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("ERC721gatedPaymaster", function () {
let erc721: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/gasless.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("GaslessPaymaster", function () {
let greeter: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
33 changes: 16 additions & 17 deletions contracts/test/timeBased.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("TimeBasedPaymaster", function () {
let greeter: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
userWallet = Wallet.createRandom();
console.log(`User wallet's address: ${userWallet.address}`);
Expand Down Expand Up @@ -55,6 +55,21 @@ describe("TimeBasedPaymaster", function () {
await setGreetingTx.wait();
}

it("should fail due to Paymaster validation error outside the time window", async function () {
// Arrange
let errorOccurred = false;

// Act
try {
await executeGreetingTransaction(wallet);
} catch (error) {
errorOccurred = true;
expect(error.message).to.include("Paymaster validation error");
}
// Assert
expect(errorOccurred).to.be.true;
});

it("should cost the user no gas during the time window", async function () {
// Arrange
const currentDate = new Date();
Expand All @@ -75,20 +90,4 @@ describe("TimeBasedPaymaster", function () {
expect(newBalance.toString()).to.equal(initialBalance.toString());
expect(await greeter.greet()).to.equal("Hola, mundo!");
});

it("should fail due to Paymaster validation error outside the time window", async function () {
// Arrange
let errorOccurred = false;

// Act
try {
await executeGreetingTransaction(wallet);
} catch (error) {
errorOccurred = true;
expect(error.message).to.include("Paymaster validation error");
}

// Assert
expect(errorOccurred).to.be.true;
});
});

0 comments on commit 4600fc9

Please sign in to comment.