@apibara/evm 2.1.0-beta.22 → 2.1.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +403 -476
- package/dist/index.d.cts +1073 -2035
- package/dist/index.d.mts +1073 -2035
- package/dist/index.d.ts +1073 -2035
- package/dist/index.mjs +405 -467
- package/package.json +2 -4
- package/src/block.ts +312 -307
- package/src/common.ts +64 -101
- package/src/filter.ts +128 -138
- package/src/proto/data.ts +26 -1
- package/src/common.test.ts +0 -79
- package/src/filter.test.ts +0 -187
- package/src/helpers.ts +0 -8
package/src/filter.test.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { encodeEventTopics, pad, parseAbi } from "viem";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { Schema } from "@effect/schema";
|
|
5
|
-
import {
|
|
6
|
-
Filter,
|
|
7
|
-
LogFilter,
|
|
8
|
-
filterFromProto,
|
|
9
|
-
filterToProto,
|
|
10
|
-
mergeFilter,
|
|
11
|
-
} from "./filter";
|
|
12
|
-
|
|
13
|
-
const abi = parseAbi([
|
|
14
|
-
"event Transfer(address indexed from, address indexed to, uint256 value)",
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
describe("Filter", () => {
|
|
18
|
-
it("all filters are optional", () => {
|
|
19
|
-
const filter = Filter.make({});
|
|
20
|
-
|
|
21
|
-
const proto = filterToProto(filter);
|
|
22
|
-
const back = filterFromProto(proto);
|
|
23
|
-
expect(back).toEqual(filter);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("accepts logs filter", () => {
|
|
27
|
-
const filter = Filter.make({
|
|
28
|
-
logs: [
|
|
29
|
-
{
|
|
30
|
-
address: "0x123456789012",
|
|
31
|
-
strict: true,
|
|
32
|
-
topics: encodeEventTopics({
|
|
33
|
-
abi,
|
|
34
|
-
eventName: "Transfer",
|
|
35
|
-
args: { from: null, to: null },
|
|
36
|
-
}) as `0x${string}`[],
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(filter.logs).toHaveLength(1);
|
|
42
|
-
|
|
43
|
-
const proto = filterToProto(filter);
|
|
44
|
-
const back = filterFromProto(proto);
|
|
45
|
-
|
|
46
|
-
expect(back).toBeDefined();
|
|
47
|
-
expect(back.logs).toHaveLength(1);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe("LogFilter", () => {
|
|
52
|
-
const encode = Schema.encodeSync(LogFilter);
|
|
53
|
-
const decode = Schema.decodeSync(LogFilter);
|
|
54
|
-
|
|
55
|
-
it("can be empty", () => {
|
|
56
|
-
const filter = LogFilter.make({});
|
|
57
|
-
|
|
58
|
-
const proto = encode(filter);
|
|
59
|
-
const back = decode(proto);
|
|
60
|
-
expect(back).toEqual(filter);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("can have null topics", () => {
|
|
64
|
-
const filter = LogFilter.make({
|
|
65
|
-
topics: [null, pad("0x1"), null, pad("0x3")],
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const proto = encode(filter);
|
|
69
|
-
const back = decode(proto);
|
|
70
|
-
expect(back).toEqual(filter);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("can have all optional fields", () => {
|
|
74
|
-
const filter = LogFilter.make({
|
|
75
|
-
address: pad("0xa", { size: 20 }),
|
|
76
|
-
topics: [null, pad("0x1"), null, pad("0x3")],
|
|
77
|
-
includeTransaction: true,
|
|
78
|
-
includeReceipt: true,
|
|
79
|
-
strict: true,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const proto = encode(filter);
|
|
83
|
-
const back = decode(proto);
|
|
84
|
-
expect(back).toEqual(filter);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe("mergeFilter", () => {
|
|
89
|
-
it("returns header.always if any has it", () => {
|
|
90
|
-
const fa = mergeFilter({}, { header: "always" });
|
|
91
|
-
expect(fa).toMatchInlineSnapshot(`
|
|
92
|
-
{
|
|
93
|
-
"header": "always",
|
|
94
|
-
"logs": [],
|
|
95
|
-
"transactions": [],
|
|
96
|
-
"withdrawals": [],
|
|
97
|
-
}
|
|
98
|
-
`);
|
|
99
|
-
const fb = mergeFilter({ header: "always" }, {});
|
|
100
|
-
expect(fb).toMatchInlineSnapshot(`
|
|
101
|
-
{
|
|
102
|
-
"header": "always",
|
|
103
|
-
"logs": [],
|
|
104
|
-
"transactions": [],
|
|
105
|
-
"withdrawals": [],
|
|
106
|
-
}
|
|
107
|
-
`);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("returns an empty header by default", () => {
|
|
111
|
-
const f = mergeFilter({}, {});
|
|
112
|
-
expect(f).toMatchInlineSnapshot(`
|
|
113
|
-
{
|
|
114
|
-
"header": undefined,
|
|
115
|
-
"logs": [],
|
|
116
|
-
"transactions": [],
|
|
117
|
-
"withdrawals": [],
|
|
118
|
-
}
|
|
119
|
-
`);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("concatenates logs", () => {
|
|
123
|
-
const f = mergeFilter(
|
|
124
|
-
{ logs: [{ address: "0xAAAAAAAAAAAAAAAAAAAAAA" }] },
|
|
125
|
-
{ logs: [{ address: "0xBBBBBBBBBBBBBBBBBBBBBB" }] },
|
|
126
|
-
);
|
|
127
|
-
expect(f).toMatchInlineSnapshot(`
|
|
128
|
-
{
|
|
129
|
-
"header": undefined,
|
|
130
|
-
"logs": [
|
|
131
|
-
{
|
|
132
|
-
"address": "0xAAAAAAAAAAAAAAAAAAAAAA",
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
"address": "0xBBBBBBBBBBBBBBBBBBBBBB",
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
"transactions": [],
|
|
139
|
-
"withdrawals": [],
|
|
140
|
-
}
|
|
141
|
-
`);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("concatenates transactions", () => {
|
|
145
|
-
const f = mergeFilter(
|
|
146
|
-
{ transactions: [{ from: "0xAAAAAAAAAAAAAAAAAAAAAA" }] },
|
|
147
|
-
{ transactions: [{ from: "0xBBBBBBBBBBBBBBBBBBBBBB" }] },
|
|
148
|
-
);
|
|
149
|
-
expect(f).toMatchInlineSnapshot(`
|
|
150
|
-
{
|
|
151
|
-
"header": undefined,
|
|
152
|
-
"logs": [],
|
|
153
|
-
"transactions": [
|
|
154
|
-
{
|
|
155
|
-
"from": "0xAAAAAAAAAAAAAAAAAAAAAA",
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
"from": "0xBBBBBBBBBBBBBBBBBBBBBB",
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
"withdrawals": [],
|
|
162
|
-
}
|
|
163
|
-
`);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("concatenates withdrawals", () => {
|
|
167
|
-
const f = mergeFilter(
|
|
168
|
-
{ withdrawals: [{ validatorIndex: 1 }] },
|
|
169
|
-
{ withdrawals: [{ validatorIndex: 100 }] },
|
|
170
|
-
);
|
|
171
|
-
expect(f).toMatchInlineSnapshot(`
|
|
172
|
-
{
|
|
173
|
-
"header": undefined,
|
|
174
|
-
"logs": [],
|
|
175
|
-
"transactions": [],
|
|
176
|
-
"withdrawals": [
|
|
177
|
-
{
|
|
178
|
-
"validatorIndex": 1,
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
"validatorIndex": 100,
|
|
182
|
-
},
|
|
183
|
-
],
|
|
184
|
-
}
|
|
185
|
-
`);
|
|
186
|
-
});
|
|
187
|
-
});
|