-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy patherc20StreamingBuilder.test.ts
More file actions
100 lines (87 loc) · 3.26 KB
/
Copy patherc20StreamingBuilder.test.ts
File metadata and controls
100 lines (87 loc) · 3.26 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
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
import type { Address } from 'viem';
import { size } from 'viem';
import { expect, describe, it } from 'vitest';
import { erc20StreamingBuilder } from '../../src/caveatBuilder/erc20StreamingBuilder';
import { TIMESTAMP_UPPER_BOUND_SECONDS } from '../../src/caveatBuilder/shared';
import type { DeleGatorEnvironment } from '../../src/types';
import { randomAddress } from '../utils';
describe('erc20StreamingBuilder()', () => {
const EXPECTED_TERMS_LENGTH = 148; // 148 bytes for the allowance
const environment = {
caveatEnforcers: { ERC20StreamingEnforcer: randomAddress() },
} as any as DeleGatorEnvironment;
const buildWithParams = (
tokenAddress: Address,
initialAmount: bigint,
maxAmount: bigint,
amountPerSecond: bigint,
startTime: number,
) => {
return erc20StreamingBuilder(
environment,
tokenAddress,
initialAmount,
maxAmount,
amountPerSecond,
startTime,
);
};
describe('validation', () => {
it('should fail with an invalid token address', () => {
const invalidAddress = 'invalid-address' as Address;
expect(() =>
buildWithParams(invalidAddress, 1000n, 1000n, 1n, 1),
).to.throw('Invalid tokenAddress: must be a valid address');
});
it('should fail with a non-positive initial amount', () => {
const validAddress = randomAddress();
expect(() => buildWithParams(validAddress, -1n, 1000n, 1n, 1)).to.throw(
'Invalid initialAmount: must be greater than zero',
);
});
it('should fail with a non-positive max amount', () => {
const validAddress = randomAddress();
expect(() => buildWithParams(validAddress, 1000n, 0n, 1n, 1)).to.throw(
'Invalid maxAmount: must be a positive number',
);
expect(() => buildWithParams(validAddress, 1000n, -1n, 1n, 1)).to.throw(
'Invalid maxAmount: must be a positive number',
);
});
it('should fail with a non-positive amount per second', () => {
const validAddress = randomAddress();
expect(() => buildWithParams(validAddress, 1000n, 1000n, 0n, 1)).to.throw(
'Invalid amountPerSecond: must be a positive number',
);
expect(() =>
buildWithParams(validAddress, 1000n, 1000n, -1n, 1),
).to.throw('Invalid amountPerSecond: must be a positive number');
});
it('should fail with a non-positive start time', () => {
const validAddress = randomAddress();
expect(() => buildWithParams(validAddress, 1000n, 1000n, 1n, 0)).to.throw(
'Invalid startTime: must be a positive number',
);
expect(() =>
buildWithParams(validAddress, 1000n, 1000n, 1n, -1),
).to.throw('Invalid startTime: must be a positive number');
});
it('should fail when start time is greater than the upper bound', () => {
expect(() =>
buildWithParams(
randomAddress(),
1000n,
1000n,
1n,
TIMESTAMP_UPPER_BOUND_SECONDS + 1,
),
).to.throw(
'Invalid startTime: must be less than or equal to 253402300799',
);
});
it('should build terms of the correct length', () => {
const { terms } = buildWithParams(randomAddress(), 1000n, 1000n, 1n, 1);
expect(size(terms)).to.equal(EXPECTED_TERMS_LENGTH);
});
});
});