Skip to content

Commit

Permalink
Revert "fix: ci test"
Browse files Browse the repository at this point in the history
This reverts commit 275b690.
  • Loading branch information
yiweichi committed Nov 22, 2024
1 parent 275b690 commit 6ba2aae
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions test/commands/test/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { Config } from '@oclif/core';
import { JsonRpcProvider, Contract } from 'ethers';
import * as configParser from '../../../src/utils/config-parser.js';
import TestContracts from '../../../src/commands/test/contracts.js';

const mockConfig: Config = {
// Add minimum required properties
root: '/mock/root',
name: 'mock-cli',
version: '1.0.0',
// Add other required properties as needed
} as Config;

describe('TestContracts', () => {
let parseTomlConfigStub: sinon.SinonStub;
let providerStub: sinon.SinonStubbedInstance<JsonRpcProvider>;
let contractStub: sinon.SinonStubbedInstance<Contract>;

beforeEach(() => {
parseTomlConfigStub = sinon.stub(configParser, 'parseTomlConfig');
providerStub = sinon.createStubInstance(JsonRpcProvider);
contractStub = sinon.createStubInstance(Contract);

parseTomlConfigStub.returns({
L1_CONTRACT: '0x1111111111111111111111111111111111111111',
L2_CONTRACT: '0x2222222222222222222222222222222222222222',
L2_GAS_PRICE_ORACLE_IMPLEMENTATION_ADDR: '0x3333333333333333333333333333333333333333',
L2_GAS_PRICE_ORACLE_PROXY_ADDR: '0x4444444444444444444444444444444444444444',
L1_GAS_PRICE_ORACLE_ADDR: '0x5555555555555555555555555555555555555555',
general: {
L1_RPC_ENDPOINT: 'http://l1.example.com',
L2_RPC_ENDPOINT: 'http://l2.example.com',
},
});

sinon.stub(JsonRpcProvider, 'from' as keyof typeof JsonRpcProvider).returns(providerStub);
sinon.stub(Contract, 'from' as keyof typeof Contract).returns(contractStub);
});

afterEach(() => {
sinon.restore();
});

it('should correctly initialize providers', async () => {
const testContracts = new TestContracts([], mockConfig);
await testContracts.run();

expect(JsonRpcProvider.from).to.have.been.calledTwice;

Check failure on line 50 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'calledTwice' does not exist on type 'Assertion'.

Check failure on line 50 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'calledTwice' does not exist on type 'Assertion'.

Check failure on line 50 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'calledTwice' does not exist on type 'Assertion'.

Check failure on line 50 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'calledTwice' does not exist on type 'Assertion'.

Check failure on line 50 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'calledTwice' does not exist on type 'Assertion'.

Check failure on line 50 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'calledTwice' does not exist on type 'Assertion'.
expect(JsonRpcProvider.from).to.have.been.calledWith('http://l1.example.com');

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 51 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.
expect(JsonRpcProvider.from).to.have.been.calledWith('http://l2.example.com');

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'from' does not exist on type 'typeof JsonRpcProvider'.

Check failure on line 52 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.
});

it('should check contract deployment on L1', async () => {
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
contractStub.initialized.resolves(true);

const testContracts = new TestContracts([], {});

Check failure on line 59 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 59 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 59 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 59 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 59 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 59 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Argument of type '{}' is not assignable to parameter of type 'Config'.
await testContracts.run();

expect(providerStub.getCode).to.have.been.calledWith('0x1111111111111111111111111111111111111111');

Check failure on line 62 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 62 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 62 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 62 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 62 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 62 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.
expect(contractStub.initialized).to.have.been.called;

Check failure on line 63 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'called' does not exist on type 'Assertion'.

Check failure on line 63 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'called' does not exist on type 'Assertion'.

Check failure on line 63 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'called' does not exist on type 'Assertion'.

Check failure on line 63 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'called' does not exist on type 'Assertion'.

Check failure on line 63 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'called' does not exist on type 'Assertion'.

Check failure on line 63 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'called' does not exist on type 'Assertion'.
});

it('should check contract deployment on L2', async () => {
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
contractStub.initialized.resolves(true);

const testContracts = new TestContracts([], {});

Check failure on line 70 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 70 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 70 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 70 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 70 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Argument of type '{}' is not assignable to parameter of type 'Config'.

Check failure on line 70 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Argument of type '{}' is not assignable to parameter of type 'Config'.
await testContracts.run();

expect(providerStub.getCode).to.have.been.calledWith('0x2222222222222222222222222222222222222222');

Check failure on line 73 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 73 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 73 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 73 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, latest)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 73 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/-1)

Property 'calledWith' does not exist on type 'Assertion'.

Check failure on line 73 in test/commands/test/contracts.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest, lts/*)

Property 'calledWith' does not exist on type 'Assertion'.
expect(contractStub.initialized).to.have.been.called;
});

it('should handle undeployed contracts', async () => {
providerStub.getCode.resolves('0x'); // Empty bytecode

const testContracts = new TestContracts([], {});
await testContracts.run();

expect(providerStub.getCode).to.have.been.called;
expect(contractStub.initialized).to.not.have.been.called;
});

it('should handle uninitialized contracts', async () => {
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
contractStub.initialized.resolves(false);

const testContracts = new TestContracts([], {});
await testContracts.run();

expect(providerStub.getCode).to.have.been.called;
expect(contractStub.initialized).to.have.been.called;
});

it('should check L2 Gas Price Oracle contracts on L1', async () => {
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
contractStub.initialized.resolves(true);

const testContracts = new TestContracts([], {});
await testContracts.run();

expect(providerStub.getCode).to.have.been.calledWith('0x3333333333333333333333333333333333333333');
expect(providerStub.getCode).to.have.been.calledWith('0x4444444444444444444444444444444444444444');
});

it('should check L1 Gas Price Oracle contract on L2', async () => {
providerStub.getCode.resolves('0x123456'); // Non-empty bytecode
contractStub.initialized.resolves(true);

const testContracts = new TestContracts([], {});
await testContracts.run();

expect(providerStub.getCode).to.have.been.calledWith('0x5555555555555555555555555555555555555555');
});
});

0 comments on commit 6ba2aae

Please sign in to comment.