-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathargsEqualityCheckBuilder.test.ts
More file actions
72 lines (55 loc) · 1.99 KB
/
Copy pathargsEqualityCheckBuilder.test.ts
File metadata and controls
72 lines (55 loc) · 1.99 KB
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
import { size, type Hex } from 'viem';
import { expect, describe, it } from 'vitest';
import { argsEqualityCheckBuilder } from '../../src/caveatBuilder/argsEqualityCheckBuilder';
import type { DeleGatorEnvironment } from '../../src/types';
import { randomBytes, randomAddress } from '../utils';
describe('argsEqualityCheckBuilder()', () => {
const environment = {
caveatEnforcers: { ArgsEqualityCheckEnforcer: randomAddress() },
} as any as DeleGatorEnvironment;
const buildWithArgs = (args: Hex) => {
return argsEqualityCheckBuilder(environment, args);
};
describe('validation', () => {
it('should fail when args is not hex', () => {
expect(() => buildWithArgs('not-hex' as Hex)).to.throw(
'Invalid args: must be a valid hex string',
);
});
it('should fail when args is not defined', () => {
expect(() => buildWithArgs(undefined as any as Hex)).to.throw(
'Invalid args: must be a valid hex string',
);
expect(() => buildWithArgs(null as any as Hex)).to.throw(
'Invalid args: must be a valid hex string',
);
});
});
describe('builds a caveat', () => {
it('should build a caveat with valid args', () => {
const args = randomBytes(128);
const caveat = buildWithArgs(args);
const terms = args;
expect(caveat).to.deep.equal({
enforcer: environment.caveatEnforcers.ArgsEqualityCheckEnforcer,
terms,
args: '0x',
});
});
it('should build a caveat with zero-length args', () => {
const args = '0x';
const caveat = buildWithArgs(args);
const terms = args;
expect(caveat).to.deep.equal({
enforcer: environment.caveatEnforcers.ArgsEqualityCheckEnforcer,
terms,
args: '0x',
});
});
});
it('should create a caveat with terms length matching number of targets', () => {
const args = randomBytes(128);
const caveat = buildWithArgs(args);
expect(size(caveat.terms)).to.equal(size(args));
});
});