ethereum-waffle#MockContract TypeScript Examples
The following examples show how to use
ethereum-waffle#MockContract.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockedExchangeRates.ts From lyra-protocol with ISC License | 5 votes |
constructor(_contract: MockContract & IExchangeRates) {
this.contract = _contract;
}
Example #2
Source File: MockedExchangeRates.ts From lyra-protocol with ISC License | 5 votes |
contract: MockContract & IExchangeRates;
Example #3
Source File: MockedExchanger.ts From lyra-protocol with ISC License | 5 votes |
constructor(_contract: MockContract & IExchanger) {
this.contract = _contract;
}
Example #4
Source File: MockedExchanger.ts From lyra-protocol with ISC License | 5 votes |
contract: MockContract & IExchanger;
Example #5
Source File: AmmSpec2.ts From perpetual-protocol with GNU General Public License v3.0 | 5 votes |
describe("Amm Unit Test 2 (Waffle)", async () => {
const [wallet1, wallet2] = new MockProvider().getWallets()
let amm: Amm
let l2PriceFeed: MockContract
let quoteToken: MockContract
let clearingHouse: MockContract
const AmmArtifact = await artifacts.readArtifact(ContractFullyQualifiedName.Amm)
const IERC20Artifact = await artifacts.readArtifact(ContractFullyQualifiedName.IERC20)
const L2PriceFeedArtifact = await artifacts.readArtifact(ContractFullyQualifiedName.L2PriceFeed)
beforeEach(async () => {
quoteToken = await deployMockContract(wallet1, IERC20Artifact.abi)
clearingHouse = await deployMockContract(wallet1, [])
l2PriceFeed = await deployMockContract(wallet1, L2PriceFeedArtifact.abi)
amm = ((await deployContract(wallet1, AmmArtifact, [], { gasLimit: 6000000 })) as unknown) as Amm
await amm.initialize(
parseEther("1000"),
parseEther("100"),
parseEther("0.9"), // tradeLimitRatio
parseEther("3600"), // fundingPeriod - 1hr
l2PriceFeed.address,
utils.formatBytes32String("ETH"),
quoteToken.address,
BigNumber.from(0), // fluctuation
BigNumber.from(0), // toll
BigNumber.from(0), // spread
)
await amm.setCounterParty(clearingHouse.address)
amm.connect(clearingHouse.address)
})
describe("price", () => {
it("getUnderlyingPrice", async () => {
const price = parseEther("1")
const priceFeedKeyBytes32 = await amm.priceFeedKey()
const priceFeedKeyStr = utils.parseBytes32String(priceFeedKeyBytes32)
expect(priceFeedKeyStr).eq("ETH")
await l2PriceFeed.mock.getPrice.withArgs(priceFeedKeyBytes32).returns(price)
expect((await amm.getUnderlyingPrice()).d).deep.eq(price)
})
})
describe("setCap", () => {
it("change maxHoldingBaseAsset and openInterestNotionalCap", async () => {
await expect(amm.setCap({ d: 100 }, { d: 200 }))
.to.emit(amm, "CapChanged")
.withArgs("100", "200")
expect((await amm.getMaxHoldingBaseAsset()).d).deep.eq(BigNumber.from(100))
expect((await amm.getOpenInterestNotionalCap()).d).deep.eq(BigNumber.from(200))
})
})
describe("setPriceFeed", () => {
it("set priceFeed correctly", async () => {
const updatedPriceFeed = "0x77F9710E7d0A19669A13c055F62cd80d313dF022"
expect(await amm.priceFeed()).to.eq(l2PriceFeed.address)
await expect(amm.setPriceFeed(updatedPriceFeed))
.to.emit(amm, "PriceFeedUpdated")
.withArgs(updatedPriceFeed)
expect(await amm.priceFeed()).to.eq(updatedPriceFeed)
})
it("set priceFeed via non-owner causes revert transaction", async () => {
await expect(amm.connect(wallet2).setPriceFeed(l2PriceFeed.address)).to.be.revertedWith(
"PerpFiOwnableUpgrade: caller is not the owner",
)
})
it("revert if priceFeed address is zero", async () => {
await expect(amm.setPriceFeed(constants.AddressZero)).to.be.revertedWith("invalid PriceFeed address")
})
})
})
Example #6
Source File: deployTestSystem.ts From lyra-protocol with ISC License | 4 votes |
export async function deployTestContracts(deployer: Signer): Promise<TestSystemContractsType> {
// Deploy mocked contracts
const mockedExchangeRatesContract = await deployMockContract(deployer, IExchangeRatesJson.abi);
const exchangeRates = new MockedExchangeRates(mockedExchangeRatesContract as MockContract & IExchangeRates);
const mockedExchangerContract = await deployMockContract(deployer, IExchangerJson.abi);
const exchanger = new MockedExchanger(mockedExchangerContract as MockContract & IExchanger);
// Deploy real contracts
const lyraGlobals = (await (await ethers.getContractFactory('LyraGlobals'))
.connect(deployer)
.deploy()) as LyraGlobals;
const blackScholes = (await (await ethers.getContractFactory('BlackScholes'))
.connect(deployer)
.deploy()) as BlackScholes;
const registry = (await (await ethers.getContractFactory('LyraMarketsRegistry'))
.connect(deployer)
.deploy()) as LyraMarketsRegistry;
const optionMarket = (await (await ethers.getContractFactory('OptionMarket'))
.connect(deployer)
.deploy()) as OptionMarket;
const optionMarketPricer = (await (await ethers.getContractFactory('OptionMarketPricer'))
.connect(deployer)
.deploy()) as OptionMarketPricer;
const optionGreekCache = (await (await ethers.getContractFactory('OptionGreekCache'))
.connect(deployer)
.deploy()) as OptionGreekCache;
const liquidityPool = (await (await ethers.getContractFactory('TestLiquidityPool'))
.connect(deployer)
.deploy()) as TestLiquidityPool;
const liquidityCertificate = (await (await ethers.getContractFactory('LiquidityCertificate'))
.connect(deployer)
.deploy('USD/ETH Pool Certificate', 'UEP')) as LiquidityCertificate;
const optionToken = (await (await ethers.getContractFactory('OptionToken'))
.connect(deployer)
.deploy('USD/ETH Option Tokens')) as OptionToken;
const shortCollateral = (await (await ethers.getContractFactory('ShortCollateral'))
.connect(deployer)
.deploy()) as ShortCollateral;
const optionMarketViewer = (await (await ethers.getContractFactory('OptionMarketViewer'))
.connect(deployer)
.deploy()) as OptionMarketViewer;
const optionMarketSafeSlippage = (await (await ethers.getContractFactory('OptionMarketSafeSlippage'))
.connect(deployer)
.deploy()) as OptionMarketSafeSlippage;
// Test Contracts
const quoteToken = (await (await ethers.getContractFactory('TestERC20Fail'))
.connect(deployer)
.deploy('Synthetic USD', 'sUSD')) as TestERC20Fail;
const baseToken = (await (await ethers.getContractFactory('TestERC20Fail'))
.connect(deployer)
.deploy('Synthetic ETH', 'sETH')) as TestERC20Fail;
const synthetix = (await (await ethers.getContractFactory('TestSynthetixReturnZero'))
.connect(deployer)
.deploy()) as TestSynthetixReturnZero;
const poolHedger = (await (await ethers.getContractFactory('PoolHedger')).connect(deployer).deploy()) as PoolHedger;
const collateralShort = (await (await ethers.getContractFactory('TestCollateralShort'))
.connect(deployer)
.deploy()) as TestCollateralShort;
return {
lyraGlobals,
registry,
optionMarket,
optionGreekCache,
optionMarketPricer,
optionToken,
blackScholes,
liquidityPool,
liquidityCertificate,
shortCollateral,
optionMarketViewer,
optionMarketSafeSlippage,
poolHedger,
mocked: {
exchangeRates,
exchanger,
},
test: {
quoteToken,
baseToken,
synthetix,
collateralShort,
},
};
}