Skip to content

Commit

Permalink
fix: resume ci build and test
Browse files Browse the repository at this point in the history
  • Loading branch information
preethamr committed Oct 10, 2023
1 parent 890bf0c commit d32ca94
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ on:

jobs:
build-and-test:
if: github.ref != 'refs/heads/staging'
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
25 changes: 3 additions & 22 deletions packages/agents/lighthouse/src/tasks/prover/operations/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 = {
Expand All @@ -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);
Expand Down

0 comments on commit d32ca94

Please sign in to comment.