Skip to content

Commit 6ba2aae

Browse files
committed
Revert "fix: ci test"
This reverts commit 275b690.
1 parent 275b690 commit 6ba2aae

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { expect } from 'chai';
2+
import sinon from 'sinon';
3+
import { Config } from '@oclif/core';
4+
import { JsonRpcProvider, Contract } from 'ethers';
5+
import * as configParser from '../../../src/utils/config-parser.js';
6+
import TestContracts from '../../../src/commands/test/contracts.js';
7+
8+
const mockConfig: Config = {
9+
// Add minimum required properties
10+
root: '/mock/root',
11+
name: 'mock-cli',
12+
version: '1.0.0',
13+
// Add other required properties as needed
14+
} as Config;
15+
16+
describe('TestContracts', () => {
17+
let parseTomlConfigStub: sinon.SinonStub;
18+
let providerStub: sinon.SinonStubbedInstance<JsonRpcProvider>;
19+
let contractStub: sinon.SinonStubbedInstance<Contract>;
20+
21+
beforeEach(() => {
22+
parseTomlConfigStub = sinon.stub(configParser, 'parseTomlConfig');
23+
providerStub = sinon.createStubInstance(JsonRpcProvider);
24+
contractStub = sinon.createStubInstance(Contract);
25+
26+
parseTomlConfigStub.returns({
27+
L1_CONTRACT: '0x1111111111111111111111111111111111111111',
28+
L2_CONTRACT: '0x2222222222222222222222222222222222222222',
29+
L2_GAS_PRICE_ORACLE_IMPLEMENTATION_ADDR: '0x3333333333333333333333333333333333333333',
30+
L2_GAS_PRICE_ORACLE_PROXY_ADDR: '0x4444444444444444444444444444444444444444',
31+
L1_GAS_PRICE_ORACLE_ADDR: '0x5555555555555555555555555555555555555555',
32+
general: {
33+
L1_RPC_ENDPOINT: 'http://l1.example.com',
34+
L2_RPC_ENDPOINT: 'http://l2.example.com',
35+
},
36+
});
37+
38+
sinon.stub(JsonRpcProvider, 'from' as keyof typeof JsonRpcProvider).returns(providerStub);
39+
sinon.stub(Contract, 'from' as keyof typeof Contract).returns(contractStub);
40+
});
41+
42+
afterEach(() => {
43+
sinon.restore();
44+
});
45+
46+
it('should correctly initialize providers', async () => {
47+
const testContracts = new TestContracts([], mockConfig);
48+
await testContracts.run();
49+
50+
expect(JsonRpcProvider.from).to.have.been.calledTwice;
51+
expect(JsonRpcProvider.from).to.have.been.calledWith('http://l1.example.com');
52+
expect(JsonRpcProvider.from).to.have.been.calledWith('http://l2.example.com');
53+
});
54+
55+
it('should check contract deployment on L1', async () => {
56+
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
57+
contractStub.initialized.resolves(true);
58+
59+
const testContracts = new TestContracts([], {});
60+
await testContracts.run();
61+
62+
expect(providerStub.getCode).to.have.been.calledWith('0x1111111111111111111111111111111111111111');
63+
expect(contractStub.initialized).to.have.been.called;
64+
});
65+
66+
it('should check contract deployment on L2', async () => {
67+
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
68+
contractStub.initialized.resolves(true);
69+
70+
const testContracts = new TestContracts([], {});
71+
await testContracts.run();
72+
73+
expect(providerStub.getCode).to.have.been.calledWith('0x2222222222222222222222222222222222222222');
74+
expect(contractStub.initialized).to.have.been.called;
75+
});
76+
77+
it('should handle undeployed contracts', async () => {
78+
providerStub.getCode.resolves('0x'); // Empty bytecode
79+
80+
const testContracts = new TestContracts([], {});
81+
await testContracts.run();
82+
83+
expect(providerStub.getCode).to.have.been.called;
84+
expect(contractStub.initialized).to.not.have.been.called;
85+
});
86+
87+
it('should handle uninitialized contracts', async () => {
88+
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
89+
contractStub.initialized.resolves(false);
90+
91+
const testContracts = new TestContracts([], {});
92+
await testContracts.run();
93+
94+
expect(providerStub.getCode).to.have.been.called;
95+
expect(contractStub.initialized).to.have.been.called;
96+
});
97+
98+
it('should check L2 Gas Price Oracle contracts on L1', async () => {
99+
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
100+
contractStub.initialized.resolves(true);
101+
102+
const testContracts = new TestContracts([], {});
103+
await testContracts.run();
104+
105+
expect(providerStub.getCode).to.have.been.calledWith('0x3333333333333333333333333333333333333333');
106+
expect(providerStub.getCode).to.have.been.calledWith('0x4444444444444444444444444444444444444444');
107+
});
108+
109+
it('should check L1 Gas Price Oracle contract on L2', async () => {
110+
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
111+
contractStub.initialized.resolves(true);
112+
113+
const testContracts = new TestContracts([], {});
114+
await testContracts.run();
115+
116+
expect(providerStub.getCode).to.have.been.calledWith('0x5555555555555555555555555555555555555555');
117+
});
118+
});

0 commit comments

Comments
 (0)