diff --git a/.github/workflows/build-test-deploy.yml b/.github/workflows/build-test-deploy.yml index ee070504ef..6da92fe852 100644 --- a/.github/workflows/build-test-deploy.yml +++ b/.github/workflows/build-test-deploy.yml @@ -17,7 +17,6 @@ on: jobs: build-and-test: - if: github.ref != 'refs/heads/staging' runs-on: ubuntu-latest permissions: contents: read diff --git a/packages/agents/lighthouse/src/tasks/prover/operations/process.ts b/packages/agents/lighthouse/src/tasks/prover/operations/process.ts index bfe074de08..4370e11553 100644 --- a/packages/agents/lighthouse/src/tasks/prover/operations/process.ts +++ b/packages/agents/lighthouse/src/tasks/prover/operations/process.ts @@ -215,7 +215,7 @@ export const processMessages = async (brokerMessage: BrokerMessage, _requestCont } // Batch submit messages by destination domain try { - const data = contracts.spokeConnector.encodeFunctionData("proveAndProcess", [ + const proveAndProcessEncodedData = contracts.spokeConnector.encodeFunctionData("proveAndProcess", [ messageProofs, aggregateRoot, messageRootProof, @@ -224,22 +224,11 @@ export const processMessages = async (brokerMessage: BrokerMessage, _requestCont logger.info("Proving and processing messages", requestContext, methodContext, { destinationDomain, - data, - destinationSpokeConnector, - }); - - const proveAndProcessEncodedData = contracts.spokeConnector.encodeFunctionData("proveAndProcess", [ - messageProofs, - aggregateRoot, - messageRootProof, - messageRootIndex, - ]); - - logger.debug("Proving and processing messages", requestContext, methodContext, { provenMessages, proveAndProcessEncodedData, destinationSpokeConnector, }); + const chainId = chainData.get(destinationDomain)!.chainId; /// Temp: Using relayer proxy @@ -252,19 +241,11 @@ export const processMessages = async (brokerMessage: BrokerMessage, _requestCont domain, }); - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - const encodedData = contracts.spokeConnector.encodeFunctionData("proveAndProcess", [ - messageProofs, - aggregateRoot, - messageRootProof, - messageRootIndex, - ]); - const { taskId, relayerType } = await sendWithRelayerWithBackup( chainId, destinationDomain, destinationSpokeConnector, - encodedData, + proveAndProcessEncodedData, relayers, chainreader, logger, diff --git a/packages/agents/lighthouse/test/tasks/prover/operations/process.spec.ts b/packages/agents/lighthouse/test/tasks/prover/operations/process.spec.ts index 3ce44669c1..75ab946d9c 100644 --- a/packages/agents/lighthouse/test/tasks/prover/operations/process.spec.ts +++ b/packages/agents/lighthouse/test/tasks/prover/operations/process.spec.ts @@ -2,7 +2,7 @@ import { expect, createRequestContext, SparseMerkleTree, mkBytes32, XMessage } f import { SinonStub, stub } from "sinon"; import { mock, mockXMessage1, mockXMessage2 } from "../../../mock"; -import { proverCtxMock } from "../../../globalTestHook"; +import { proverCtxMock, sendWithRelayerWithBackupStub } from "../../../globalTestHook"; import { NoDestinationDomainForProof, NoMessageProof } from "../../../../src/errors"; import { BrokerMessage } from "../../../../src/tasks/prover/operations/types"; import { processMessages } from "../../../../src/tasks/prover/operations"; @@ -23,15 +23,24 @@ describe("Operations: Process", () => { describe("#processMessages", () => { let getProofStub: SinonStub; let verifyStub: SinonStub; + let encodeFunctionDataStubMT: SinonStub; + let encodeFunctionDataStubSC: SinonStub; + beforeEach(() => { getProofStub = stub(SparseMerkleTree.prototype, "getProof"); verifyStub = stub(SparseMerkleTree.prototype, "verify"); + encodeFunctionDataStubMT = proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub; + encodeFunctionDataStubSC = proverCtxMock.adapters.contracts.spokeConnector.encodeFunctionData as SinonStub; }); - it("should dedup and be fulfilled", async () => { - getProofStub.resolves(["0x1"]); - verifyStub.resolves({ verified: true }); - (proverCtxMock.adapters.contracts.spokeConnector.encodeFunctionData as SinonStub).returns("0x"); - (proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub).returns("0x"); + + it("happy case should work", async () => { + getProofStub.returns(["0x1"]); + verifyStub.returns({ calculated: "0x", verified: true }); + encodeFunctionDataStubSC.returns("0x"); + encodeFunctionDataStubMT.returns("0x"); + sendWithRelayerWithBackupStub.resolves({ + taskId: "0x123", + }); mockBrokerMesage.messages.push(mockBrokerMesage.messages[0]); mockBrokerMesage.messages.push(mockBrokerMesage.messages[2]); const mockXMessage2: XMessage = { @@ -43,46 +52,53 @@ describe("Operations: Process", () => { mockXMessage2.leaf = mockBrokerMesage.messages[0].leaf; mockBrokerMesage.messages.push(mockXMessage2); await processMessages(mockBrokerMesage, requestContext); - expect(getProofStub.callCount).to.equal(2); + expect(getProofStub.callCount).to.equal(3); + expect(encodeFunctionDataStubSC.callCount).to.equal(1); + expect(sendWithRelayerWithBackupStub).to.have.been.calledOnce; }); it("should be fulfilled", async () => { - getProofStub.resolves(["0x1"]); - verifyStub.resolves({ verified: true }); + getProofStub.returns(["0x1"]); + verifyStub.returns({ verified: true }); (proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub).returns("0x"); await processMessages(mockBrokerMesage, requestContext); }); + it("should catch error if no destination domain proof", async () => { - getProofStub.resolves(["0x1"]); - verifyStub.resolves({ verified: true }); + getProofStub.returns(["0x1"]); + verifyStub.returns({ verified: true }); (proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub).returns("0x"); await expect( processMessages({ ...mockBrokerMesage, destinationDomain: "101010" }, requestContext), ).to.eventually.be.rejectedWith(NoDestinationDomainForProof); }); + it("should catch error if no message proof", async () => { - getProofStub.resolves(undefined); - verifyStub.resolves({ verified: true }); + getProofStub.returns(undefined); + verifyStub.returns({ verified: true }); (proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub).returns("0x"); (proverCtxMock.adapters.contracts.merkleTreeManager.decodeFunctionResult as SinonStub).returns([0]); await expect(processMessages(mockBrokerMesage, requestContext)).to.eventually.be.rejectedWith(NoMessageProof); }); + it("should do nothing if empty message proof", async () => { - getProofStub.resolves(["0x"]); - verifyStub.resolves({ verified: false }); + getProofStub.returns(["0x"]); + verifyStub.returns({ verified: false }); (proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub).returns("0x"); await processMessages(mockBrokerMesage, requestContext); }); + it("should do nothing if already processed", async () => { - getProofStub.resolves(["0x"]); - verifyStub.resolves({ verified: false }); + getProofStub.returns(["0x"]); + verifyStub.returns({ verified: false }); (proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub).returns("0x"); (proverCtxMock.adapters.contracts.merkleTreeManager.decodeFunctionResult as SinonStub).returns([2]); await processMessages(mockBrokerMesage, requestContext); }); + it("should do nothing if status unused", async () => { - getProofStub.resolves(["0x"]); - verifyStub.resolves({ verified: false }); + getProofStub.returns(["0x"]); + verifyStub.returns({ verified: false }); (proverCtxMock.adapters.contracts.merkleTreeManager.encodeFunctionData as SinonStub).returns("0x"); (proverCtxMock.adapters.contracts.merkleTreeManager.decodeFunctionResult as SinonStub).returns([1]); await processMessages(mockBrokerMesage, requestContext);