-
Notifications
You must be signed in to change notification settings - Fork 27
/
testArbVerifier.ts
140 lines (120 loc) · 4.76 KB
/
testArbVerifier.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { Server } from '@chainlink/ccip-read-server';
import { makeArbGateway } from '@ensdomains/arb-gateway';
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';
import type { HardhatEthersHelpers } from '@nomicfoundation/hardhat-ethers/types';
import { expect } from 'chai';
import {
Contract,
FetchRequest,
Provider,
Signer,
ethers as ethersT
} from 'ethers';
import express from 'express';
import hre, { ethers } from 'hardhat';
import { EthereumProvider } from 'hardhat/types';
import request from 'supertest';
type ethersObj = typeof ethersT &
Omit<HardhatEthersHelpers, 'provider'> & {
provider: Omit<HardhatEthersProvider, '_hardhatProvider'> & {
_hardhatProvider: EthereumProvider;
};
};
declare module 'hardhat/types/runtime' {
const ethers: ethersObj;
interface HardhatRuntimeEnvironment {
ethers: ethersObj;
}
}
describe('ArbVerifier', () => {
let provider: Provider;
let signer: Signer;
let gateway: express.Application;
let target: Contract;
before(async () => {
// Hack to get a 'real' ethers provider from hardhat. The default `HardhatProvider`
// doesn't support CCIP-read.
provider = new ethers.BrowserProvider(hre.network.provider);
signer = await provider.getSigner(0);
//Rollup address according to sequencer config. Unfortunately, there is no endpoint to fetch it at runtime from the rollup.
//The address can be found at nitro-testnode-sequencer-1/config/deployment.json
const rollupAddress = '0xb264babb91df9d1ca05c8c2028288dc08c4bee46';
// When testing against Goerli, replace with this address
// const rollupAddress = '0x45e5cAea8768F42B385A366D3551Ad1e0cbFAb17';
const gateway = await makeArbGateway(
(hre.network.config as any).url,
(hre.config.networks[hre.network.companionNetworks.l2] as any).url,
rollupAddress,
5,
);
const server = new Server()
gateway.add(server)
const app = server.makeApp('/')
// Replace ethers' fetch function with one that calls the gateway directly.
const getUrl = FetchRequest.createGetUrlFunc();
ethers.FetchRequest.registerGetUrl(async (req: FetchRequest) => {
if (req.url != "test:") return getUrl(req);
const r = request(app).post('/');
if (req.hasBody()) {
r.set('Content-Type', 'application/json').send(
ethers.toUtf8String(req.body)
);
}
const response = await r;
return {
statusCode: response.statusCode,
statusMessage: response.ok ? 'OK' : response.statusCode.toString(),
body: ethers.toUtf8Bytes(JSON.stringify(response.body)),
headers: {
'Content-Type': 'application/json',
},
};
});
const targetDeployment = await hre.deployments.get('TestL1');
target = await ethers.getContractAt('TestL1', targetDeployment.address, signer);
})
it('simple proofs for fixed values', async () => {
const result = await target.getLatest({ enableCcipRead: true });
expect(Number(result)).to.equal(42);
});
it('simple proofs for dynamic values', async () => {
const result = await target.getName({ enableCcipRead: true });
expect(result).to.equal('Satoshi');
});
it('nested proofs for dynamic values', async () => {
const result = await target.getHighscorer(42, { enableCcipRead: true });
expect(result).to.equal('Hal Finney');
});
it('nested proofs for long dynamic values', async () => {
const result = await target.getHighscorer(1, { enableCcipRead: true });
expect(result).to.equal(
'Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Sr.'
);
});
it('nested proofs with lookbehind', async () => {
const result = await target.getLatestHighscore({ enableCcipRead: true });
expect(Number(result)).to.equal(12345);
});
it('nested proofs with lookbehind for dynamic values', async () => {
const result = await target.getLatestHighscorer({ enableCcipRead: true });
expect(result).to.equal('Hal Finney');
});
it('mappings with variable-length keys', async () => {
const result = await target.getNickname('Money Skeleton', {
enableCcipRead: true,
});
expect(result).to.equal('Vitalik Buterin');
});
it('nested proofs of mappings with variable-length keys', async () => {
const result = await target.getPrimaryNickname({ enableCcipRead: true });
expect(result).to.equal('Hal Finney');
});
it('treats uninitialized storage elements as zeroes', async () => {
const result = await target.getZero({ enableCcipRead: true });
expect(Number(result)).to.equal(0);
});
it('treats uninitialized dynamic values as empty strings', async () => {
const result = await target.getNickname('Santa', { enableCcipRead: true });
expect(result).to.equal("");
})
});