Skip to content

Commit f64b409

Browse files
committed
chore(benchmarks): add redact shield tests
1 parent 8dc0476 commit f64b409

6 files changed

Lines changed: 73 additions & 4 deletions

subgraph/tests/railgun-smart-wallet-shield.test.ts renamed to subgraph/tests/railgun/railgun-smart-wallet-shield.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts";
22
import { assert, describe, test, clearStore, beforeAll, afterAll } from "matchstick-as/assembly/index";
33

4-
import { handleShield } from "../src/railgun/railgun-smart-wallet";
4+
import { handleShield } from "../../src/railgun/railgun-smart-wallet";
55

66
import { createShieldEvent, createCommitmentTuple, createShieldCiphertextTuple } from "./railgun-smart-wallet-utils";
77

subgraph/tests/railgun-smart-wallet-transact.test.ts renamed to subgraph/tests/railgun/railgun-smart-wallet-transact.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BigInt, Bytes } from "@graphprotocol/graph-ts";
22
import { assert, describe, test, clearStore, beforeAll, afterAll } from "matchstick-as/assembly/index";
33

4-
import { handleTransact } from "../src/railgun/railgun-smart-wallet";
4+
import { handleTransact } from "../../src/railgun/railgun-smart-wallet";
55

66
import { createTransactEvent, createTransactCiphertextTuple } from "./railgun-smart-wallet-utils";
77

subgraph/tests/railgun-smart-wallet-unshield.test.ts renamed to subgraph/tests/railgun/railgun-smart-wallet-unshield.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Address, BigInt } from "@graphprotocol/graph-ts";
22
import { assert, describe, test, clearStore, beforeAll, afterAll } from "matchstick-as/assembly/index";
33

4-
import { handleUnshield } from "../src/railgun/railgun-smart-wallet";
4+
import { handleUnshield } from "../../src/railgun/railgun-smart-wallet";
55

66
import { createUnshieldEvent } from "./railgun-smart-wallet-utils";
77

subgraph/tests/railgun-smart-wallet-utils.ts renamed to subgraph/tests/railgun/railgun-smart-wallet-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ethereum, BigInt, Address, Bytes } from "@graphprotocol/graph-ts";
22
import { newMockEvent } from "matchstick-as";
33

4-
import { Shield, Transact, Unshield } from "../generated/RailgunSmartWallet/RailgunSmartWallet";
4+
import { Shield, Transact, Unshield } from "../../generated/RailgunSmartWallet/RailgunSmartWallet";
55

66
export function createShieldEvent(
77
treeNumber: BigInt,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Address, BigInt } from "@graphprotocol/graph-ts";
2+
import { assert, describe, test, clearStore, beforeAll, afterAll } from "matchstick-as/assembly/index";
3+
4+
import { handleShieldedNative } from "../../src/redact/confidential-eth";
5+
6+
import { createShieldedNativeEvent } from "./redact-confidential-eth-utils";
7+
8+
describe("ShieldedNative event tests", () => {
9+
beforeAll(() => {
10+
const event = createShieldedNativeEvent(
11+
Address.fromString("0x0000000000000000000000000000000000000001"),
12+
Address.fromString("0x0000000000000000000000000000000000000002"),
13+
BigInt.fromI32(100),
14+
);
15+
16+
handleShieldedNative(event);
17+
});
18+
19+
afterAll(() => {
20+
clearStore();
21+
});
22+
23+
test("RedactShieldedNative created", () => {
24+
assert.entityCount("RedactShieldedNative", 1);
25+
});
26+
27+
test("RedactShieldedNative values stored correctly", () => {
28+
const id = "0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1";
29+
30+
assert.fieldEquals("RedactShieldedNative", id, "from", "0x0000000000000000000000000000000000000001");
31+
assert.fieldEquals("RedactShieldedNative", id, "to", "0x0000000000000000000000000000000000000002");
32+
assert.fieldEquals("RedactShieldedNative", id, "value", "100");
33+
});
34+
35+
test("Protocol stats updated", () => {
36+
assert.fieldEquals("RedactProtocolStats", "redact-protocol-stats", "totalTxCount", "1");
37+
assert.fieldEquals("RedactProtocolStats", "redact-protocol-stats", "totalGasUsed", "1");
38+
});
39+
40+
test("Operation stats updated (shield-native)", () => {
41+
assert.fieldEquals("RedactOperationStats", "redact-protocol-stats-shield-native", "totalCount", "1");
42+
assert.fieldEquals("RedactOperationStats", "redact-protocol-stats-shield-native", "totalGasUsed", "1");
43+
});
44+
45+
test("Shielded native token stats updated", () => {
46+
const id = "redact-protocol-stats-shield-native";
47+
48+
assert.entityCount("RedactShieldedNativeStats", 1);
49+
assert.fieldEquals("RedactShieldedNativeStats", id, "tokenAddress", "0x0000000000000000000000000000000000000000");
50+
assert.fieldEquals("RedactShieldedNativeStats", id, "totalValue", "100");
51+
assert.fieldEquals("RedactShieldedNativeStats", id, "totalCount", "1");
52+
assert.fieldEquals("RedactShieldedNativeStats", id, "totalGasUsed", "1");
53+
});
54+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ethereum, Address, BigInt } from "@graphprotocol/graph-ts";
2+
import { newMockEvent } from "matchstick-as";
3+
4+
import { ShieldedNative } from "../../generated/ConfidentialETH/ConfidentialETH";
5+
6+
export function createShieldedNativeEvent(from: Address, to: Address, value: BigInt): ShieldedNative {
7+
const event = changetype<ShieldedNative>(newMockEvent());
8+
event.parameters = [];
9+
10+
event.parameters.push(new ethereum.EventParam("from", ethereum.Value.fromAddress(from)));
11+
event.parameters.push(new ethereum.EventParam("to", ethereum.Value.fromAddress(to)));
12+
event.parameters.push(new ethereum.EventParam("value", ethereum.Value.fromUnsignedBigInt(value)));
13+
14+
return event;
15+
}

0 commit comments

Comments
 (0)