Skip to content

Commit e69f739

Browse files
authoredMay 16, 2022
🤡 Optimism integration (#728)
1 parent 79a421f commit e69f739

29 files changed

+338
-33
lines changed
 

‎.changeset/dirty-walls-repeat.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ethereum-waffle/chai": patch
3+
"@ethereum-waffle/optimism": patch
4+
---
5+
6+
Support testing on optimism
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Optimism testing
2+
3+
on:
4+
push:
5+
branches:
6+
- changeset-release/*
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
# test against a known version and a current master
13+
OPTIMISM_GIT_HEAD: ["b0a54509a6f99194221f5ade230ceae7892b3393", "master"]
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- uses: pnpm/action-setup@v2
19+
with:
20+
version: 6.32.4
21+
- name: Setup Node.js 16.x
22+
uses: actions/setup-node@v3.0.0
23+
with:
24+
node-version: 16.x
25+
- name: Build project
26+
run: |
27+
pnpm install
28+
pnpm build
29+
- name: Setup optimism node
30+
run: |
31+
cd ..
32+
git clone https://github.com/ethereum-optimism/optimism.git
33+
cd optimism/ops
34+
git checkout ${{ matrix.OPTIMISM_GIT_HEAD }}
35+
docker-compose pull
36+
docker-compose up &
37+
scripts/wait-for-sequencer.sh && echo "System is ready to accept transactions"
38+
- name: Test optimism
39+
run: |
40+
cd waffle-optimism
41+
pnpm run test:optimism

‎pnpm-lock.yaml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎waffle-chai/src/matchers/changeEtherBalance.ts

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export async function getBalanceChange(
5959
const gasPrice = txResponse.gasPrice ?? txReceipt.effectiveGasPrice;
6060
const gasUsed = txReceipt.gasUsed;
6161
const txFee = gasPrice.mul(gasUsed);
62+
const provider = account.provider as any;
63+
if (typeof provider.getL1Fee === 'function') {
64+
const l1Fee = await provider.getL1Fee(txReceipt.transactionHash);
65+
return balanceAfter.add(txFee).add(l1Fee).sub(balanceBefore);
66+
}
6267

6368
return balanceAfter.add(txFee).sub(balanceBefore);
6469
} else {

‎waffle-chai/src/matchers/changeEtherBalances.ts

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ async function getTxFees(
7070
const gasPrice = txResponse.gasPrice ?? txReceipt.effectiveGasPrice;
7171
const gasUsed = txReceipt.gasUsed;
7272
const txFee = gasPrice.mul(gasUsed);
73+
const provider = account.provider as any;
74+
if (typeof provider.getL1Fee === 'function') {
75+
const l1Fee = await provider.getL1Fee(txReceipt.transactionHash);
76+
return txFee.add(l1Fee);
77+
}
7378

7479
return txFee;
7580
}

‎waffle-chai/src/matchers/revertedWith.ts

+18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function supportRevertedWith(Assertion: Chai.AssertionStatic) {
1616
const onError = (error: any) => {
1717
const revertString = error?.receipt?.revertString ??
1818
decodeHardhatError(error, this) ??
19+
decodeOptimismError(error) ??
1920
decodeRevertString(error);
2021

2122
const isReverted = revertReason instanceof RegExp
@@ -73,3 +74,20 @@ const decodeHardhatError = (error: any, context: any) => {
7374

7475
return tryDecode(error) ?? tryDecode(error.error); // the error may be wrapped
7576
};
77+
78+
const decodeOptimismError = (error: any) => {
79+
const tryDecode = (error: any) => {
80+
const body = error?.body;
81+
if (body) {
82+
const regexp = /"execution reverted: (.*)"/g;
83+
const matches = regexp.exec(body);
84+
if (matches && matches.length >= 1) {
85+
return matches[1];
86+
}
87+
}
88+
};
89+
90+
return tryDecode(error) ??
91+
tryDecode(error?.error) ??
92+
tryDecode(error?.error?.error);
93+
};
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {changeEtherBalanceTest} from './changeEtherBalanceTest';
2+
import {BASE_FEE_PER_GAS, TX_GAS} from './constants';
23
import {describeMockProviderCases} from './MockProviderCases';
34

45
describeMockProviderCases('INTEGRATION: changeEtherBalance matcher', (provider) => {
5-
changeEtherBalanceTest(provider);
6+
changeEtherBalanceTest(provider, {txGasFees: TX_GAS * BASE_FEE_PER_GAS, baseFeePerGas: BASE_FEE_PER_GAS});
67
});

‎waffle-chai/test/matchers/changeEtherBalanceTest.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@ import {MockProvider} from '@ethereum-waffle/provider';
22
import {expect, AssertionError} from 'chai';
33
import {BigNumber, Contract, Wallet} from 'ethers';
44

5-
import {BASE_FEE_PER_GAS, TX_GAS} from './constants';
6-
7-
export const changeEtherBalanceTest = (provider: MockProvider) => {
5+
interface ChangeEtherBalanceTestOptions {
6+
txGasFees: number | (() => number);
7+
baseFeePerGas: number;
8+
}
9+
10+
export const changeEtherBalanceTest = (
11+
provider: MockProvider,
12+
options: ChangeEtherBalanceTestOptions
13+
) => {
14+
let txGasFees: number;
15+
let baseFeePerGas: number;
816
let sender: Wallet;
917
let receiver: Wallet;
1018
let contract: Contract;
11-
let txGasFees: number;
1219

1320
before(() => {
21+
txGasFees = typeof options.txGasFees === 'function' ? options.txGasFees() : options.txGasFees;
22+
baseFeePerGas = options.baseFeePerGas;
1423
const wallets = provider.getWallets();
1524
sender = wallets[0];
1625
receiver = wallets[1];
1726
contract = new Contract(receiver.address, [], provider);
18-
txGasFees = BASE_FEE_PER_GAS * TX_GAS;
1927
});
2028

2129
describe('Transaction Callback', () => {
@@ -42,7 +50,7 @@ export const changeEtherBalanceTest = (provider: MockProvider) => {
4250
await expect(() =>
4351
sender.sendTransaction({
4452
to: receiver.address,
45-
gasPrice: BASE_FEE_PER_GAS,
53+
gasPrice: baseFeePerGas,
4654
value: 200
4755
})
4856
).to.changeEtherBalance(sender, -(txGasFees + 200), {includeFee: true});
@@ -52,7 +60,7 @@ export const changeEtherBalanceTest = (provider: MockProvider) => {
5260
await expect(() =>
5361
sender.sendTransaction({
5462
to: receiver.address,
55-
gasPrice: BASE_FEE_PER_GAS,
63+
gasPrice: baseFeePerGas,
5664
value: 200
5765
})
5866
).to.changeEtherBalance(receiver, 200, {includeFee: true});
@@ -62,7 +70,7 @@ export const changeEtherBalanceTest = (provider: MockProvider) => {
6270
await expect(() =>
6371
sender.sendTransaction({
6472
to: receiver.address,
65-
gasPrice: BASE_FEE_PER_GAS,
73+
gasPrice: baseFeePerGas,
6674
value: 200
6775
})
6876
).to.changeEtherBalance(sender, -200);
@@ -91,13 +99,13 @@ export const changeEtherBalanceTest = (provider: MockProvider) => {
9199
expect(() =>
92100
sender.sendTransaction({
93101
to: receiver.address,
94-
gasPrice: BASE_FEE_PER_GAS,
102+
gasPrice: baseFeePerGas,
95103
value: 200
96104
})
97105
).to.changeEtherBalance(sender, -200, {includeFee: true})
98106
).to.be.eventually.rejectedWith(
99107
AssertionError,
100-
`Expected "${sender.address}" to change balance by -200 wei, but it has changed by -18375000000200 wei`
108+
`Expected "${sender.address}" to change balance by -200 wei, but it has changed by -${txGasFees + 200} wei`
101109
);
102110
});
103111

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {changeEtherBalancesTest} from './changeEtherBalancesTest';
2+
import {TX_GAS, BASE_FEE_PER_GAS} from './constants';
23
import {describeMockProviderCases} from './MockProviderCases';
34

45
describeMockProviderCases('INTEGRATION: changeEtherBalances matcher', (provider) => {
5-
changeEtherBalancesTest(provider);
6+
changeEtherBalancesTest(provider, {txGasFees: TX_GAS * BASE_FEE_PER_GAS, baseFeePerGas: BASE_FEE_PER_GAS});
67
});

‎waffle-chai/test/matchers/changeEtherBalancesTest.ts

+23-15
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@ import {MockProvider} from '@ethereum-waffle/provider';
22
import {expect, AssertionError} from 'chai';
33
import {Contract, Wallet} from 'ethers';
44

5-
import {BASE_FEE_PER_GAS, TX_GAS} from './constants';
6-
7-
export const changeEtherBalancesTest = (provider: MockProvider) => {
5+
interface ChangeEtherBalancesTestOptions {
6+
txGasFees: number | (() => number);
7+
baseFeePerGas: number;
8+
}
9+
10+
export const changeEtherBalancesTest = (
11+
provider: MockProvider,
12+
options: ChangeEtherBalancesTestOptions
13+
) => {
14+
let txGasFees: number;
15+
let baseFeePerGas: number;
816
let sender: Wallet;
917
let receiver: Wallet;
1018
let contractWallet: Wallet;
1119
let contract: Contract;
12-
let txGasFees: number;
1320

1421
before(() => {
22+
txGasFees = typeof options.txGasFees === 'function' ? options.txGasFees() : options.txGasFees;
23+
baseFeePerGas = options.baseFeePerGas;
1524
const wallets = provider.getWallets();
1625
sender = wallets[0];
1726
receiver = wallets[1];
1827
contractWallet = wallets[2];
1928
contract = new Contract(contractWallet.address, [], provider);
20-
txGasFees = BASE_FEE_PER_GAS * TX_GAS;
2129
});
2230

2331
describe('Transaction Callback', () => {
@@ -37,7 +45,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
3745
await expect(() =>
3846
sender.sendTransaction({
3947
to: receiver.address,
40-
gasPrice: BASE_FEE_PER_GAS,
48+
gasPrice: baseFeePerGas,
4149
value: 200
4250
})
4351
).to.changeEtherBalances([sender, receiver], ['-200', 200]);
@@ -47,7 +55,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
4755
await expect(() =>
4856
sender.sendTransaction({
4957
to: receiver.address,
50-
gasPrice: BASE_FEE_PER_GAS,
58+
gasPrice: baseFeePerGas,
5159
value: 200
5260
})
5361
).to.changeEtherBalances([sender, receiver, contract], [-(txGasFees + 200), 200, 0], {includeFee: true});
@@ -57,7 +65,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
5765
await expect(() =>
5866
sender.sendTransaction({
5967
to: receiver.address,
60-
gasPrice: BASE_FEE_PER_GAS,
68+
gasPrice: baseFeePerGas,
6169
value: 200
6270
})
6371
).to.not.changeEtherBalances([sender, receiver], [-(txGasFees + 201), 200]);
@@ -74,7 +82,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
7482
expect(() =>
7583
sender.sendTransaction({
7684
to: receiver.address,
77-
gasPrice: BASE_FEE_PER_GAS,
85+
gasPrice: baseFeePerGas,
7886
value: 200
7987
})
8088
).to.changeEtherBalances([sender, receiver], [-200, 201])
@@ -87,7 +95,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
8795
expect(() =>
8896
sender.sendTransaction({
8997
to: receiver.address,
90-
gasPrice: BASE_FEE_PER_GAS,
98+
gasPrice: baseFeePerGas,
9199
value: 200
92100
})
93101
).to.changeEtherBalances([sender, receiver], [-201, 200])
@@ -103,7 +111,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
103111
expect(() =>
104112
sender.sendTransaction({
105113
to: receiver.address,
106-
gasPrice: BASE_FEE_PER_GAS,
114+
gasPrice: baseFeePerGas,
107115
value: 200
108116
})
109117
).to.not.changeEtherBalances([sender, receiver], [-200, 200])
@@ -131,7 +139,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
131139
it('Should pass when all expected balance changes are equal to actual values', async () => {
132140
await expect(await sender.sendTransaction({
133141
to: receiver.address,
134-
gasPrice: BASE_FEE_PER_GAS,
142+
gasPrice: baseFeePerGas,
135143
value: 200
136144
})
137145
).to.changeEtherBalances([sender, receiver], [(-(txGasFees + 200)).toString(), 200], {includeFee: true});
@@ -140,7 +148,7 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
140148
it('Should take into account transaction fee', async () => {
141149
await expect(await sender.sendTransaction({
142150
to: receiver.address,
143-
gasPrice: BASE_FEE_PER_GAS,
151+
gasPrice: baseFeePerGas,
144152
value: 200
145153
})
146154
).to.changeEtherBalances([sender, receiver, contract], [-(txGasFees + 200), 200, 0], {includeFee: true});
@@ -164,14 +172,14 @@ export const changeEtherBalancesTest = (provider: MockProvider) => {
164172
await expect(
165173
expect(await sender.sendTransaction({
166174
to: receiver.address,
167-
gasPrice: BASE_FEE_PER_GAS,
175+
gasPrice: baseFeePerGas,
168176
value: 200
169177
})
170178
).to.changeEtherBalances([sender, receiver], [-200, 200], {includeFee: true})
171179
).to.be.eventually.rejectedWith(
172180
AssertionError,
173181
`Expected ${sender.address},${receiver.address} to change balance ` +
174-
'by -200,200 wei, but it has changed by -18375000000200,200 wei'
182+
`by -200,200 wei, but it has changed by -${txGasFees + 200},200 wei`
175183
);
176184
});
177185

‎waffle-chai/test/matchers/revertedWithTest.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import {MATCHERS_ABI, MATCHERS_BYTECODE} from '../contracts/Matchers';
44

55
import {MockProvider} from '@ethereum-waffle/provider';
66

7-
export const revertedWithTest = (provider: MockProvider) => {
7+
interface RevertedWithTestingOptions {
8+
includePanicCodes?: boolean;
9+
}
10+
11+
export const revertedWithTest = (provider: MockProvider, options: RevertedWithTestingOptions = {}) => {
12+
const panicCodes = options.includePanicCodes ?? true;
813
let wallet: Wallet;
914
let matchers: Contract;
1015

@@ -182,7 +187,9 @@ export const revertedWithTest = (provider: MockProvider) => {
182187
).to.be.eventually.rejected;
183188
});
184189

185-
it('Handle panic error', async () => {
186-
await expect(matchers.doPanic()).to.be.revertedWith('panic code 0x12');
187-
});
190+
if (panicCodes) {
191+
it('Handle panic error', async () => {
192+
await expect(matchers.doPanic()).to.be.revertedWith('panic code 0x12');
193+
});
194+
}
188195
};
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {waffle} from 'hardhat';
22
import {MockProvider} from 'ethereum-waffle';
33
import {changeEtherBalanceTest} from '@ethereum-waffle/chai/test';
4+
import {TX_GAS, BASE_FEE_PER_GAS} from './constants';
45

56
describe('INTEGRATION: changeEtherBalance matcher', () => {
67
const provider = waffle.provider as MockProvider;
@@ -9,5 +10,5 @@ describe('INTEGRATION: changeEtherBalance matcher', () => {
910
await provider.send('hardhat_reset', []);
1011
});
1112

12-
changeEtherBalanceTest(provider);
13+
changeEtherBalanceTest(provider, {txGasFees: TX_GAS * BASE_FEE_PER_GAS, baseFeePerGas: BASE_FEE_PER_GAS});
1314
});
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {waffle} from 'hardhat';
22
import {MockProvider} from 'ethereum-waffle';
33
import {changeEtherBalancesTest} from '@ethereum-waffle/chai/test';
4+
import {TX_GAS, BASE_FEE_PER_GAS} from './constants';
45

56
describe('INTEGRATION: changeEtherBalance matcher', () => {
67
const provider = waffle.provider as MockProvider;
@@ -9,5 +10,5 @@ describe('INTEGRATION: changeEtherBalance matcher', () => {
910
await provider.send('hardhat_reset', []);
1011
});
1112

12-
changeEtherBalancesTest(provider);
13+
changeEtherBalancesTest(provider, {txGasFees: TX_GAS * BASE_FEE_PER_GAS, baseFeePerGas: BASE_FEE_PER_GAS});
1314
});

‎waffle-hardhat/test/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const TX_GAS = 21000; // Gas used by a single, non-contract transaction.
2+
export const BASE_FEE_PER_GAS = 875000000;

‎waffle-optimism/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../.eslintrc.json')

‎waffle-optimism/.mocharc.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
process.env.NODE_ENV = 'test'
2+
module.exports = {
3+
require: 'ts-node/register/transpile-only',
4+
timeout: 50000,
5+
spec: 'test/**/*.test.{js,ts}'
6+
}

‎waffle-optimism/package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@ethereum-waffle/optimism",
3+
"description": "Testing waffle with optimism",
4+
"version": "4.0.0-alpha.20",
5+
"author": "Marek Kirejczyk <account@ethworks.io> (http://ethworks.io)",
6+
"repository": "git@github.com:EthWorks/Waffle.git",
7+
"private": true,
8+
"license": "MIT",
9+
"main": "dist/cjs/index.js",
10+
"module": "dist/esm/index.ts",
11+
"types": "dist/esm/index.d.ts",
12+
"scripts": {
13+
"build": "true",
14+
"test": "true",
15+
"test:optimism": "mocha",
16+
"lint": "eslint '{src,test}/**/*.ts'",
17+
"lint:fix": "eslint --fix '{src,test}/**/*.ts'"
18+
},
19+
"engines": {
20+
"node": ">=10.0"
21+
},
22+
"dependencies": {
23+
"@ethersproject/providers": "^5.6.2",
24+
"ethers": "5.6.2"
25+
},
26+
"devDependencies": {
27+
"@ethereum-waffle/chai": "workspace:*",
28+
"eslint": "^7.14.0",
29+
"ethereum-waffle": "workspace:*",
30+
"mocha": "^8.2.1"
31+
}
32+
}

‎waffle-optimism/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './provider';

‎waffle-optimism/src/provider.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {JsonRpcProvider} from '@ethersproject/providers';
2+
import type {MockProvider} from 'ethereum-waffle';
3+
import {BigNumber, Wallet} from 'ethers';
4+
5+
const privateKeys = [
6+
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
7+
'0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',
8+
'0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',
9+
'0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6',
10+
'0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a',
11+
'0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e',
12+
'0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356',
13+
'0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97',
14+
'0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6',
15+
'0xf214f2b2cd398c806f84e317254e0f0b801d0643303237d97a22a48e01628897',
16+
'0x701b615bbdfb9de65240bc28bd21bbc0d996645a3dd57e7b12bc2bdf6f192c82',
17+
'0xa267530f49f8280200edf313ee7af6b827f2a8bce2897751d06a843f644967b1',
18+
'0x47c99abed3324a2707c28affff1267e45918ec8c3f20b8aa892e8b065d2942dd',
19+
'0xc526ee95bf44d8fc405a158bb884d9d1238d99f0612e9f33d006bb0789009aaa',
20+
'0x8166f546bab6da521a8369cab06c5d2b9e46670292d85c875ee9ec20e84ffb61',
21+
'0xea6c44ac03bff858b476bba40716402b03e41b8e97e276d1baec7c37d42484a0',
22+
'0x689af8efa8c651a91ad287602527f3af2fe9f6501a7ac4b061667b5a93e037fd',
23+
'0xde9be858da4a475276426320d5e9262ecfc3ba460bfac56360bfa6c4c28b4ee0',
24+
'0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e'
25+
];
26+
27+
export class OptimismProvider extends JsonRpcProvider {
28+
getWallets(): Wallet[] {
29+
return privateKeys.map(key => new Wallet(key, this));
30+
}
31+
32+
async getL1Fee(transactionHash: string): Promise<BigNumber> {
33+
const fullReceipt = await this.perform('getTransactionReceipt', {transactionHash});
34+
return BigNumber.from(fullReceipt.l1Fee);
35+
}
36+
}
37+
38+
export const getOptimismProvider = (url = 'http://localhost:8545'): MockProvider => {
39+
const provider = new OptimismProvider(url);
40+
return provider as unknown as MockProvider;
41+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {chainingMatchersTest} from '@ethereum-waffle/chai/test';
2+
import {getOptimismProvider} from '../src/provider';
3+
4+
describe('Optimism: chaining', () => {
5+
const provider = getOptimismProvider();
6+
7+
chainingMatchersTest(provider);
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {changeEtherBalanceTest} from '@ethereum-waffle/chai/test';
2+
import {getOptimismProvider} from '../src';
3+
import {calculateL2TxGasFee} from './utils';
4+
5+
describe('Optimism: changeEtherBalance matcher', () => {
6+
const provider = getOptimismProvider();
7+
let txGasFees: number;
8+
9+
// needed to get fees for a single transaction on Optimism - it can be non constant
10+
before(async () => {
11+
txGasFees = await calculateL2TxGasFee(provider as any);
12+
});
13+
14+
changeEtherBalanceTest(provider, {txGasFees: () => txGasFees, baseFeePerGas: 1});
15+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {changeEtherBalancesTest} from '@ethereum-waffle/chai/test';
2+
import {getOptimismProvider} from '../src';
3+
import {calculateL2TxGasFee} from './utils';
4+
5+
describe('Optimism: changeEtherBalances matcher', () => {
6+
const provider = getOptimismProvider();
7+
let txGasFees: number;
8+
9+
before(async () => {
10+
txGasFees = await calculateL2TxGasFee(provider as any);
11+
});
12+
13+
changeEtherBalancesTest(provider, {txGasFees: () => txGasFees, baseFeePerGas: 1});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {changeTokenBalanceTest} from '@ethereum-waffle/chai/test';
2+
import {getOptimismProvider} from '../src/provider';
3+
4+
describe('Optimism: changeTokenBalance matcher', () => {
5+
const provider = getOptimismProvider();
6+
7+
changeTokenBalanceTest(provider);
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {changeTokenBalancesTest} from '@ethereum-waffle/chai/test';
2+
import {getOptimismProvider} from '../src/provider';
3+
4+
describe('Optimism: changeEtherBalance matcher', () => {
5+
const provider = getOptimismProvider();
6+
7+
changeTokenBalancesTest(provider);
8+
});
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {eventsTest} from '@ethereum-waffle/chai/test';
2+
import {getOptimismProvider} from '../src/provider';
3+
4+
describe('Optimism: changeEtherBalance matcher', () => {
5+
const provider = getOptimismProvider();
6+
7+
eventsTest(provider);
8+
});
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {revertedTest, revertedWithTest} from '@ethereum-waffle/chai/test';
2+
import {getOptimismProvider} from '../src/provider';
3+
4+
describe('Optimism: Matchers: reverted', () => {
5+
const provider = getOptimismProvider();
6+
7+
revertedTest(provider);
8+
});
9+
10+
describe('Optimism: Matchers: revertedWith', () => {
11+
const provider = getOptimismProvider();
12+
13+
revertedWithTest(provider, {includePanicCodes: false});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {OptimismProvider} from '../../src/provider';
2+
3+
/* needed to get fees for a single transaction on Optimism - it can be non constant
4+
*
5+
*/
6+
export const calculateL2TxGasFee = async (provider: OptimismProvider) => {
7+
const [sender, receiver] = provider.getWallets();
8+
const tx = await sender.sendTransaction({
9+
to: receiver.address,
10+
value: 200
11+
});
12+
const txReceipt = await tx.wait();
13+
const l1Fee = await provider.getL1Fee(txReceipt.transactionHash);
14+
const txGasFees = txReceipt.gasUsed.mul(tx.gasPrice ?? txReceipt.effectiveGasPrice).add(l1Fee).toNumber();
15+
return txGasFees;
16+
};
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './getTxGasFees';

‎waffle-optimism/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"references": [
4+
{
5+
"path": "../waffle-chai"
6+
},
7+
{
8+
"path": "../waffle-cli"
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)
Please sign in to comment.