-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mocks can be deployed with libs
- Loading branch information
Showing
6 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import './TestLibrary.sol'; | ||
|
||
contract Librarian { | ||
function getLibValue() external pure returns (uint256) { | ||
return TestLibrary.getSomeValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
library TestLibrary { | ||
function getSomeValue() external pure returns (uint256) { | ||
return 10; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import { smock } from '@src'; | ||
import { Librarian__factory, TestLibrary__factory } from '@typechained'; | ||
import chai, { expect } from 'chai'; | ||
import { ethers } from 'hardhat'; | ||
|
||
chai.use(smock.matchers); | ||
|
||
describe.only('Mock: Initialization', () => { | ||
it('should be able to use libraries', async () => { | ||
const testLibrary = await (await ethers.getContractFactory('TestLibrary')).deploy(); | ||
const librarian = await ( | ||
await smock.mock<Librarian__factory>('Librarian', { | ||
libraries: { | ||
TestLibrary: testLibrary.address, | ||
}, | ||
}) | ||
).deploy(); | ||
|
||
expect(await librarian.getLibValue()).to.equal(10); | ||
}); | ||
|
||
// TODO: make it work | ||
it.skip('should be able to use mocked libraries', async () => { | ||
const testLibrary = await (await smock.mock<TestLibrary__factory>('TestLibrary')).deploy(); | ||
const librarian = await ( | ||
await smock.mock<Librarian__factory>('Librarian', { | ||
libraries: { | ||
TestLibrary: testLibrary.address, | ||
}, | ||
}) | ||
).deploy(); | ||
|
||
const mockValue = BigNumber.from(123); | ||
testLibrary.getSomeValue.returns(mockValue); | ||
|
||
expect(await librarian.getLibValue()).to.equal(mockValue); | ||
}); | ||
}); |