Skip to content

Commit

Permalink
Merge pull request #1072 from rainlanguage/2024-12-13-sg-bug
Browse files Browse the repository at this point in the history
sg bug
  • Loading branch information
thedavidmeister authored Dec 13, 2024
2 parents 998e6d6 + daa89e0 commit 34cb5be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion subgraph/src/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function makeClearBountyId(
vaultEntityId: Bytes
): Bytes {
return Bytes.fromByteArray(
crypto.keccak256(eventId(event).concat(vaultEntityId))
crypto.keccak256(vaultEntityId.concat(eventId(event)))
);
}

Expand Down
32 changes: 31 additions & 1 deletion subgraph/tests/tradevaultbalancechange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
assert,
} from "matchstick-as";
import { BigInt, Address, Bytes, crypto } from "@graphprotocol/graph-ts";
import { Evaluable, IO, createTakeOrderEvent } from "./event-mocks.test";
import {
Evaluable,
IO,
createAfterClearEvent,
createTakeOrderEvent,
} from "./event-mocks.test";
import { eventId } from "../src/interfaces/event";
import {
createTradeVaultBalanceChangeEntity,
Expand All @@ -18,6 +23,7 @@ import { vaultEntityId } from "../src/vault";
import { orderHashFromTakeOrderEvent } from "../src/takeorder";
import { makeTradeId } from "../src/trade";
import { createMockERC20Functions } from "./erc20.test";
import { makeClearBountyId } from "../src/clear";

describe("Deposits", () => {
afterEach(() => {
Expand Down Expand Up @@ -136,4 +142,28 @@ describe("Deposits", () => {
event.transaction.hash.toHex()
);
});

test("TradeVaultBalanceChangeEntity id should not be equal to ClearBounty id", () => {
const alice = Address.fromString(
"0x850c40aBf6e325231ba2DeD1356d1f2c267e63Ce"
);
let aliceOutputAmount = BigInt.fromString("10");
let bobOutputAmount = BigInt.fromString("20");
let aliceInputAmount = BigInt.fromString("15");
let bobInputAmount = BigInt.fromString("10");
let vaultEntityId = Bytes.fromHexString(
"0x1234567890abcdef1234567890abcdef12345678"
);
let event = createAfterClearEvent(
alice,
aliceOutputAmount,
bobOutputAmount,
aliceInputAmount,
bobInputAmount
);
const id1 = tradeVaultBalanceChangeId(event, vaultEntityId);
const id2 = makeClearBountyId(event, vaultEntityId);

assert.assertTrue(id1 !== id2);
});
});

0 comments on commit 34cb5be

Please sign in to comment.