-
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.
- Loading branch information
1 parent
b72547b
commit 413803c
Showing
10 changed files
with
2,313 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,9 @@ | ||
import { BigInt, ethereum } from "@graphprotocol/graph-ts"; | ||
import { InvoiceFundedEvent } from "../../generated/schema"; | ||
import { InvoiceFunded } from "../../generated/BullaFactoring/BullaFactoring"; | ||
|
||
export const getInvoiceFundedEventId = (underlyingClaimId: BigInt, event: ethereum.Event): string => | ||
"InvoiceFunded-" + underlyingClaimId.toString() + "-" + event.transaction.hash.toHexString() + "-" + event.logIndex.toString(); | ||
|
||
export const createInvoiceFundedEvent = (underlyingTokenId: BigInt, event: InvoiceFunded): InvoiceFundedEvent => | ||
new InvoiceFundedEvent(getInvoiceFundedEventId(underlyingTokenId, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { InvoiceFunded } from "../../generated/BullaFactoring/BullaFactoring"; | ||
import { getClaim } from "../functions/BullaClaimERC721"; | ||
import { createInvoiceFundedEvent } from "../functions/BullaFactoring"; | ||
|
||
export function handleInvoiceFunded(event: InvoiceFunded): void { | ||
const ev = event.params; | ||
const originatingClaimId = ev.invoiceId; | ||
|
||
const underlyingClaim = getClaim(originatingClaimId.toString()); | ||
const InvoiceFundedEvent = createInvoiceFundedEvent(originatingClaimId, event); | ||
|
||
InvoiceFundedEvent.invoiceId = underlyingClaim.id; | ||
InvoiceFundedEvent.fundedAmount = ev.fundedAmount; | ||
InvoiceFundedEvent.originalCreditor = ev.originalCreditor; | ||
|
||
InvoiceFundedEvent.eventName = "InvoiceFunded"; | ||
InvoiceFundedEvent.blockNumber = event.block.number; | ||
InvoiceFundedEvent.transactionHash = event.transaction.hash; | ||
InvoiceFundedEvent.logIndex = event.logIndex; | ||
InvoiceFundedEvent.timestamp = event.block.timestamp; | ||
|
||
InvoiceFundedEvent.save(); | ||
} |
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,43 @@ | ||
import { BigInt, log } from "@graphprotocol/graph-ts"; | ||
import { assert, test } from "matchstick-as/assembly/index"; | ||
import { CLAIM_TYPE_INVOICE } from "../src/functions/common"; | ||
import { handleClaimCreated } from "../src/mappings/BullaClaimERC721"; | ||
import { handleInvoiceFunded } from "../src/mappings/BullaFactoring"; | ||
import { newClaimCreatedEvent } from "./functions/BullaClaimERC721.testtools"; | ||
import { ADDRESS_1, afterEach, setupContracts } from "./helpers"; | ||
import { newInvoiceFundedEvent } from "./functions/BullaFactoring.testtools"; | ||
import { getInvoiceFundedEventId } from "../src/functions/BullaFactoring"; | ||
|
||
test("it handles BullaFactoring events", () => { | ||
setupContracts(); | ||
|
||
const claimId = BigInt.fromI32(1); | ||
const fundedAmount = BigInt.fromI32(10000); | ||
const originalCreditor = ADDRESS_1; | ||
|
||
const timestamp = BigInt.fromI32(100); | ||
const blockNum = BigInt.fromI32(100); | ||
|
||
const invoiceFundedEvent = newInvoiceFundedEvent(claimId, fundedAmount, originalCreditor); | ||
invoiceFundedEvent.block.timestamp = timestamp; | ||
invoiceFundedEvent.block.number = blockNum; | ||
|
||
const claimCreatedEvent = newClaimCreatedEvent(claimId.toU32(), CLAIM_TYPE_INVOICE); | ||
claimCreatedEvent.block.timestamp = timestamp; | ||
claimCreatedEvent.block.number = blockNum; | ||
|
||
handleClaimCreated(claimCreatedEvent); | ||
handleInvoiceFunded(invoiceFundedEvent); | ||
|
||
const invoiceFundedEventId = getInvoiceFundedEventId(claimId, invoiceFundedEvent); | ||
assert.fieldEquals("InvoiceFundedEvent", invoiceFundedEventId, "invoiceId", invoiceFundedEvent.params.invoiceId.toString()); | ||
assert.fieldEquals("InvoiceFundedEvent", invoiceFundedEventId, "fundedAmount", invoiceFundedEvent.params.fundedAmount.toString()); | ||
assert.fieldEquals("InvoiceFundedEvent", invoiceFundedEventId, "originalCreditor", invoiceFundedEvent.params.originalCreditor.toHexString()); | ||
|
||
log.info("✅ should create a InvoiceFunded event", []); | ||
|
||
afterEach(); | ||
}); | ||
|
||
// exporting for test coverage | ||
export { handleInvoiceFunded }; |
16 changes: 16 additions & 0 deletions
16
bulla-contracts/tests/functions/BullaFactoring.testtools.ts
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,16 @@ | ||
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; | ||
import { newMockEvent } from "matchstick-as"; | ||
import { InvoiceFunded } from "../../generated/BullaFactoring/BullaFactoring"; | ||
import { toEthAddress, toUint256 } from "../helpers"; | ||
|
||
export const newInvoiceFundedEvent = (originatingClaimId: BigInt, fundedAmount: BigInt, originalCreditor: Address): InvoiceFunded => { | ||
const event: InvoiceFunded = changetype<InvoiceFunded>(newMockEvent()); | ||
|
||
const invoiceId = new ethereum.EventParam("invoiceId", toUint256(originatingClaimId)); | ||
const fundedAmountParam = new ethereum.EventParam("fundedAmount", toUint256(fundedAmount)); | ||
const originalCreditorParam = new ethereum.EventParam("originalCreditor", toEthAddress(originalCreditor)); | ||
|
||
event.parameters = [invoiceId, fundedAmountParam, originalCreditorParam]; | ||
|
||
return event; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.