-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SUBGRAPH] [BUG] PoolMember not getting updated when the member units…
… change (#1877) * add a test starter * add the test * fixes * improve test * update dev container for matchstick compatibility * implement the fix * clean-up * add elaborate test for pool total amount received * fix test issue * add even more comments * fix test name * ignore test --------- Co-authored-by: 0xdavinchee <[email protected]>
- Loading branch information
1 parent
24762f1
commit b48fcca
Showing
8 changed files
with
390 additions
and
42 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
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
89 changes: 89 additions & 0 deletions
89
packages/subgraph/tests/bugs/2024-03-06-pool-member-units-changed.test.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,89 @@ | ||
import { handleMemberUnitsUpdated } from "../../src/mappings/superfluidPool"; | ||
import { createMemberUnitsUpdatedEvent } from "../gdav1/gdav1.helper"; | ||
import { Address, BigInt } from "@graphprotocol/graph-ts"; | ||
import { FAKE_INITIAL_BALANCE, alice, bob, charlie } from "../constants"; | ||
import { BIG_INT_ZERO, getPoolMemberID } from "../../src/utils"; | ||
import { assert, describe, test } from "matchstick-as"; | ||
import { mockedGetAppManifest, mockedRealtimeBalanceOf } from "../mockedFunctions"; | ||
|
||
describe("PoolMember not updating when units changed", () => { | ||
test("emit MemberUnitsUpdated event", () => { | ||
const superTokenAddress = alice; | ||
|
||
const poolAddress = Address.fromString(bob); | ||
const poolMemberAccountAddress = Address.fromString(charlie); | ||
const poolMemberId = getPoolMemberID(poolAddress, poolMemberAccountAddress); | ||
|
||
mockedGetAppManifest(poolMemberAccountAddress.toHexString(), false, false, BIG_INT_ZERO); | ||
|
||
// Initialize pool member for the first time | ||
const firstEvent = createMemberUnitsUpdatedEvent( | ||
superTokenAddress, | ||
poolMemberAccountAddress.toHexString(), | ||
BigInt.fromI32(0), // old units | ||
BigInt.fromI32(0) // new units | ||
); | ||
firstEvent.address = poolAddress; | ||
|
||
mockedRealtimeBalanceOf( | ||
superTokenAddress, | ||
poolMemberAccountAddress.toHexString(), | ||
firstEvent.block.timestamp, | ||
FAKE_INITIAL_BALANCE, | ||
BigInt.fromI32(0), | ||
BIG_INT_ZERO | ||
); | ||
|
||
handleMemberUnitsUpdated(firstEvent); | ||
// --- | ||
|
||
|
||
const newUnits = BigInt.fromI32(100); | ||
const blockNumber = BigInt.fromI32(200) | ||
const timestamp = BigInt.fromI32(300) | ||
|
||
const secondEvent = createMemberUnitsUpdatedEvent( | ||
superTokenAddress, | ||
poolMemberAccountAddress.toHexString(), | ||
BigInt.fromI32(0), // old units | ||
newUnits | ||
); | ||
secondEvent.block.timestamp = timestamp | ||
secondEvent.address = poolAddress; | ||
secondEvent.block.number = blockNumber; | ||
|
||
mockedRealtimeBalanceOf( | ||
superTokenAddress, | ||
poolMemberAccountAddress.toHexString(), | ||
secondEvent.block.timestamp, | ||
FAKE_INITIAL_BALANCE, | ||
BigInt.fromI32(0), | ||
BIG_INT_ZERO | ||
); | ||
|
||
// Act | ||
handleMemberUnitsUpdated(secondEvent); | ||
|
||
// Assert | ||
assert.fieldEquals( | ||
"PoolMember", | ||
poolMemberId, | ||
"units", | ||
newUnits.toString() | ||
); | ||
|
||
assert.fieldEquals( | ||
"PoolMember", | ||
poolMemberId, | ||
"updatedAtTimestamp", | ||
timestamp.toString() | ||
); | ||
|
||
assert.fieldEquals( | ||
"PoolMember", | ||
poolMemberId, | ||
"updatedAtBlockNumber", | ||
blockNumber.toString() | ||
); | ||
}); | ||
}); |
Oops, something went wrong.