@@ -731,26 +731,31 @@ export function testRecoveryFlowJurorReveals(context: () => ShutterTestContext)
731731
732732export function testHashFunctionBehavior ( context : ( ) => ShutterTestContext ) {
733733 describe ( "Hash Function Behavior" , ( ) => {
734- it ( "Should return different hashes for juror vs non-juror callers " , async ( ) => {
734+ it ( "Should compute different hashes for juror recovery vs non-juror normal flow " , async ( ) => {
735735 const ctx = context ( ) ;
736- const disputeId = await createDisputeAndDraw ( ctx , ctx . shutterCourtID , 3 , ctx . shutterDKID ) ;
737- await advanceToCommitPeriod ( ctx , disputeId ) ;
738736
739- const voteIDs = await getVoteIDsForJuror ( ctx , disputeId , ctx . juror1 ) ;
737+ // Test 1: Verify hashVote matches generateCommitments for non-juror case
740738 const { fullCommit, recoveryCommit } = generateCommitments ( ctx . choice , ctx . salt , ctx . justification ) ;
739+ const nonJurorHash = await ctx . disputeKit . hashVote ( ctx . choice , ctx . salt , ctx . justification ) ;
740+ expect ( nonJurorHash ) . to . equal ( fullCommit , "Non-juror hash should match full commitment" ) ;
741741
742- await ctx . disputeKit
743- . connect ( ctx . juror1 )
744- . castCommitShutter ( disputeId , voteIDs , fullCommit , recoveryCommit , ctx . identity , ctx . encryptedVote ) ;
742+ // Test 2: Verify the two commitment types are different
743+ expect ( fullCommit ) . to . not . equal ( recoveryCommit , "Full and recovery commitments should differ" ) ;
745744
746- await advanceToVotePeriod ( ctx , disputeId ) ;
745+ // Test 3: Calculate what the juror hash would be and verify it matches recovery commitment
746+ const jurorExpectedHash = ethers . keccak256 (
747+ ethers . AbiCoder . defaultAbiCoder ( ) . encode ( [ "uint256" , "uint256" ] , [ ctx . choice , ctx . salt ] )
748+ ) ;
749+ expect ( jurorExpectedHash ) . to . equal ( recoveryCommit , "Juror hash calculation should match recovery commitment" ) ;
747750
748- // During castVoteShutter, the contract should use different hash logic
749- // For juror: hash(choice, salt)
750- // For non-juror: hash(choice, salt, justificationHash)
751+ // Test 4: Verify that changing justification affects non-juror hash but not juror hash
752+ const differentJustification = "Different justification" ;
753+ const { fullCommit : newFullCommit } = generateCommitments ( ctx . choice , ctx . salt , differentJustification ) ;
754+ const newNonJurorHash = await ctx . disputeKit . hashVote ( ctx . choice , ctx . salt , differentJustification ) ;
751755
752- // This is tested implicitly by the recovery flow tests above
753- // The juror can reveal with any justification, while non-juror must provide exact justification
756+ expect ( newNonJurorHash ) . to . equal ( newFullCommit , "New non-juror hash should match new full commitment" ) ;
757+ expect ( newNonJurorHash ) . to . not . equal ( nonJurorHash , "Non-juror hash should change with justification" ) ;
758+ // Note: juror hash would remain the same (recoveryCommit) regardless of justification
754759 } ) ;
755760
756761 it ( "Should correctly compute hash for normal flow" , async ( ) => {
0 commit comments