-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBundleDataClient.ts
122 lines (112 loc) · 3.45 KB
/
BundleDataClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { expect } from "chai";
import { BundleData, BundleDataClient } from "../src/clients/BundleDataClient";
import { getMessageHash, randomAddress, toBN } from "../src/utils";
import { UNDEFINED_MESSAGE_HASH } from "../src/constants";
import { MockSpokePoolClient } from "../src/clients/mocks";
import { createSpyLogger } from "./utils";
const random = () => Math.round(Math.random() * 1e6);
describe("BundleDataClient", function () {
let chainIds: number[];
let spokePoolClients: { [chainId: number]: MockSpokePoolClient };
let bundleDataClient: BundleDataClient;
const logger = createSpyLogger().spyLogger;
const l1Token = randomAddress();
const originChainId = 1;
beforeEach(function () {
spokePoolClients = {};
bundleDataClient = new BundleDataClient(
logger,
{}, // commonClients
spokePoolClients,
chainIds,
{} // block buffers
);
});
it("Correctly appends message hashes to deposit and fill events", function () {
const eventData = {
depositor: randomAddress(),
recipient: randomAddress(),
originChainId,
destinationChainId: random(),
inputToken: randomAddress(),
outputToken: randomAddress(),
inputAmount: toBN(random()),
outputAmount: toBN(random()),
message: "0x",
messageHash: UNDEFINED_MESSAGE_HASH,
depositId: toBN(random()),
quoteTimestamp: random(),
fillDeadline: random(),
exclusivityDeadline: random(),
exclusiveRelayer: randomAddress(),
fromLiteChain: false,
toLiteChain: false,
quoteBlockNumber: random(),
};
const blockFields = {
transactionHash: "",
blockNumber: 0,
transactionIndex: 0,
logIndex: 0,
};
const miscFill = {
relayer: randomAddress(),
repaymentChainId: random(),
relayExecutionInfo: {
updatedRecipient: eventData.recipient,
updatedMessage: eventData.message,
updatedOutputAmount: eventData.outputAmount,
fillType: random(),
},
};
const bundleData: Pick<BundleData, "bundleDepositsV3" | "bundleFillsV3"> = {
bundleDepositsV3: {
[originChainId]: {
[l1Token]: [
{
...eventData,
...blockFields,
message: "0x",
messageHash: UNDEFINED_MESSAGE_HASH,
},
{
...eventData,
...blockFields,
message: "0x1234",
messageHash: UNDEFINED_MESSAGE_HASH,
},
],
},
},
bundleFillsV3: {
[originChainId]: {
[l1Token]: {
fills: [
{
...eventData,
...blockFields,
...miscFill,
lpFeePct: toBN(random()),
},
{
...eventData,
...blockFields,
...miscFill,
lpFeePct: toBN(random()),
},
],
totalRefundAmount: toBN(random()),
realizedLpFees: toBN(random()),
refunds: {},
},
},
},
};
bundleDataClient.backfillMessageHashes(bundleData);
Object.values(bundleData.bundleDepositsV3[originChainId][l1Token]).forEach((deposit) => {
expect(deposit.message).to.exist;
expect(deposit.messageHash).to.not.equal(UNDEFINED_MESSAGE_HASH);
expect(deposit.messageHash).to.equal(getMessageHash(deposit.message));
});
});
});