Skip to content

Commit

Permalink
Merge pull request #15 from loreum-org/feat/proposal-canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad authored Feb 23, 2024
2 parents 968aafa + d8e0d68 commit 65b99a4
Show file tree
Hide file tree
Showing 9 changed files with 1,040 additions and 1,043 deletions.
966 changes: 497 additions & 469 deletions package-lock.json

Large diffs are not rendered by default.

931 changes: 472 additions & 459 deletions subgraphs/chamber/abis/Chamber.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions subgraphs/chamber/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ type ProposalExecuted @entity(immutable: true) {
transactionHash: Bytes!
}

type ProposalCanceled @entity(immutable: true) {
id: ID!
proposalId: BigInt! # uint256
contractAddress: Bytes! # address
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type ReceivedEther @entity(immutable: true) {
id: ID!
sender: Bytes! # address
Expand Down
15 changes: 15 additions & 0 deletions subgraphs/chamber/src/chamber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProposalApproved as ProposalApprovedEvent,
ProposalCreated as ProposalCreatedEvent,
ProposalExecuted as ProposalExecutedEvent,
ProposalCanceled as ProposalCanceledEvent,
ReceivedEther as ReceivedEtherEvent,
ReceivedFallback as ReceivedFallbackEvent,
} from "../generated/templates/Chamber/Chamber";
Expand All @@ -21,6 +22,7 @@ import {
ProposalApproved,
ProposalCreated,
ProposalExecuted,
ProposalCanceled,
ReceivedEther,
ReceivedFallback,
} from "../generated/schema";
Expand Down Expand Up @@ -127,6 +129,19 @@ export function handleProposalExecuted(event: ProposalExecutedEvent): void {
proposalExecutedTx.save();
}

export function handleProposalCanceled(event: ProposalCanceledEvent): void {
const id = createId(event.transaction.hash, event.logIndex);
const proposalCanceledTx = new ProposalCanceled(id);
proposalCanceledTx.proposalId = event.params.proposalId;
proposalCanceledTx.contractAddress = changetype<Bytes>(event.transaction.to);

proposalCanceledTx.blockNumber = event.block.number;
proposalCanceledTx.blockTimestamp = event.block.timestamp;
proposalCanceledTx.transactionHash = event.transaction.hash;

proposalCanceledTx.save();
}

export function handleReceivedEther(event: ReceivedEtherEvent): void {
const id = createId(event.transaction.hash, event.logIndex);
const receivedEtherTx = new ReceivedEther(id);
Expand Down
2 changes: 2 additions & 0 deletions subgraphs/chamber/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ templates:
handler: handleProposalCreated
- event: ProposalExecuted(uint256)
handler: handleProposalExecuted
- event: ProposalCanceled(uint256)
handler: handleProposalCanceled
- event: ReceivedEther(indexed address,uint256)
handler: handleReceivedEther
- event: ReceivedFallback(indexed address,uint256)
Expand Down
16 changes: 16 additions & 0 deletions subgraphs/chamber/tests/chamber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ProposalApproved,
// ProposalCreated,
ProposalExecuted,
ProposalCanceled,
ReceivedEther,
ReceivedFallback,
} from "../generated/templates/Chamber/Chamber";
Expand All @@ -20,6 +21,7 @@ import {
handleProposalApproved,
// handleProposalCreated,
handleProposalExecuted,
handleProposalCanceled,
handleReceivedEther,
handleReceivedFallback,
} from "../src/chamber";
Expand All @@ -32,6 +34,7 @@ import {
createProposalApprovedEvent,
// createProposalCreatedEvent,
createProposalExecutedEvent,
createProposalCanceledEvent,
createReceivedEtherEvent,
createReceivedFallbackEvent,
} from "./helpers/utils";
Expand All @@ -44,6 +47,7 @@ import {
expectProposalApprovedAdded,
// expectProposalCreatedAdded,
expectProposalExecutedAdded,
expectProposalCanceledAdded,
expectReceivedEtherAdded,
expectReceivedFallbackAdded,
} from "./helpers/assertions";
Expand Down Expand Up @@ -161,6 +165,18 @@ describe("Chamber Test", () => {
});
});

describe("Test ProposalCanceled", () => {
const createMockProposalCanceledEvent = (proposalId: i32 = 1): ProposalCanceled => {
const event = createProposalCanceledEvent(proposalId);
return event;
};
test("Handel ProposalCanceled Tx", () => {
const event = createMockProposalCanceledEvent();
handleProposalCanceled(event);
expectProposalCanceledAdded(event);
});
});

describe("Test ReceivedEther", () => {
const createMockReceivedEtherEvent = (
sender: string = "0x8E1aA1674D9Fc9f0dca4a4D31db85E65D216666c",
Expand Down
10 changes: 10 additions & 0 deletions subgraphs/chamber/tests/helpers/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ProposalApproved as ProposalApprovedTx,
ProposalCreated as ProposalCreatedTx,
ProposalExecuted as ProposalExecutedTx,
ProposalCanceled as ProposalCanceledTx,
ReceivedEther as ReceivedEtherTx,
ReceivedFallback as ReceivedFallbackTX,
} from "../../generated/schema";
Expand All @@ -22,6 +23,7 @@ import {
ProposalApproved,
ProposalCreated,
ProposalExecuted,
ProposalCanceled,
ReceivedEther,
ReceivedFallback,
} from "../../generated/templates/Chamber/Chamber";
Expand Down Expand Up @@ -113,6 +115,14 @@ export const expectProposalExecutedAdded = (event: ProposalExecuted): void => {
assert.bigIntEquals(event.params.proposalId, proposalExecutedTx.proposalId);
};

export const expectProposalCanceledAdded = (event: ProposalCanceled): void => {
const id = createId(event.transaction.hash, event.transactionLogIndex);
const proposalCanceledTx = ProposalCanceledTx.load(id);
assert.assertNotNull(proposalCanceledTx);
if (!proposalCanceledTx) return;
assert.bigIntEquals(event.params.proposalId, proposalCanceledTx.proposalId);
};

export const expectReceivedEtherAdded = (event: ReceivedEther): void => {
const id = createId(event.transaction.hash, event.transactionLogIndex);
const receivedEtherTx = ReceivedEtherTx.load(id);
Expand Down
17 changes: 17 additions & 0 deletions subgraphs/chamber/tests/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ProposalApproved,
ProposalCreated,
ProposalExecuted,
ProposalCanceled,
ReceivedEther,
ReceivedFallback,
} from "../../generated/templates/Chamber/Chamber";
Expand Down Expand Up @@ -196,6 +197,22 @@ export function createProposalExecutedEvent(proposalId: i32): ProposalExecuted {
return proposalExecutedEvent;
}

export function createProposalCanceledEvent(proposalId: i32): ProposalCanceled {
const mockEvent = newMockEvent();
const proposalCanceledEvent = new ProposalCanceled(
mockEvent.address,
mockEvent.logIndex,
mockEvent.transactionLogIndex,
mockEvent.logType,
mockEvent.block,
mockEvent.transaction,
[],
mockEvent.receipt
);
proposalCanceledEvent.parameters.push(uintEventParam("proposalId", proposalId));
return proposalCanceledEvent;
}

export function createReceivedEtherEvent(sender: string, value: i32): ReceivedEther {
const mockEvent = newMockEvent();
const receivedEtherEvent = new ReceivedEther(
Expand Down
117 changes: 2 additions & 115 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -724,60 +724,13 @@
which "2.0.2"
yaml "1.10.2"

"@graphprotocol/[email protected]":
version "0.67.4"
resolved "https://registry.npmjs.org/@graphprotocol/graph-cli/-/graph-cli-0.67.4.tgz"
integrity sha512-U2LDemWwmYUxf7PloAcDPXK1UeceRphGJJKrhNbDZB32hlp3LY+GI6HnRK4F9Oeri2azB3t3/humNxIDgbim0w==
dependencies:
"@float-capital/float-subgraph-uncrashable" "^0.0.0-alpha.4"
"@oclif/core" "2.8.6"
"@oclif/plugin-autocomplete" "^2.3.6"
"@oclif/plugin-not-found" "^2.4.0"
"@whatwg-node/fetch" "^0.8.4"
assemblyscript "0.19.23"
binary-install-raw "0.0.13"
chalk "3.0.0"
chokidar "3.5.3"
debug "4.3.4"
docker-compose "0.23.19"
dockerode "2.5.8"
fs-extra "9.1.0"
glob "9.3.5"
gluegun "5.1.6"
graphql "15.5.0"
immutable "4.2.1"
ipfs-http-client "55.0.0"
jayson "4.0.0"
js-yaml "3.14.1"
prettier "3.0.3"
semver "7.4.0"
sync-request "6.1.0"
tmp-promise "3.0.3"
web3-eth-abi "1.7.0"
which "2.0.2"
yaml "1.10.2"

"@graphprotocol/graph-ts@^0.27.0":
version "0.27.0"
resolved "https://registry.npmjs.org/@graphprotocol/graph-ts/-/graph-ts-0.27.0.tgz"
integrity sha512-r1SPDIZVQiGMxcY8rhFSM0y7d/xAbQf5vHMWUf59js1KgoyWpM6P3tczZqmQd7JTmeyNsDGIPzd9FeaxllsU4w==
dependencies:
assemblyscript "0.19.10"

"@graphprotocol/graph-ts@^0.28.0":
version "0.28.1"
resolved "https://registry.npmjs.org/@graphprotocol/graph-ts/-/graph-ts-0.28.1.tgz"
integrity sha512-1wMLQ0cu84/6Ml3zcz9ya1zFzrDAzCj0dIGZ7Rz9upnRSXg5jjqU4DefO/OYrl2K2/OPso9hSAr6I4aue2pL1Q==
dependencies:
assemblyscript "0.19.10"

"@graphprotocol/[email protected]":
version "0.32.0"
resolved "https://registry.npmjs.org/@graphprotocol/graph-ts/-/graph-ts-0.32.0.tgz"
integrity sha512-YfKLT2w+ItXD/VPYQiAKtINQONVsAOkcqVFMHlhUy0fcEBVWuFBT53hJNI0/l5ujQa4TSxtzrKW/7EABAdgI8g==
dependencies:
assemblyscript "0.19.10"

"@humanwhocodes/config-array@^0.11.13":
version "0.11.13"
resolved "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz"
Expand Down Expand Up @@ -2543,15 +2496,6 @@ asn1js@^3.0.1, asn1js@^3.0.5:
pvutils "^1.1.3"
tslib "^2.4.0"

assemblyscript@^0.19.20:
version "0.19.23"
resolved "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.19.23.tgz"
integrity sha512-fwOQNZVTMga5KRsfY80g7cpOl4PsFQczMwHzdtgoqLXaYhkhavufKb0sB0l3T1DUxpAufA0KNhlbpuuhZUwxMA==
dependencies:
binaryen "102.0.0-nightly.20211028"
long "^5.2.0"
source-map-support "^0.5.20"

[email protected]:
version "0.19.10"
resolved "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.19.10.tgz"
Expand Down Expand Up @@ -2967,7 +2911,7 @@ [email protected]:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

"chamber@file:/Users/jyotirmoy/Desktop/repo/subgraph/subgraphs/chamber":
"chamber@file:/Users/jyotirmoy/Desktop/subgraph/subgraphs/chamber":
version "1.0.0"
resolved "file:subgraphs/chamber"
dependencies:
Expand Down Expand Up @@ -3633,13 +3577,6 @@ [email protected]:
dependencies:
jake "^10.6.1"

[email protected]:
version "3.1.8"
resolved "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz"
integrity sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==
dependencies:
jake "^10.8.5"

electron-fetch@^1.7.2:
version "1.9.1"
resolved "https://registry.npmjs.org/electron-fetch/-/electron-fetch-1.9.1.tgz"
Expand Down Expand Up @@ -4541,42 +4478,6 @@ [email protected]:
which "2.0.2"
yargs-parser "^21.0.0"

[email protected]:
version "5.1.6"
resolved "https://registry.npmjs.org/gluegun/-/gluegun-5.1.6.tgz"
integrity sha512-9zbi4EQWIVvSOftJWquWzr9gLX2kaDgPkNR5dYWbM53eVvCI3iKuxLlnKoHC0v4uPoq+Kr/+F569tjoFbA4DSA==
dependencies:
apisauce "^2.1.5"
app-module-path "^2.2.0"
cli-table3 "0.6.0"
colors "1.4.0"
cosmiconfig "7.0.1"
cross-spawn "7.0.3"
ejs "3.1.8"
enquirer "2.3.6"
execa "5.1.1"
fs-jetpack "4.3.1"
lodash.camelcase "^4.3.0"
lodash.kebabcase "^4.1.1"
lodash.lowercase "^4.3.0"
lodash.lowerfirst "^4.3.1"
lodash.pad "^4.5.1"
lodash.padend "^4.6.1"
lodash.padstart "^4.6.1"
lodash.repeat "^4.1.0"
lodash.snakecase "^4.1.1"
lodash.startcase "^4.4.0"
lodash.trim "^4.5.1"
lodash.trimend "^4.5.1"
lodash.trimstart "^4.5.1"
lodash.uppercase "^4.3.0"
lodash.upperfirst "^4.3.1"
ora "4.0.2"
pluralize "^8.0.0"
semver "7.3.5"
which "2.0.2"
yargs-parser "^21.0.0"

gopd@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz"
Expand Down Expand Up @@ -5713,7 +5614,7 @@ long@^5.2.0:
resolved "https://registry.npmjs.org/long/-/long-5.2.3.tgz"
integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==

"loreum-nft@file:/Users/jyotirmoy/Desktop/repo/subgraph/subgraphs/loreum-nft":
"loreum-nft@file:/Users/jyotirmoy/Desktop/subgraph/subgraphs/loreum-nft":
version "1.0.0"
resolved "file:subgraphs/loreum-nft"

Expand Down Expand Up @@ -5817,15 +5718,6 @@ matchstick-as@^0.5.0:
dependencies:
wabt "1.0.24"

[email protected]:
version "0.5.0"
resolved "https://registry.npmjs.org/matchstick-as/-/matchstick-as-0.5.0.tgz"
integrity sha512-4K619YDH+so129qt4RB4JCNxaFwJJYLXPc7drpG+/mIj86Cfzg6FKs/bA91cnajmS1CLHdhHl9vt6Kd6Oqvfkg==
dependencies:
"@graphprotocol/graph-ts" "^0.27.0"
assemblyscript "^0.19.20"
wabt "1.0.24"

md5.js@^1.3.4:
version "1.3.5"
resolved "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz"
Expand Down Expand Up @@ -6838,11 +6730,6 @@ [email protected]:
resolved "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

[email protected]:
version "3.0.3"
resolved "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz"
integrity sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==

proc-log@^2.0.0, proc-log@^2.0.1:
version "2.0.1"
resolved "https://registry.npmjs.org/proc-log/-/proc-log-2.0.1.tgz"
Expand Down

0 comments on commit 65b99a4

Please sign in to comment.