-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from overlay-market/arthurka/bac-86-add-tests-…
…to-overlayv1factory-handlers `OverlayV1Factory` tests
- Loading branch information
Showing
4 changed files
with
315 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
import { | ||
assert, | ||
describe, | ||
test, | ||
clearStore, | ||
beforeAll, | ||
beforeEach, | ||
afterEach | ||
} from "matchstick-as/assembly/index" | ||
import { newMockEvent } from "matchstick-as" | ||
import { ethereum, Address, BigInt } from "@graphprotocol/graph-ts" | ||
|
||
import { | ||
MarketDeployed as MarketDeployedEvent, | ||
FeeRecipientUpdated as FeeRecipientUpdatedEvent, | ||
ParamUpdated as ParamUpdatedEvent, | ||
EmergencyShutdown as EmergencyShutdownEvent | ||
} from "../../../generated/OverlayV1Factory/OverlayV1Factory" | ||
import { handleEmergencyShutdown, handleFeeRecipientUpdated, handleMarketDeployed, handleParamUpdated } from "../../mapping" | ||
import { FACTORY_ADDRESS, PERIPHERY_ADDRESS } from "../../utils/constants" | ||
import { setupMarketMockedFunctions } from "./shared/mockedFunctions" | ||
import { loadFactory } from "../../utils" | ||
|
||
export { handleMarketDeployed } | ||
|
||
const market = Address.fromString("0x0000000000000000000000000000000000000001") | ||
const user = Address.fromString("0x0000000000000000000000000000000000000004"); | ||
const feed = Address.fromString("0x0000000000000000000000000000000000000005"); | ||
const recipientAddress = Address.fromString("0x0000000000000000000000000000000000000006"); | ||
|
||
const factoryAddress = Address.fromString(FACTORY_ADDRESS) | ||
const marketStateAddress = Address.fromString(PERIPHERY_ADDRESS) | ||
|
||
// createParamUpdatedEvent attrs | ||
|
||
// because RISK_PARAMS[5] doesn't work without million hoops | ||
const paramNameKey = "capLeverage" | ||
const paramNameValue: u8 = 5 | ||
const paramValue = BigInt.fromI32(5) | ||
|
||
describe("Market Factory events", () => { | ||
beforeAll(() => { | ||
setupMarketMockedFunctions(factoryAddress, marketStateAddress, market) | ||
}) | ||
describe("Market Deployed event", () => { | ||
beforeEach(() => { | ||
const event = createMarketDeployedEvent(factoryAddress, user, market, feed) | ||
handleMarketDeployed(event) | ||
}) | ||
|
||
afterEach(() => { | ||
clearStore() | ||
}) | ||
|
||
test("creates Market entity", () => { | ||
assert.entityCount("Market", 1) | ||
}) | ||
|
||
}) | ||
|
||
describe("Fee Recipient Updated event", () => { | ||
beforeEach(() => { | ||
// initializing factory | ||
loadFactory(factoryAddress.toString()) | ||
// imitating an event | ||
const event = createFeeRecipientUpdatedEvent(factoryAddress, user, recipientAddress) | ||
handleFeeRecipientUpdated(event) | ||
}) | ||
|
||
afterEach(() => { | ||
clearStore() | ||
}) | ||
|
||
test("doesn't create additional Factory entity", () => { | ||
assert.entityCount("Factory", 1) | ||
}) | ||
|
||
test("fee recipient is set correctly", () => { | ||
assert.fieldEquals("Factory", factoryAddress.toHexString(), "feeRecipient", recipientAddress.toHexString()) | ||
}) | ||
}) | ||
|
||
describe("Param Updated event", () => { | ||
beforeEach(() => { | ||
loadFactory(factoryAddress.toString()) | ||
const event = createParamUpdatedEvent(factoryAddress, user, market, paramNameValue, paramValue) | ||
handleParamUpdated(event) | ||
}) | ||
|
||
afterEach(() => { | ||
clearStore() | ||
}) | ||
|
||
test("param value is set correctly", () => { | ||
assert.fieldEquals("Market", market.toHexString(), paramNameKey, paramValue.toString()) | ||
}) | ||
}) | ||
|
||
describe("Emergency Shutdown event", () => { | ||
beforeEach(() => { | ||
loadFactory(factoryAddress.toString()) | ||
const event = createEmergencyShutdownEvent(factoryAddress, user, market) | ||
handleEmergencyShutdown(event) | ||
}) | ||
|
||
afterEach(() => { | ||
clearStore() | ||
}) | ||
|
||
test("market is marked as shut down", () => { | ||
assert.fieldEquals("Market", market.toHexString(), "isShutdown", "true") | ||
}) | ||
}) | ||
}) | ||
|
||
function createMarketDeployedEvent( | ||
factory: Address, | ||
user: Address, | ||
market: Address, | ||
feed: Address | ||
): MarketDeployedEvent { | ||
const event = changetype<MarketDeployedEvent>(newMockEvent()) | ||
|
||
event.address = factory | ||
event.parameters = new Array() | ||
|
||
event.parameters.push( | ||
new ethereum.EventParam("user", ethereum.Value.fromAddress(user)), | ||
) | ||
event.parameters.push( | ||
new ethereum.EventParam("market", ethereum.Value.fromAddress(market)), | ||
) | ||
event.parameters.push( | ||
new ethereum.EventParam("feed", ethereum.Value.fromAddress(feed)), | ||
) | ||
|
||
return event | ||
} | ||
|
||
function createFeeRecipientUpdatedEvent( | ||
factory: Address, | ||
user: Address, | ||
recipient: Address | ||
): FeeRecipientUpdatedEvent { | ||
const event = changetype<FeeRecipientUpdatedEvent>(newMockEvent()) | ||
|
||
event.address = factory | ||
event.parameters = new Array() | ||
|
||
event.parameters.push( | ||
new ethereum.EventParam("user", ethereum.Value.fromAddress(user)), | ||
) | ||
event.parameters.push( | ||
new ethereum.EventParam("recipient", ethereum.Value.fromAddress(recipient)), | ||
) | ||
|
||
return event | ||
} | ||
|
||
function createParamUpdatedEvent( | ||
factory: Address, | ||
user: Address, | ||
market: Address, | ||
name: u8, | ||
value: BigInt | ||
): ParamUpdatedEvent { | ||
const event = changetype<ParamUpdatedEvent>(newMockEvent()) | ||
|
||
event.address = factory | ||
event.parameters = new Array() | ||
|
||
event.parameters.push( | ||
new ethereum.EventParam("user", ethereum.Value.fromAddress(user)), | ||
) | ||
event.parameters.push( | ||
new ethereum.EventParam("market", ethereum.Value.fromAddress(market)), | ||
) | ||
// fromI32 was chosen because `name` is uint8, int32 includes values up to uint16 | ||
event.parameters.push( | ||
new ethereum.EventParam("name", ethereum.Value.fromI32(name)), | ||
) | ||
event.parameters.push( | ||
new ethereum.EventParam("value", ethereum.Value.fromUnsignedBigInt(value)), | ||
) | ||
|
||
return event | ||
} | ||
|
||
function createEmergencyShutdownEvent( | ||
factory: Address, | ||
user: Address, | ||
market: Address | ||
): EmergencyShutdownEvent { | ||
const event = changetype<EmergencyShutdownEvent>(newMockEvent()) | ||
|
||
event.address = factory | ||
event.parameters = new Array() | ||
|
||
event.parameters.push( | ||
new ethereum.EventParam("user", ethereum.Value.fromAddress(user)), | ||
) | ||
event.parameters.push( | ||
new ethereum.EventParam("market", ethereum.Value.fromAddress(market)), | ||
) | ||
|
||
return event | ||
} |
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,8 @@ | ||
import { Address, BigInt } from "@graphprotocol/graph-ts" | ||
|
||
const MARKET_COLLATERAL = BigInt.fromI32(1000) | ||
const MARKET_POSITION_ID = BigInt.fromI32(1) | ||
const MARKET_PCD_HOLDER = Address.fromString("0x000000000000000000000000000000000000ca1e") | ||
const MARKET_SENDER = Address.fromString("0x0000000000000000000000000000000000000b0b") | ||
|
||
export { MARKET_COLLATERAL, MARKET_POSITION_ID, MARKET_PCD_HOLDER, MARKET_SENDER } |
Oops, something went wrong.