Skip to content

Commit db2a49c

Browse files
committed
chore: remove unused functions and move single-use function
1 parent 1365923 commit db2a49c

12 files changed

+57
-204
lines changed

test/balancer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@ export enum UserBalanceOpKind {
44
TRANSFER_INTERNAL = 2,
55
TRANSFER_EXTERNAL = 3,
66
}
7-
8-
export enum BalancerErrors {
9-
SWAP_LIMIT = "BAL#507",
10-
SWAP_DEADLINE = "BAL#508",
11-
}

test/bytecode.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/decoding.test.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { constants, utils, Wallet } from "ethers";
2+
import { constants, ethers, utils, Wallet } from "ethers";
33
import { waffle } from "hardhat";
44

55
import {
@@ -20,8 +20,6 @@ import {
2020
signOrder,
2121
} from "../src/ts";
2222

23-
import { fillDistinctBytes, SAMPLE_ORDER } from "./testHelpers";
24-
2523
type UnknownArray = unknown[] | readonly unknown[];
2624
// [A, B, C] -> [A, B]
2725
type RemoveLast<T extends UnknownArray> = T extends [...infer U, unknown]
@@ -107,6 +105,29 @@ function validFlags(): TradeFlags[] {
107105
/* eslint-enable @typescript-eslint/no-explicit-any */
108106
}
109107

108+
function fillDistinctBytes(count: number, start: number): string {
109+
return ethers.utils.hexlify(
110+
[...Array(count)].map((_, i) => (start + i) % 256),
111+
);
112+
}
113+
114+
function fillBytes(count: number, byte: number): string {
115+
return ethers.utils.hexlify([...Array(count)].map(() => byte));
116+
}
117+
118+
const SAMPLE_ORDER = {
119+
sellToken: fillBytes(20, 0x01),
120+
buyToken: fillBytes(20, 0x02),
121+
receiver: fillBytes(20, 0x03),
122+
sellAmount: ethers.utils.parseEther("42"),
123+
buyAmount: ethers.utils.parseEther("13.37"),
124+
validTo: 0xffffffff,
125+
appData: ethers.constants.HashZero,
126+
feeAmount: ethers.utils.parseEther("1.0"),
127+
kind: OrderKind.SELL,
128+
partiallyFillable: false,
129+
};
130+
110131
describe("Order flags", () => {
111132
it("encodeTradeFlags is the right inverse of decodeTradeFlags", () => {
112133
for (const tradeFlags of validFlags()) {

test/e2e/balancerSwap.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ import {
1414
domain,
1515
grantRequiredRoles,
1616
} from "../../src/ts";
17-
import { UserBalanceOpKind, BalancerErrors } from "../balancer";
17+
import { UserBalanceOpKind } from "../balancer";
1818

1919
import { deployTestContracts } from "./fixture";
2020

21+
export enum BalancerErrors {
22+
SWAP_LIMIT = "BAL#507",
23+
SWAP_DEADLINE = "BAL#508",
24+
}
25+
2126
const LOTS = ethers.utils.parseEther("10000.0");
2227
const debug = Debug("e2e:balancerSwap");
2328

test/e2e/deployment.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
implementationAddress,
1111
proxyInterface,
1212
} from "../../src/ts";
13-
import { builtAndDeployedMetadataCoincide } from "../bytecode";
1413

1514
import { deployTestContracts } from "./fixture";
1615

@@ -22,6 +21,26 @@ async function contractAddress<C extends ContractName>(
2221
return deterministicDeploymentAddress(artifact, deploymentArguments);
2322
}
2423

24+
async function builtAndDeployedMetadataCoincide(
25+
contractAddress: string,
26+
contractName: string,
27+
): Promise<boolean> {
28+
const contractArtifacts = await artifacts.readArtifact(contractName);
29+
30+
const code = await ethers.provider.send("eth_getCode", [
31+
contractAddress,
32+
"latest",
33+
]);
34+
35+
// NOTE: The last 53 bytes in a deployed contract's bytecode contains the
36+
// contract metadata. Compare the deployed contract's metadata with the
37+
// compiled contract's metadata.
38+
// <https://docs.soliditylang.org/en/v0.7.6/metadata.html>
39+
const metadata = (bytecode: string) => bytecode.slice(-106);
40+
41+
return metadata(code) === metadata(contractArtifacts.deployedBytecode);
42+
}
43+
2544
describe("E2E: Deployment", () => {
2645
let owner: Wallet;
2746
let manager: Wallet;

test/e2e/wineOilMarket.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ERC20 from "@openzeppelin/contracts/build/contracts/ERC20PresetMinterPauser.json";
22
import { expect } from "chai";
3-
import { BigNumber, Contract, Wallet } from "ethers";
3+
import { BigNumber, BigNumberish, Contract, Wallet } from "ethers";
44
import { ethers, waffle } from "hardhat";
55

66
import {
@@ -11,10 +11,13 @@ import {
1111
TypedDataDomain,
1212
domain,
1313
} from "../../src/ts";
14-
import { ceilDiv } from "../testHelpers";
1514

1615
import { deployTestContracts } from "./fixture";
1716

17+
function ceilDiv(p: BigNumberish, q: BigNumberish): BigNumber {
18+
return BigNumber.from(p).add(q).sub(1).div(q);
19+
}
20+
1821
describe("E2E: RetrETH Red Wine and Olive Oil Market", () => {
1922
let deployer: Wallet;
2023
let solver: Wallet;

test/encoding.ts

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import { BigNumber } from "ethers";
22
import { ethers } from "hardhat";
33

4-
import {
5-
Order,
6-
OrderBalance,
7-
OrderKind,
8-
normalizeOrder,
9-
FLAG_MASKS,
10-
FlagKey,
11-
FlagOptions,
12-
} from "../src/ts";
4+
import { Order, OrderBalance, OrderKind } from "../src/ts";
135

14-
export type AbiOrder = [
6+
type AbiOrder = [
157
string,
168
string,
179
string,
@@ -26,42 +18,6 @@ export type AbiOrder = [
2618
string,
2719
];
2820

29-
function optionsForKey<K extends FlagKey>(key: K): FlagOptions<K> {
30-
return FLAG_MASKS[key].options;
31-
}
32-
export const allOrderKinds = optionsForKey("kind");
33-
export const allPartiallyFillable = optionsForKey("partiallyFillable");
34-
export const allSigningSchemes = optionsForKey("signingScheme");
35-
36-
export function allOptions<
37-
K extends FlagKey,
38-
AllOptions extends Record<K, FlagOptions<K>>,
39-
>(): AllOptions {
40-
const result: Record<string, FlagOptions<K>> = {};
41-
Object.entries(FLAG_MASKS).map(
42-
([key, value]) => (result[key] = value.options),
43-
);
44-
return result as AllOptions;
45-
}
46-
47-
export function encodeOrder(order: Order): AbiOrder {
48-
const o = normalizeOrder(order);
49-
return [
50-
o.sellToken,
51-
o.buyToken,
52-
o.receiver,
53-
BigNumber.from(o.sellAmount),
54-
BigNumber.from(o.buyAmount),
55-
o.validTo,
56-
o.appData,
57-
BigNumber.from(o.feeAmount),
58-
ethers.utils.id(o.kind),
59-
o.partiallyFillable,
60-
ethers.utils.id(o.sellTokenBalance),
61-
ethers.utils.id(o.buyTokenBalance),
62-
];
63-
}
64-
6521
function decodeEnum<T>(hash: string, values: T[]): T {
6622
for (const value of values) {
6723
if (hash == ethers.utils.id(`${value}`)) {

test/hardhatNetwork.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/sign.test.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

test/src/FeeClaimingERC20.sol

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/src/TestERC20.sol

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/testHelpers.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)