@boostxyz/sdk 0.0.0-alpha.13 → 0.0.0-alpha.14
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/Actions/EventAction.cjs +1 -1
- package/dist/Actions/EventAction.cjs.map +1 -1
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +54 -53
- package/dist/Actions/EventAction.js.map +1 -1
- package/package.json +3 -3
- package/src/Actions/EventAction.test.ts +81 -84
- package/src/Actions/EventAction.ts +3 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { selectors as eventSelectors } from
|
|
2
|
-
import { selectors as funcSelectors } from
|
|
3
|
-
import { loadFixture } from
|
|
1
|
+
import { selectors as eventSelectors } from "@boostxyz/signatures/events";
|
|
2
|
+
import { selectors as funcSelectors } from "@boostxyz/signatures/functions";
|
|
3
|
+
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
|
|
4
4
|
import {
|
|
5
5
|
type AbiEvent,
|
|
6
6
|
type Address,
|
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
pad,
|
|
12
12
|
parseEther,
|
|
13
13
|
toHex,
|
|
14
|
-
} from
|
|
15
|
-
import { beforeAll, beforeEach, describe, expect, test } from
|
|
16
|
-
import type { MockERC20 } from
|
|
17
|
-
import type { MockERC721 } from
|
|
18
|
-
import { accounts } from
|
|
14
|
+
} from "viem";
|
|
15
|
+
import { beforeAll, beforeEach, describe, expect, test } from "vitest";
|
|
16
|
+
import type { MockERC20 } from "../../test/MockERC20";
|
|
17
|
+
import type { MockERC721 } from "../../test/MockERC721";
|
|
18
|
+
import { accounts } from "../../test/accounts";
|
|
19
19
|
import {
|
|
20
20
|
type Fixtures,
|
|
21
21
|
type StringEmitterFixtures,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
fundErc20,
|
|
25
25
|
deployStringEmitterMock,
|
|
26
26
|
fundErc721,
|
|
27
|
-
} from
|
|
27
|
+
} from "../../test/helpers";
|
|
28
28
|
import {
|
|
29
29
|
EventAction,
|
|
30
30
|
type EventLogs,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
FilterType,
|
|
33
33
|
PrimitiveType,
|
|
34
34
|
SignatureType,
|
|
35
|
-
} from
|
|
35
|
+
} from "./EventAction";
|
|
36
36
|
|
|
37
37
|
let fixtures: Fixtures,
|
|
38
38
|
erc721: MockERC721,
|
|
@@ -51,7 +51,7 @@ function basicErc721TransferAction(
|
|
|
51
51
|
actionClaimant: {
|
|
52
52
|
signatureType: SignatureType.EVENT,
|
|
53
53
|
signature: eventSelectors[
|
|
54
|
-
|
|
54
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
55
55
|
] as Hex,
|
|
56
56
|
fieldIndex: 1,
|
|
57
57
|
targetContract: erc721.assertValidAddress(),
|
|
@@ -60,7 +60,7 @@ function basicErc721TransferAction(
|
|
|
60
60
|
actionSteps: [
|
|
61
61
|
{
|
|
62
62
|
signature: eventSelectors[
|
|
63
|
-
|
|
63
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
64
64
|
] as Hex,
|
|
65
65
|
signatureType: SignatureType.EVENT,
|
|
66
66
|
targetContract: erc721.assertValidAddress(),
|
|
@@ -88,17 +88,18 @@ function cloneEventAction(fixtures: Fixtures, erc721: MockERC721) {
|
|
|
88
88
|
function basicErc721MintFuncAction(
|
|
89
89
|
erc721: MockERC721,
|
|
90
90
|
): EventActionPayloadSimple {
|
|
91
|
+
console.log(funcSelectors["mint(address)"] as Hex);
|
|
91
92
|
return {
|
|
92
93
|
actionClaimant: {
|
|
93
94
|
signatureType: SignatureType.FUNC,
|
|
94
|
-
signature:
|
|
95
|
+
signature: funcSelectors["mint(address)"] as Hex,
|
|
95
96
|
fieldIndex: 0,
|
|
96
97
|
targetContract: erc721.assertValidAddress(),
|
|
97
98
|
chainid: defaultOptions.config.chains[0].id,
|
|
98
99
|
},
|
|
99
100
|
actionSteps: [
|
|
100
101
|
{
|
|
101
|
-
signature:
|
|
102
|
+
signature: funcSelectors["mint(address)"] as Hex,
|
|
102
103
|
signatureType: SignatureType.FUNC,
|
|
103
104
|
actionType: 0,
|
|
104
105
|
targetContract: erc721.assertValidAddress(),
|
|
@@ -118,16 +119,14 @@ function basicErc20MintFuncAction(erc20: MockERC20): EventActionPayloadSimple {
|
|
|
118
119
|
return {
|
|
119
120
|
actionClaimant: {
|
|
120
121
|
signatureType: SignatureType.FUNC,
|
|
121
|
-
signature:
|
|
122
|
+
signature: funcSelectors["mint(address to, uint256 amount)"] as Hex,
|
|
122
123
|
fieldIndex: 0,
|
|
123
124
|
targetContract: erc20.assertValidAddress(),
|
|
124
125
|
chainid: defaultOptions.config.chains[0].id,
|
|
125
126
|
},
|
|
126
127
|
actionSteps: [
|
|
127
128
|
{
|
|
128
|
-
signature:
|
|
129
|
-
funcSelectors['mint(address to, uint256 amount)'] as Hex,
|
|
130
|
-
),
|
|
129
|
+
signature: funcSelectors["mint(address to, uint256 amount)"] as Hex,
|
|
131
130
|
signatureType: SignatureType.FUNC,
|
|
132
131
|
actionType: 0,
|
|
133
132
|
targetContract: erc20.assertValidAddress(),
|
|
@@ -153,7 +152,7 @@ function indexedStringErc721TransferAction(
|
|
|
153
152
|
actionClaimant: {
|
|
154
153
|
signatureType: SignatureType.EVENT,
|
|
155
154
|
signature: eventSelectors[
|
|
156
|
-
|
|
155
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
157
156
|
] as Hex,
|
|
158
157
|
fieldIndex: 1,
|
|
159
158
|
targetContract: erc721.assertValidAddress(),
|
|
@@ -162,7 +161,7 @@ function indexedStringErc721TransferAction(
|
|
|
162
161
|
actionSteps: [
|
|
163
162
|
{
|
|
164
163
|
signature: eventSelectors[
|
|
165
|
-
|
|
164
|
+
"InfoIndexed(address indexed,string indexed)"
|
|
166
165
|
] as Hex,
|
|
167
166
|
signatureType: SignatureType.EVENT,
|
|
168
167
|
actionType: 0,
|
|
@@ -189,7 +188,7 @@ function stringErc721TransferAction(
|
|
|
189
188
|
actionClaimant: {
|
|
190
189
|
signatureType: SignatureType.EVENT,
|
|
191
190
|
signature: eventSelectors[
|
|
192
|
-
|
|
191
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
193
192
|
] as Hex,
|
|
194
193
|
fieldIndex: 1,
|
|
195
194
|
targetContract: erc721.assertValidAddress(),
|
|
@@ -197,7 +196,7 @@ function stringErc721TransferAction(
|
|
|
197
196
|
},
|
|
198
197
|
actionSteps: [
|
|
199
198
|
{
|
|
200
|
-
signature: eventSelectors[
|
|
199
|
+
signature: eventSelectors["Info(address,string)"] as Hex,
|
|
201
200
|
signatureType: SignatureType.EVENT,
|
|
202
201
|
actionType: 0,
|
|
203
202
|
targetContract: stringEmitterAddress,
|
|
@@ -249,13 +248,13 @@ function cloneStringEventAction(
|
|
|
249
248
|
};
|
|
250
249
|
}
|
|
251
250
|
|
|
252
|
-
describe(
|
|
251
|
+
describe("EventAction Event Selector", () => {
|
|
253
252
|
beforeEach(async () => {
|
|
254
253
|
erc721 = await loadFixture(fundErc721(defaultOptions));
|
|
255
254
|
});
|
|
256
255
|
|
|
257
|
-
describe(
|
|
258
|
-
test(
|
|
256
|
+
describe("basic transfer event", () => {
|
|
257
|
+
test("can successfully be deployed", async () => {
|
|
259
258
|
const action = new EventAction(
|
|
260
259
|
defaultOptions,
|
|
261
260
|
basicErc721TransferAction(erc721),
|
|
@@ -264,17 +263,17 @@ describe('EventAction Event Selector', () => {
|
|
|
264
263
|
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
265
264
|
});
|
|
266
265
|
|
|
267
|
-
test(
|
|
266
|
+
test("can get an action step", async () => {
|
|
268
267
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
269
268
|
const step = await action.getActionStep(0);
|
|
270
269
|
if (!step)
|
|
271
|
-
throw new Error(
|
|
270
|
+
throw new Error("there should be an action step at this index");
|
|
272
271
|
step.targetContract = step.targetContract.toUpperCase() as Hex;
|
|
273
272
|
step.actionParameter.filterData =
|
|
274
273
|
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
275
274
|
expect(step).toMatchObject({
|
|
276
275
|
signature: eventSelectors[
|
|
277
|
-
|
|
276
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
278
277
|
] as Hex,
|
|
279
278
|
signatureType: SignatureType.EVENT,
|
|
280
279
|
actionType: 0,
|
|
@@ -288,7 +287,7 @@ describe('EventAction Event Selector', () => {
|
|
|
288
287
|
});
|
|
289
288
|
});
|
|
290
289
|
|
|
291
|
-
test(
|
|
290
|
+
test("can get all action steps", async () => {
|
|
292
291
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
293
292
|
const steps = await action.getActionSteps();
|
|
294
293
|
expect(steps.length).toBe(1);
|
|
@@ -298,7 +297,7 @@ describe('EventAction Event Selector', () => {
|
|
|
298
297
|
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
299
298
|
expect(step).toMatchObject({
|
|
300
299
|
signature: eventSelectors[
|
|
301
|
-
|
|
300
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
302
301
|
] as Hex,
|
|
303
302
|
signatureType: SignatureType.EVENT,
|
|
304
303
|
actionType: 0,
|
|
@@ -312,26 +311,26 @@ describe('EventAction Event Selector', () => {
|
|
|
312
311
|
});
|
|
313
312
|
});
|
|
314
313
|
|
|
315
|
-
test(
|
|
314
|
+
test("can get the total number of action steps", async () => {
|
|
316
315
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
317
316
|
const count = await action.getActionStepsCount();
|
|
318
317
|
expect(count).toBe(1);
|
|
319
318
|
});
|
|
320
319
|
|
|
321
|
-
test(
|
|
320
|
+
test("can get the action claimant", async () => {
|
|
322
321
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
323
322
|
const claimant = await action.getActionClaimant();
|
|
324
323
|
claimant.targetContract = claimant.targetContract.toUpperCase() as Hex;
|
|
325
324
|
expect(claimant).toMatchObject({
|
|
326
325
|
signatureType: SignatureType.EVENT,
|
|
327
326
|
signature: eventSelectors[
|
|
328
|
-
|
|
327
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
329
328
|
] as Hex,
|
|
330
329
|
fieldIndex: 1,
|
|
331
330
|
});
|
|
332
331
|
});
|
|
333
332
|
|
|
334
|
-
test(
|
|
333
|
+
test("can get all action steps", async () => {
|
|
335
334
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
336
335
|
const steps = await action.getActionSteps();
|
|
337
336
|
expect(steps.length).toBe(1);
|
|
@@ -341,7 +340,7 @@ describe('EventAction Event Selector', () => {
|
|
|
341
340
|
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
342
341
|
expect(step).toMatchObject({
|
|
343
342
|
signature: eventSelectors[
|
|
344
|
-
|
|
343
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
345
344
|
] as Hex,
|
|
346
345
|
signatureType: SignatureType.EVENT,
|
|
347
346
|
actionType: 0,
|
|
@@ -355,32 +354,32 @@ describe('EventAction Event Selector', () => {
|
|
|
355
354
|
});
|
|
356
355
|
});
|
|
357
356
|
|
|
358
|
-
test(
|
|
357
|
+
test("can get the total number of action steps", async () => {
|
|
359
358
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
360
359
|
const count = await action.getActionStepsCount();
|
|
361
360
|
expect(count).toBe(1);
|
|
362
361
|
});
|
|
363
362
|
|
|
364
|
-
test(
|
|
363
|
+
test("can get the action claimant", async () => {
|
|
365
364
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
366
365
|
const claimant = await action.getActionClaimant();
|
|
367
366
|
claimant.targetContract = claimant.targetContract.toUpperCase() as Hex;
|
|
368
367
|
expect(claimant).toMatchObject({
|
|
369
368
|
signatureType: SignatureType.EVENT,
|
|
370
369
|
signature: eventSelectors[
|
|
371
|
-
|
|
370
|
+
"Transfer(address indexed,address indexed,uint256 indexed)"
|
|
372
371
|
] as Hex,
|
|
373
372
|
fieldIndex: 1,
|
|
374
373
|
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
375
374
|
});
|
|
376
375
|
});
|
|
377
376
|
|
|
378
|
-
test(
|
|
377
|
+
test("with no logs, does not validate", async () => {
|
|
379
378
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
380
379
|
expect(await action.validateActionSteps()).toBe(false);
|
|
381
380
|
});
|
|
382
381
|
|
|
383
|
-
test(
|
|
382
|
+
test("with a correct log, validates", async () => {
|
|
384
383
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
385
384
|
const recipient = accounts[1].account;
|
|
386
385
|
await erc721.approve(recipient, 1n);
|
|
@@ -388,100 +387,98 @@ describe('EventAction Event Selector', () => {
|
|
|
388
387
|
expect(await action.validateActionSteps()).toBe(true);
|
|
389
388
|
});
|
|
390
389
|
|
|
391
|
-
test(
|
|
390
|
+
test("can supply your own logs to validate against", async () => {
|
|
392
391
|
const logs: EventLogs = [
|
|
393
392
|
{
|
|
394
|
-
eventName:
|
|
393
|
+
eventName: "Transfer",
|
|
395
394
|
args: [
|
|
396
|
-
|
|
397
|
-
|
|
395
|
+
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
396
|
+
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
|
|
398
397
|
1n,
|
|
399
398
|
],
|
|
400
399
|
address: erc721.assertValidAddress(),
|
|
401
400
|
blockHash:
|
|
402
|
-
|
|
401
|
+
"0xbf602f988260519805d032be46d6ff97fbefbee6924b21097074d6d0bc34eced",
|
|
403
402
|
blockNumber: 1203n,
|
|
404
|
-
data:
|
|
403
|
+
data: "0x",
|
|
405
404
|
logIndex: 0,
|
|
406
405
|
removed: false,
|
|
407
406
|
topics: [
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
407
|
+
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
408
|
+
"0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
409
|
+
"0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8",
|
|
410
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
412
411
|
],
|
|
413
412
|
transactionHash:
|
|
414
|
-
|
|
413
|
+
"0xff0e6ab0c4961ec14b7b40afec83ed7d7a77582683512a262e641d21f82efea5",
|
|
415
414
|
transactionIndex: 0,
|
|
416
415
|
},
|
|
417
416
|
];
|
|
418
417
|
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
419
|
-
expect(
|
|
420
|
-
await action.validateActionSteps({ logs }),
|
|
421
|
-
).toBe(true);
|
|
418
|
+
expect(await action.validateActionSteps({ logs })).toBe(true);
|
|
422
419
|
});
|
|
423
420
|
|
|
424
|
-
describe(
|
|
425
|
-
test(
|
|
421
|
+
describe("string event actions", () => {
|
|
422
|
+
test("cannot parse and validate contains for an emitted string event with an indexed param", async () => {
|
|
426
423
|
const action = await loadFixture(
|
|
427
424
|
cloneStringEventAction(
|
|
428
425
|
fixtures,
|
|
429
426
|
indexedStringErc721TransferAction(
|
|
430
427
|
FilterType.CONTAINS,
|
|
431
|
-
toHex(
|
|
428
|
+
toHex("ello"),
|
|
432
429
|
stringEmitterFixtures.address,
|
|
433
430
|
erc721,
|
|
434
431
|
),
|
|
435
432
|
),
|
|
436
433
|
);
|
|
437
434
|
|
|
438
|
-
await stringEmitterFixtures.emitIndexedString(
|
|
435
|
+
await stringEmitterFixtures.emitIndexedString("Hello world");
|
|
439
436
|
await expect(() => action.validateActionSteps()).rejects.toThrowError(
|
|
440
437
|
/Parameter is not transparently stored onchain/,
|
|
441
438
|
);
|
|
442
439
|
});
|
|
443
|
-
test(
|
|
440
|
+
test("can parse and validate contains for an emitted string event", async () => {
|
|
444
441
|
const action = await loadFixture(
|
|
445
442
|
cloneStringEventAction(
|
|
446
443
|
fixtures,
|
|
447
444
|
stringErc721TransferAction(
|
|
448
445
|
FilterType.CONTAINS,
|
|
449
|
-
toHex(
|
|
446
|
+
toHex("ello"),
|
|
450
447
|
stringEmitterFixtures.address,
|
|
451
448
|
erc721,
|
|
452
449
|
),
|
|
453
450
|
),
|
|
454
451
|
);
|
|
455
|
-
await stringEmitterFixtures.emitString(
|
|
452
|
+
await stringEmitterFixtures.emitString("Hello world");
|
|
456
453
|
expect(await action.validateActionSteps()).toBe(true);
|
|
457
454
|
});
|
|
458
|
-
test(
|
|
455
|
+
test("can parse and validate regex for an emitted string event", async () => {
|
|
459
456
|
const action = await loadFixture(
|
|
460
457
|
cloneStringEventAction(
|
|
461
458
|
fixtures,
|
|
462
459
|
stringErc721TransferAction(
|
|
463
460
|
FilterType.REGEX,
|
|
464
|
-
toHex(
|
|
461
|
+
toHex("[hH]ello"),
|
|
465
462
|
stringEmitterFixtures.address,
|
|
466
463
|
erc721,
|
|
467
464
|
),
|
|
468
465
|
),
|
|
469
466
|
);
|
|
470
467
|
|
|
471
|
-
await stringEmitterFixtures.emitString(
|
|
468
|
+
await stringEmitterFixtures.emitString("Hello world");
|
|
472
469
|
expect(await action.validateActionSteps()).toBe(true);
|
|
473
470
|
});
|
|
474
471
|
});
|
|
475
472
|
});
|
|
476
473
|
});
|
|
477
474
|
|
|
478
|
-
describe(
|
|
475
|
+
describe("EventAction Func Selector", () => {
|
|
479
476
|
beforeEach(async () => {
|
|
480
477
|
erc721 = await loadFixture(fundErc721(defaultOptions));
|
|
481
478
|
erc20 = await loadFixture(fundErc20(defaultOptions));
|
|
482
479
|
});
|
|
483
480
|
|
|
484
|
-
test(
|
|
481
|
+
test("can be deployed successfully", async () => {
|
|
485
482
|
const action = new EventAction(
|
|
486
483
|
defaultOptions,
|
|
487
484
|
basicErc721MintFuncAction(erc721),
|
|
@@ -490,12 +487,12 @@ describe('EventAction Func Selector', () => {
|
|
|
490
487
|
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
491
488
|
});
|
|
492
489
|
|
|
493
|
-
test(
|
|
490
|
+
test("validates function action step with correct hash", async () => {
|
|
494
491
|
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
495
492
|
const actionSteps = await action.getActionSteps();
|
|
496
493
|
const recipient = accounts[1].account;
|
|
497
494
|
const { hash } = await erc721.mintRaw(recipient, {
|
|
498
|
-
value: parseEther(
|
|
495
|
+
value: parseEther(".1"),
|
|
499
496
|
});
|
|
500
497
|
|
|
501
498
|
expect(
|
|
@@ -505,7 +502,7 @@ describe('EventAction Func Selector', () => {
|
|
|
505
502
|
).toBe(true);
|
|
506
503
|
});
|
|
507
504
|
|
|
508
|
-
test(
|
|
505
|
+
test("throws an error when hash is missing", async () => {
|
|
509
506
|
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
510
507
|
const actionSteps = await action.getActionSteps();
|
|
511
508
|
try {
|
|
@@ -513,18 +510,18 @@ describe('EventAction Func Selector', () => {
|
|
|
513
510
|
} catch (e) {
|
|
514
511
|
expect(e).toBeInstanceOf(Error);
|
|
515
512
|
expect((e as Error).message).toBe(
|
|
516
|
-
|
|
513
|
+
"Hash is required for function validation",
|
|
517
514
|
);
|
|
518
515
|
}
|
|
519
516
|
});
|
|
520
517
|
|
|
521
|
-
test(
|
|
518
|
+
test("validates function step with EQUAL filter", async () => {
|
|
522
519
|
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
523
520
|
const actionSteps = await action.getActionSteps();
|
|
524
521
|
|
|
525
522
|
const recipient = accounts[1].account;
|
|
526
523
|
const { hash } = await erc721.mintRaw(recipient, {
|
|
527
|
-
value: parseEther(
|
|
524
|
+
value: parseEther(".1"),
|
|
528
525
|
});
|
|
529
526
|
|
|
530
527
|
const criteriaMatch = await action.isActionFunctionValid(actionSteps[0], {
|
|
@@ -534,18 +531,18 @@ describe('EventAction Func Selector', () => {
|
|
|
534
531
|
expect(criteriaMatch).toBe(true);
|
|
535
532
|
});
|
|
536
533
|
|
|
537
|
-
test(
|
|
534
|
+
test("fails validation with incorrect function signature", async () => {
|
|
538
535
|
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
539
536
|
const actionSteps = await action.getActionSteps();
|
|
540
537
|
const recipient = accounts[1].account;
|
|
541
538
|
|
|
542
539
|
const invalidStep = {
|
|
543
540
|
...actionSteps[0],
|
|
544
|
-
signature:
|
|
541
|
+
signature: funcSelectors["mint(address to, uint256 amount)"] as Hex, // Intentional mismatch
|
|
545
542
|
};
|
|
546
543
|
|
|
547
544
|
const { hash } = await erc721.mintRaw(recipient, {
|
|
548
|
-
value: parseEther(
|
|
545
|
+
value: parseEther(".1"),
|
|
549
546
|
});
|
|
550
547
|
|
|
551
548
|
try {
|
|
@@ -558,13 +555,13 @@ describe('EventAction Func Selector', () => {
|
|
|
558
555
|
}
|
|
559
556
|
});
|
|
560
557
|
|
|
561
|
-
test(
|
|
558
|
+
test("validates against NOT_EQUAL filter criteria", async () => {
|
|
562
559
|
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
563
560
|
const actionSteps = await action.getActionSteps();
|
|
564
561
|
actionSteps[0].actionParameter.filterType = FilterType.NOT_EQUAL;
|
|
565
562
|
const recipient = accounts[2].account;
|
|
566
563
|
const { hash } = await erc721.mintRaw(recipient, {
|
|
567
|
-
value: parseEther(
|
|
564
|
+
value: parseEther(".1"),
|
|
568
565
|
});
|
|
569
566
|
|
|
570
567
|
expect(
|
|
@@ -574,7 +571,7 @@ describe('EventAction Func Selector', () => {
|
|
|
574
571
|
).toBe(true);
|
|
575
572
|
});
|
|
576
573
|
|
|
577
|
-
test(
|
|
574
|
+
test("validates GREATER_THAN criteria for numeric values", async () => {
|
|
578
575
|
const action = await loadFixture(cloneFunctionAction20(fixtures, erc20));
|
|
579
576
|
const actionSteps = await action.getActionSteps();
|
|
580
577
|
|
|
@@ -582,7 +579,7 @@ describe('EventAction Func Selector', () => {
|
|
|
582
579
|
filterType: FilterType.GREATER_THAN,
|
|
583
580
|
fieldType: PrimitiveType.UINT,
|
|
584
581
|
fieldIndex: 1,
|
|
585
|
-
filterData: toHex(
|
|
582
|
+
filterData: toHex("1"),
|
|
586
583
|
};
|
|
587
584
|
|
|
588
585
|
const address = accounts[1].account;
|
|
@@ -596,14 +593,14 @@ describe('EventAction Func Selector', () => {
|
|
|
596
593
|
).toBe(true);
|
|
597
594
|
});
|
|
598
595
|
|
|
599
|
-
test(
|
|
596
|
+
test("validates LESS_THAN criteria for numeric values", async () => {
|
|
600
597
|
const action = await loadFixture(cloneFunctionAction20(fixtures, erc20));
|
|
601
598
|
const actionSteps = await action.getActionSteps();
|
|
602
599
|
actionSteps[0].actionParameter = {
|
|
603
600
|
filterType: FilterType.LESS_THAN,
|
|
604
601
|
fieldType: PrimitiveType.UINT,
|
|
605
602
|
fieldIndex: 1,
|
|
606
|
-
filterData: toHex(
|
|
603
|
+
filterData: toHex("5"),
|
|
607
604
|
};
|
|
608
605
|
|
|
609
606
|
const address = accounts[1].account;
|
|
@@ -617,16 +614,16 @@ describe('EventAction Func Selector', () => {
|
|
|
617
614
|
).toBe(true);
|
|
618
615
|
});
|
|
619
616
|
|
|
620
|
-
test(
|
|
617
|
+
test("validates entire flow of function action", async () => {
|
|
621
618
|
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
622
619
|
const recipient = accounts[1].account;
|
|
623
620
|
const { hash } = await erc721.mintRaw(recipient, {
|
|
624
|
-
value: parseEther(
|
|
621
|
+
value: parseEther(".1"),
|
|
625
622
|
});
|
|
626
623
|
|
|
627
624
|
expect(
|
|
628
625
|
await action.validateActionSteps({
|
|
629
|
-
hash
|
|
626
|
+
hash,
|
|
630
627
|
}),
|
|
631
628
|
).toBe(true);
|
|
632
629
|
});
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
encodeAbiParameters,
|
|
25
25
|
fromHex,
|
|
26
26
|
isAddressEqual,
|
|
27
|
+
pad,
|
|
27
28
|
trim,
|
|
28
29
|
} from 'viem';
|
|
29
30
|
import { getLogs } from 'viem/actions';
|
|
@@ -615,7 +616,8 @@ export class EventAction extends DeployableTarget<
|
|
|
615
616
|
params?: ValidateFunctionStepParams & { chainId?: number },
|
|
616
617
|
) {
|
|
617
618
|
const criteria = actionStep.actionParameter;
|
|
618
|
-
|
|
619
|
+
let signature = actionStep.signature;
|
|
620
|
+
|
|
619
621
|
if (!params || !params?.hash) {
|
|
620
622
|
// Should we return false in this case?
|
|
621
623
|
throw new Error('Hash is required for function validation');
|