From e5cbbaafec6a10db7f16c4f7df93c44bae8d5118 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 7 Feb 2024 11:48:53 -0300 Subject: [PATCH] fix: Parse instance deployed event --- .../fixtures/ContractInstanceDeployedEventData.hex | 1 + .../contract_instance_deployed_event.test.ts | 13 +++++++++++++ .../contract/contract_instance_deployed_event.ts | 2 +- yarn-project/circuits.js/src/tests/fixtures.ts | 6 ++++++ .../end-to-end/src/e2e_deploy_contract.test.ts | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 yarn-project/circuits.js/fixtures/ContractInstanceDeployedEventData.hex create mode 100644 yarn-project/circuits.js/src/contract/contract_instance_deployed_event.test.ts diff --git a/yarn-project/circuits.js/fixtures/ContractInstanceDeployedEventData.hex b/yarn-project/circuits.js/fixtures/ContractInstanceDeployedEventData.hex new file mode 100644 index 00000000000..225f04bb119 --- /dev/null +++ b/yarn-project/circuits.js/fixtures/ContractInstanceDeployedEventData.hex @@ -0,0 +1 @@ +0000000085864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631173b1e288f0f29f945ffa7b4ec2b69393e32b78501d0f193288e4a886a9f6e18000000000000000000000000000000000000000000000000000000000000000113554cdde23fee1efdb34bb3f685929e9098b8328083970984754948007e11ea0798434d6f2adf997c4fe3d14cb8468aa3cbf7a70d8c499c3c775fc8feff67960f68e30db11bc73392acfc02600ad1177cbe0d17cbbb5d3086a592b736f414a8000000000000000000000000507a47e77fc808e31716c47865eb372b2a487b7505331ff473c938df8b7a6dba01cf45bd6b029d4aeeff7e76953b31ef2510f7b80000000000000000000000000000000000000000000000000000000000000000 \ No newline at end of file diff --git a/yarn-project/circuits.js/src/contract/contract_instance_deployed_event.test.ts b/yarn-project/circuits.js/src/contract/contract_instance_deployed_event.test.ts new file mode 100644 index 00000000000..c7081791b4c --- /dev/null +++ b/yarn-project/circuits.js/src/contract/contract_instance_deployed_event.test.ts @@ -0,0 +1,13 @@ +import { getSampleContractInstanceDeployedEventPayload } from '../tests/fixtures.js'; +import { ContractInstanceDeployedEvent } from './contract_instance_deployed_event.js'; + +describe('ContractInstanceDeployedEvent', () => { + it('parses an event as emitted by the ClassInstanceDeployer', () => { + const data = getSampleContractInstanceDeployedEventPayload(); + const event = ContractInstanceDeployedEvent.fromLogData(data); + expect(event.address.toString()).toEqual('0x173b1e288f0f29f945ffa7b4ec2b69393e32b78501d0f193288e4a886a9f6e18'); + expect(event.contractClassId.toString()).toEqual( + '0x0798434d6f2adf997c4fe3d14cb8468aa3cbf7a70d8c499c3c775fc8feff6796', + ); + }); +}); diff --git a/yarn-project/circuits.js/src/contract/contract_instance_deployed_event.ts b/yarn-project/circuits.js/src/contract/contract_instance_deployed_event.ts index 134b24034b8..45af7ba5187 100644 --- a/yarn-project/circuits.js/src/contract/contract_instance_deployed_event.ts +++ b/yarn-project/circuits.js/src/contract/contract_instance_deployed_event.ts @@ -34,7 +34,7 @@ export class ContractInstanceDeployedEvent { const salt = reader.readObject(Fr); const contractClassId = reader.readObject(Fr); const initializationHash = reader.readObject(Fr); - const portalContractAddress = reader.readObject(EthAddress); + const portalContractAddress = EthAddress.fromField(reader.readObject(Fr)); const publicKeysHash = reader.readObject(Fr); const universalDeploy = reader.readObject(Fr).toBool(); diff --git a/yarn-project/circuits.js/src/tests/fixtures.ts b/yarn-project/circuits.js/src/tests/fixtures.ts index c65e4787b39..ceb6611d394 100644 --- a/yarn-project/circuits.js/src/tests/fixtures.ts +++ b/yarn-project/circuits.js/src/tests/fixtures.ts @@ -19,6 +19,12 @@ export function getSampleContractClassRegisteredEventPayload(): Buffer { return Buffer.from(readFileSync(path).toString(), 'hex'); } +// Copied from the test 'deploying a contract instance' in end-to-end/src/e2e_deploy_contract.test.ts +export function getSampleContractInstanceDeployedEventPayload(): Buffer { + const path = getPathToFixture('ContractInstanceDeployedEventData.hex'); + return Buffer.from(readFileSync(path).toString(), 'hex'); +} + function getPathToFixture(name: string) { return resolve(dirname(fileURLToPath(import.meta.url)), `../../fixtures/${name}`); } diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index 86ec59834c1..5ce51a687fe 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -407,6 +407,9 @@ describe('e2e_deploy_contract', () => { const publicKeysHash = computePublicKeysHash(publicKey); instance = getContractInstanceFromDeployParams(artifact, initArgs, salt, publicKey, portalAddress); + logger( + `Deploying contract instance at ${instance.address.toString()} with class id ${instance.contractClassId.toString()}`, + ); const tx = await deployer.methods .deploy(salt, contractClass.id, instance.initializationHash, portalAddress, publicKeysHash, false) .send()