-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhandler.test.ts
75 lines (68 loc) · 2.51 KB
/
handler.test.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
import { Callback, Context, ScheduledEvent } from 'aws-lambda';
import { ethers } from 'ethers';
import { MerkleFunder__factory } from './contracts';
import { run } from './handler';
import { fundChainRecipients } from './merkle-funder';
jest.mock('./merkle-funder', () => ({
fundChainRecipients: jest.fn(),
}));
jest.mock('../deployments/references.json', () => ({
MerkleFunder: {
'31337': '0x04d2B3DdCdb2790571Ca01F4768e3cC98FCb0D2B',
},
}));
const mockConfig = {
31337: {
funderMnemonic: 'test test test test test test test test test test test junk',
providers: {
provider1: {
url: 'http://provider1.com',
},
provider2: {
url: 'http://provider2.com',
},
},
},
};
jest.mock('./config', () => ({
loadConfig: jest.fn(() => mockConfig),
}));
describe('run', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should call fundChainRecipients for each provider in the config', async () => {
const merkleFunderContractAddress = '0x04d2B3DdCdb2790571Ca01F4768e3cC98FCb0D2B';
const signerAddress = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
await run(null as unknown as ScheduledEvent, null as unknown as Context, null as unknown as Callback<void>);
expect(fundChainRecipients).toHaveBeenCalledTimes(2);
expect(fundChainRecipients).toHaveBeenNthCalledWith(
1,
'31337',
expect.anything(),
expect.objectContaining({
address: merkleFunderContractAddress,
signer: expect.objectContaining({
address: signerAddress,
provider: expect.objectContaining({ connection: expect.objectContaining({ url: 'http://provider1.com' }) }),
}),
interface: expect.objectContaining(new ethers.utils.Interface(MerkleFunder__factory.abi)),
}),
expect.objectContaining({ format: 'plain', level: 'INFO', meta: { 'CHAIN-ID': '31337', PROVIDER: 'provider1' } })
);
expect(fundChainRecipients).toHaveBeenNthCalledWith(
2,
'31337',
expect.anything(),
expect.objectContaining({
address: merkleFunderContractAddress,
signer: expect.objectContaining({
address: signerAddress,
provider: expect.objectContaining({ connection: expect.objectContaining({ url: 'http://provider2.com' }) }),
}),
interface: expect.objectContaining(new ethers.utils.Interface(MerkleFunder__factory.abi)),
}),
expect.objectContaining({ format: 'plain', level: 'INFO', meta: { 'CHAIN-ID': '31337', PROVIDER: 'provider2' } })
);
});
});