diff --git a/test/unit/attesters/hydra-s1/hydra-s1-accountbound-attester.test.ts b/test/unit/attesters/hydra-s1/hydra-s1-accountbound-attester.test.ts index 616f070..d303900 100644 --- a/test/unit/attesters/hydra-s1/hydra-s1-accountbound-attester.test.ts +++ b/test/unit/attesters/hydra-s1/hydra-s1-accountbound-attester.test.ts @@ -253,9 +253,12 @@ describe('Test HydraS1 Accountbound Attester contract', () => { expect(buildAttestations[0].issuer).to.eql(hydraS1AccountboundAttester.address); expect(buildAttestations[0].value.toNumber()).to.eql(sourceValue.toNumber()); expect(buildAttestations[0].timestamp).to.eql(group.properties.generationTimestamp); - expect( - utils.defaultAbiCoder.decode(['bytes', 'uint16'], buildAttestations[0].extraData) - ).to.eql([BigNumber.from(inputs.publicInputs.nullifier)._hex, 0]); + expect(buildAttestations[0].extraData).to.eql( + encodeAccountBoundAttestationExtraData({ + nullifier: inputs.publicInputs.nullifier, + burnCount: 0, + }) + ); }); }); @@ -562,13 +565,6 @@ describe('Test HydraS1 Accountbound Attester contract', () => { const generateAttestationsTransaction = await hydraS1AccountboundAttester.generateAttestations(request, proof.toBytes()); - const attestationsExtraData = await attestationsRegistry.getAttestationExtraData( - ( - await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST() - ).add(group.properties.groupIndex), - request.destination - ); - // 0 - Checks that the transaction emitted the event await expect(generateAttestationsTransaction) .to.emit(hydraS1AccountboundAttester, 'AttestationGenerated') @@ -580,7 +576,10 @@ describe('Test HydraS1 Accountbound Attester contract', () => { hydraS1AccountboundAttester.address, sourceValue, group.properties.generationTimestamp, - attestationsExtraData, + encodeAccountBoundAttestationExtraData({ + nullifier: inputs.publicInputs.nullifier, + burnCount: 0, + }), ]); // 1 - Checks that the provided nullifier was successfully recorded in the attester @@ -621,12 +620,12 @@ describe('Test HydraS1 Accountbound Attester contract', () => { destinationSigner.address ); - // expect(attestationExtraData).to.be.eql( - // encodeAccountBoundAttestationExtraData({ - // nullifier: inputs.publicInputs.nullifier, - // burnCount: 0, - // }) - // ); + expect(attestationExtraData).to.be.eql( + encodeAccountBoundAttestationExtraData({ + nullifier: inputs.publicInputs.nullifier, + burnCount: 0, + }) + ); expect( await hydraS1AccountboundAttester.getNullifierFromExtraData( @@ -686,14 +685,6 @@ describe('Test HydraS1 Accountbound Attester contract', () => { const generateAttestationsTransaction = await hydraS1AccountboundAttester.generateAttestations(newRequest, newProof.toBytes()); - // burnCount should be recorded in the attestationsRegistry - const attestationsExtraData = await attestationsRegistry.getAttestationExtraData( - ( - await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST() - ).add(group.properties.groupIndex), - newRequest.destination - ); - // 0 - Checks that the transaction emitted the event await expect(generateAttestationsTransaction) .to.emit(hydraS1AccountboundAttester, 'AttestationGenerated') @@ -705,7 +696,10 @@ describe('Test HydraS1 Accountbound Attester contract', () => { hydraS1AccountboundAttester.address, sourceValue, group.properties.generationTimestamp, - attestationsExtraData, + encodeAccountBoundAttestationExtraData({ + nullifier: inputs.publicInputs.nullifier, + burnCount: 1, // burn count should be incremented + }), ]); await expect(generateAttestationsTransaction) .to.emit(hydraS1AccountboundAttester, 'NullifierDestinationUpdated') @@ -733,10 +727,20 @@ describe('Test HydraS1 Accountbound Attester contract', () => { ) ).to.be.eql(1); // the burnCount should be incremented - expect(utils.defaultAbiCoder.decode(['bytes', 'uint16'], attestationsExtraData)).to.eql([ - BigNumber.from(inputs.publicInputs.nullifier)._hex, - 1, - ]); + // burnCount should be recorded in the attestationsRegistry + expect( + await attestationsRegistry.getAttestationExtraData( + ( + await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST() + ).add(group.properties.groupIndex), + destination2Signer.address + ) + ).to.equal( + encodeAccountBoundAttestationExtraData({ + nullifier: inputs.publicInputs.nullifier, + burnCount: 1, // burnCount should be incremented + }) + ); // 2 - Checks that the attester unrecorded & rerecorded the attestation in the registry // 2.1 - Checks that the old destination has not anymore it's attestation expect( @@ -821,13 +825,6 @@ describe('Test HydraS1 Accountbound Attester contract', () => { const generateAttestationsTransaction = await hydraS1AccountboundAttester.generateAttestations(renewRequest, renewProof.toBytes()); - const attestationsExtraData = await attestationsRegistry.getAttestationExtraData( - ( - await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST() - ).add(group.properties.groupIndex), - renewRequest.destination - ); - // 0 - Checks that the transaction emitted the event with the new timestamp await expect(generateAttestationsTransaction) .to.emit(hydraS1AccountboundAttester, 'AttestationGenerated') @@ -839,7 +836,10 @@ describe('Test HydraS1 Accountbound Attester contract', () => { hydraS1AccountboundAttester.address, sourceValue, renewGenerationTimestamp, - attestationsExtraData, + encodeAccountBoundAttestationExtraData({ + nullifier: inputs.publicInputs.nullifier, + burnCount: 1, + }), ]); // A renew should not have changed the nullifierData @@ -912,13 +912,6 @@ describe('Test HydraS1 Accountbound Attester contract', () => { const generateAttestationsTransaction = await hydraS1AccountboundAttester.generateAttestations(renewRequest, renewProof.toBytes()); - const attestationsExtraData = await attestationsRegistry.getAttestationExtraData( - ( - await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST() - ).add(group.properties.groupIndex), - renewRequest.destination - ); - // Checks that the transaction emitted the event with a claimedValue of zero await expect(generateAttestationsTransaction) .to.emit(hydraS1AccountboundAttester, 'AttestationGenerated') @@ -930,7 +923,10 @@ describe('Test HydraS1 Accountbound Attester contract', () => { hydraS1AccountboundAttester.address, 0, // claimedValue group.properties.generationTimestamp, - attestationsExtraData, + encodeAccountBoundAttestationExtraData({ + nullifier: inputs.publicInputs.nullifier, + burnCount: 1, + }), ]); // Checks that the attestation in the registry has a value of zero diff --git a/test/utils/hydra-s1-accountbound.ts b/test/utils/hydra-s1-accountbound.ts index e59166d..65250a6 100644 --- a/test/utils/hydra-s1-accountbound.ts +++ b/test/utils/hydra-s1-accountbound.ts @@ -121,5 +121,8 @@ export const encodeAccountBoundAttestationExtraData = ({ nullifier: BigNumberish | BigInt; burnCount: number; }) => { - return ethers.utils.solidityPack(['uint256', 'uint16'], [nullifier, burnCount]); + return ethers.utils.defaultAbiCoder.encode( + ['bytes', 'uint16'], + [ethers.utils.defaultAbiCoder.encode(['uint256'], [nullifier]), burnCount] + ); };