Skip to content

Commit cefa0cb

Browse files
committed
test: added coverage for missing token gate address in gated DKs
1 parent 700738e commit cefa0cb

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

contracts/test/arbitration/dispute-kit-gated-shutter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
testERC721Gating,
88
testERC1155Gating,
99
testWhitelistIntegration,
10+
testNoTokenGateAddress,
1011
TokenGatedTestContext,
1112
} from "./helpers/dispute-kit-gated-common";
1213
import {
@@ -49,6 +50,7 @@ describe("DisputeKitGatedShutter", async () => {
4950
testERC721Gating(() => tokenContext);
5051
testERC1155Gating(() => tokenContext);
5152
testWhitelistIntegration(() => tokenContext);
53+
testNoTokenGateAddress(() => tokenContext);
5254
});
5355

5456
describe("Shutter Features", async () => {

contracts/test/arbitration/dispute-kit-gated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
testERC721Gating,
88
testERC1155Gating,
99
testWhitelistIntegration,
10+
testNoTokenGateAddress,
1011
TokenGatedTestContext,
1112
} from "./helpers/dispute-kit-gated-common";
1213

@@ -38,4 +39,5 @@ describe("DisputeKitGated", async () => {
3839
testERC721Gating(() => context);
3940
testERC1155Gating(() => context);
4041
testWhitelistIntegration(() => context);
42+
testNoTokenGateAddress(() => context);
4143
});

contracts/test/arbitration/helpers/dispute-kit-gated-common.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,82 @@ export function testWhitelistIntegration(context: () => TokenGatedTestContext) {
623623
});
624624
});
625625
}
626+
627+
export function testNoTokenGateAddress(context: () => TokenGatedTestContext) {
628+
describe("No Token Gate Edge Case (address(0))", async () => {
629+
it("Should verify that address(0) is supported by default", async () => {
630+
const ctx = context();
631+
await expectTokenSupported(ctx, ethers.ZeroAddress, true);
632+
});
633+
634+
it("Should allow dispute creation with address(0) as tokenGate", async () => {
635+
const ctx = context();
636+
// Create dispute with address(0) as tokenGate - should not revert
637+
await expect(createDisputeWithToken(ctx, ethers.ZeroAddress, false, 0)).to.not.be.reverted;
638+
});
639+
640+
it("Should draw all staked jurors when tokenGate is address(0)", async () => {
641+
const ctx = context();
642+
// Neither juror has any special tokens, but both are staked
643+
const nbOfJurors = 15n;
644+
const tx = await stakeAndDraw(
645+
ctx,
646+
Courts.GENERAL,
647+
nbOfJurors,
648+
ctx.gatedDisputeKitID,
649+
ethers.ZeroAddress,
650+
false,
651+
0
652+
).then((tx) => tx.wait());
653+
654+
// Both jurors should be eligible for drawing since there's no token gate
655+
const drawLogs =
656+
tx?.logs.filter((log: any) => log.fragment?.name === "Draw" && log.address === ctx.core.target) || [];
657+
expect(drawLogs.length).to.equal(nbOfJurors);
658+
659+
// Verify that draws include both jurors (not just one)
660+
const drawnJurors = new Set(drawLogs.map((log: any) => log.args[0]));
661+
expect(drawnJurors.size).to.be.greaterThan(1, "Should draw from multiple jurors");
662+
});
663+
664+
it("Should behave like non-gated dispute kit when tokenGate is address(0)", async () => {
665+
const ctx = context();
666+
// Verify that with address(0), jurors don't need any token balance
667+
const nbOfJurors = 3n;
668+
669+
// Ensure jurors have no DAI tokens
670+
expect(await ctx.dai.balanceOf(ctx.juror1.address)).to.equal(0);
671+
expect(await ctx.dai.balanceOf(ctx.juror2.address)).to.equal(0);
672+
673+
const tx = await stakeAndDraw(
674+
ctx,
675+
Courts.GENERAL,
676+
nbOfJurors,
677+
ctx.gatedDisputeKitID,
678+
ethers.ZeroAddress,
679+
false,
680+
0
681+
).then((tx) => tx.wait());
682+
683+
// Jurors should still be drawn despite having no tokens
684+
const drawLogs =
685+
tx?.logs.filter((log: any) => log.fragment?.name === "Draw" && log.address === ctx.core.target) || [];
686+
expect(drawLogs).to.have.length(nbOfJurors);
687+
});
688+
689+
it("Should parse address(0) correctly from insufficient extraData", async () => {
690+
const ctx = context();
691+
// Create extraData that's too short (less than 160 bytes)
692+
// This should return address(0) from _extraDataToTokenInfo
693+
const shortExtraData = ethers.AbiCoder.defaultAbiCoder().encode(
694+
["uint256", "uint256", "uint256"],
695+
[Courts.GENERAL, 3, ctx.gatedDisputeKitID]
696+
);
697+
698+
const tokenInfo = await ctx.disputeKit.extraDataToTokenInfo(shortExtraData);
699+
expect(tokenInfo[0]).to.equal(ethers.ZeroAddress);
700+
expect(tokenInfo[1]).to.equal(false);
701+
expect(tokenInfo[2]).to.equal(0);
702+
});
703+
});
704+
}

0 commit comments

Comments
 (0)