Skip to content

Commit 4c1629b

Browse files
committed
fix benchmarks
1 parent a6c28aa commit 4c1629b

File tree

7 files changed

+190
-152
lines changed

7 files changed

+190
-152
lines changed

benchmark/Safe.Creation.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import "@nomiclabs/hardhat-ethers";
2-
import { setupBenchmarkContracts } from "./utils/setup"
1+
import { setupBenchmarkContracts } from "./utils/setup";
32

4-
const contractSetup = setupBenchmarkContracts(undefined, true)
5-
describe("Safe", async () => {
3+
const contractSetup = setupBenchmarkContracts(undefined, true);
4+
describe("Safe", () => {
65
it("creation", async () => {
7-
await contractSetup()
8-
})
9-
})
6+
await contractSetup();
7+
});
8+
});

benchmark/Safe.ERC1155.spec.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
import { expect } from "chai";
22
import { ethers } from "hardhat";
3-
import "@nomiclabs/hardhat-ethers";
3+
import { BigNumberish } from "ethers";
44
import { buildSafeTransaction } from "../src/utils/execution";
55
import { benchmark, Contracts } from "./utils/setup";
66

7-
const [, , , , user5] = await ethers.getSigners();
8-
9-
benchmark("ERC1155", [
10-
{
11-
name: "transfer",
12-
prepare: async (contracts: Contracts, target: string, nonce: number) => {
13-
const token = contracts.additions.token;
14-
await token.mint(target, 23, 1337, "0x");
15-
const data = token.interface.encodeFunctionData("safeTransferFrom", [target, user5.address, 23, 500, "0x"]);
16-
return buildSafeTransaction({ to: token.address, data, safeTxGas: 1000000, nonce });
17-
},
18-
after: async (contracts: Contracts) => {
19-
expect(await contracts.additions.token.balanceOf(user5.address, 23)).to.eq(500n);
20-
},
21-
fixture: async () => {
22-
const tokenFactory = await ethers.getContractFactory("ERC1155Token");
23-
return {
24-
token: await tokenFactory.deploy(),
25-
};
7+
benchmark("ERC1155", async () => {
8+
const [, , , , user5] = await ethers.getSigners();
9+
return [
10+
{
11+
name: "transfer",
12+
prepare: async (contracts: Contracts, target: string, nonce: BigNumberish) => {
13+
const token = contracts.additions.token;
14+
const tokenAddress = await token.getAddress();
15+
await token.mint(target, 23, 1337, "0x");
16+
const data = token.interface.encodeFunctionData("safeTransferFrom", [target, user5.address, 23, 500, "0x"]);
17+
return buildSafeTransaction({ to: tokenAddress, data, safeTxGas: 1000000, nonce });
18+
},
19+
after: async (contracts: Contracts) => {
20+
expect(await contracts.additions.token.balanceOf(user5.address, 23)).to.eq(500n);
21+
},
22+
fixture: async () => {
23+
const tokenFactory = await ethers.getContractFactory("ERC1155Token");
24+
return {
25+
token: await tokenFactory.deploy(),
26+
};
27+
},
2628
},
27-
},
28-
]);
29+
];
30+
});

benchmark/Safe.ERC20.spec.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import { expect } from "chai";
22
import { ethers } from "hardhat";
3-
import "@nomiclabs/hardhat-ethers";
3+
import { BigNumberish } from "ethers";
44
import { buildSafeTransaction } from "../src/utils/execution";
55
import { benchmark, Contracts } from "./utils/setup";
66

7-
const [, , , , user5] = await ethers.getSigners();
7+
benchmark("ERC20", async () => {
8+
const [, , , , user5] = await ethers.getSigners();
89

9-
benchmark("ERC20", [
10-
{
11-
name: "transfer",
12-
prepare: async (contracts: Contracts, target: string, nonce: number) => {
13-
const token = contracts.additions.token;
14-
await token.transfer(target, 1000);
15-
const data = token.interface.encodeFunctionData("transfer", [user5.address, 500]);
16-
return buildSafeTransaction({ to: token.address, data, safeTxGas: 1000000, nonce });
10+
return [
11+
{
12+
name: "transfer",
13+
prepare: async (contracts: Contracts, target: string, nonce: BigNumberish) => {
14+
const token = contracts.additions.token;
15+
const tokenAddress = await token.getAddress();
16+
await token.transfer(target, 1000);
17+
const data = token.interface.encodeFunctionData("transfer", [user5.address, 500]);
18+
return buildSafeTransaction({ to: tokenAddress, data, safeTxGas: 1000000, nonce });
19+
},
20+
after: async (contracts: Contracts) => {
21+
expect(await contracts.additions.token.balanceOf(user5.address)).to.eq(500n);
22+
},
23+
fixture: async () => {
24+
const tokenFactory = await ethers.getContractFactory("ERC20Token");
25+
return {
26+
token: await tokenFactory.deploy(),
27+
};
28+
},
1729
},
18-
after: async (contracts: Contracts) => {
19-
expect(await contracts.additions.token.balanceOf(user5.address)).to.eq(500n);
20-
},
21-
fixture: async () => {
22-
const tokenFactory = await ethers.getContractFactory("ERC20Token");
23-
return {
24-
token: await tokenFactory.deploy(),
25-
};
26-
},
27-
},
28-
]);
30+
];
31+
});

benchmark/Safe.Ether.spec.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import { expect } from "chai";
22
import { ethers } from "hardhat";
3+
import { BigNumberish } from "ethers";
34
import { buildSafeTransaction } from "../src/utils/execution";
45
import { benchmark } from "./utils/setup";
56

67
const testTarget = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
7-
const [user1] = await ethers.getSigners();
88

9-
benchmark("Ether", [
10-
{
11-
name: "transfer",
12-
prepare: async (_, target: string, nonce: number) => {
13-
// Create account, as we don't want to test this in the benchmark
14-
await user1.sendTransaction({ to: testTarget, value: 1 });
15-
await user1.sendTransaction({ to: target, value: 1000 });
16-
return buildSafeTransaction({ to: testTarget, value: 500, safeTxGas: 1000000, nonce });
9+
benchmark("Ether", async () => {
10+
const [user1] = await ethers.getSigners();
11+
return [
12+
{
13+
name: "transfer",
14+
prepare: async (_, target: string, nonce: BigNumberish) => {
15+
// Create account, as we don't want to test this in the benchmark
16+
await user1.sendTransaction({ to: testTarget, value: 1 });
17+
await user1.sendTransaction({ to: target, value: 1000 });
18+
return buildSafeTransaction({ to: testTarget, value: 500, safeTxGas: 1000000, nonce });
19+
},
20+
after: async () => {
21+
expect(await ethers.provider.getBalance(testTarget)).to.eq(501n);
22+
},
1723
},
18-
after: async () => {
19-
expect(await ethers.provider.getBalance(testTarget)).to.eq(501n);
20-
},
21-
},
22-
]);
24+
];
25+
});

benchmark/Safe.Proxy.spec.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
import "@nomiclabs/hardhat-ethers";
21
import { buildSafeTransaction } from "../src/utils/execution";
3-
import { benchmark } from "./utils/setup"
2+
import { benchmark } from "./utils/setup";
43
import { getFactory } from "../test/utils/setup";
54

6-
benchmark("Proxy", [{
7-
name: "creation",
8-
prepare: async (contracts,_,nonce) => {
9-
const factory = contracts.additions.factory
10-
// We're cheating and passing the factory address as a singleton address to bypass a check that singleton contract exists
11-
const data = factory.interface.encodeFunctionData("createProxyWithNonce", [factory.address, "0x", 0])
12-
return buildSafeTransaction({ to: factory.address, data, safeTxGas: 1000000, nonce })
5+
benchmark("Proxy", async () => [
6+
{
7+
name: "creation",
8+
prepare: async (contracts, _, nonce) => {
9+
const factory = contracts.additions.factory;
10+
const factoryAddress = await factory.getAddress();
11+
// We're cheating and passing the factory address as a singleton address to bypass a check that singleton contract exists
12+
const data = factory.interface.encodeFunctionData("createProxyWithNonce", [factoryAddress, "0x", 0]);
13+
return buildSafeTransaction({ to: factoryAddress, data, safeTxGas: 1000000, nonce });
14+
},
15+
fixture: async () => {
16+
return {
17+
factory: await getFactory(),
18+
};
19+
},
1320
},
14-
fixture: async () => {
15-
return {
16-
factory: await getFactory(),
17-
}
18-
}
19-
}])
21+
]);
2022

21-
benchmark("Proxy", [{
22-
name: "chain specific creation",
23-
prepare: async (contracts,_,nonce) => {
24-
const factory = contracts.additions.factory
25-
// We're cheating and passing the factory address as a singleton address to bypass a check that singleton contract exists
26-
const data = factory.interface.encodeFunctionData("createChainSpecificProxyWithNonce", [factory.address, "0x", 0])
27-
return buildSafeTransaction({ to: factory.address, data, safeTxGas: 1000000, nonce })
23+
benchmark("Proxy", async () => [
24+
{
25+
name: "chain specific creation",
26+
prepare: async (contracts, _, nonce) => {
27+
const factory = contracts.additions.factory;
28+
const factoryAddress = await factory.getAddress();
29+
// We're cheating and passing the factory address as a singleton address to bypass a check that singleton contract exists
30+
const data = factory.interface.encodeFunctionData("createChainSpecificProxyWithNonce", [factoryAddress, "0x", 0]);
31+
return buildSafeTransaction({ to: factoryAddress, data, safeTxGas: 1000000, nonce });
32+
},
33+
fixture: async () => {
34+
return {
35+
factory: await getFactory(),
36+
};
37+
},
2838
},
29-
fixture: async () => {
30-
return {
31-
factory: await getFactory(),
32-
}
33-
}
34-
}])
39+
]);

0 commit comments

Comments
 (0)