Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: e2e dispute #72

Merged
merged 22 commits into from
Oct 25, 2024
Merged

test: e2e dispute #72

merged 22 commits into from
Oct 25, 2024

Conversation

0xyaco
Copy link
Collaborator

@0xyaco 0xyaco commented Oct 24, 2024

🤖 Linear

Closes GRT-192, GRT-216

Description

  • Test agent reaction to wrong response

Miscelanous fixes:

  • Improve waitForEvent E2E testing util to return the found event
  • Move dispute status mapping into ProphetCodec class
  • Normalize all IDs read from events as soon as they are fetched
  • Fix dispute settling errors not being handled correctly (thus not escalating if needed)
  • Fix proposing a new response when the active response has been disputed

Copy link

linear bot commented Oct 24, 2024

@0xyaco 0xyaco force-pushed the test/e2e-scenario-2 branch from 4a6d0da to c8b7399 Compare October 25, 2024 09:15
Copy link

linear bot commented Oct 25, 2024

Base automatically changed from fix/e2e-scenario-1 to dev October 25, 2024 13:49
Copy link
Collaborator

@jahabeebs jahabeebs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple comments 👍🏻

* When:
* - A1 detects RESP1 is wrong
*
* Then:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice explanation

* - `EBOFinalityModule.newEpoch(E1, CHAIN1, RESP2.response)`
* - `OracleRequestFinalized(REQ1.id, RESP2.id, A1.address)`
*/
test.skip("dispute response and propose a new one", { timeout: E2E_TEST_TIMEOUT }, async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the test be enabled later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the idea is to enable every test to be run sequentially later

* @param status - The uint8 value representing the dispute status.
* @returns The DisputeStatus string corresponding to the input value.
*/
private mapDisputeStatus(status: number): DisputeStatus {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@@ -343,6 +333,44 @@ export class EboActor {
await Promise.all(settledDisputes);
}

private getFinalizableResponse(request: Request, atTimestamp: UnixTimestamp) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe docs here?

return this.getAcceptedResponse(atTimestamp);
}

private async finalizeRequest(request: Request, response: Response) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe docs here?

await this.protocolProvider.finalize(request.prophetData, response.prophetData);
} catch (err) {
if (err instanceof CustomContractError) {
err.setContext({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed in getActiveDisputes you have a this.logger.warn in the catch but not here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a warn here too!

const events = await this.getEvents(this.lastCheckedBlock, lastBlock.number);

// Events will sync starting from the block after the last checked one,
// making the block interval exclusive on its lower bound:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclusive of*
exclusive on means it's included

Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful, few comments but nothing critical. after addressing beebs comments is good to go to me

Q: HexUtils.normalize is removed in many places, this is no longer required?

Comment on lines -677 to +730
responseId: HexUtils.normalize(event.metadata.responseId) as ResponseId,
responseId: event.metadata.responseId,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just double check that normalizing is no longer required

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thing to ask! The main idea of this change is to apply HexUtils.normalize only during functions that fetch events. Starting from that point, the app will always work with already normalized ids.

I've actually grep'd any as (RequestId |ResponseId |DisputeId) to remove any forced casting, keeping only the ones in methods used within ProtocolProvider.getEvent

Comment on lines 819 to 842
const operations = await Promise.allSettled([
this.pledgeFor(request, dispute),
(async () => {
try {
const { chainId } = request.decodedData.requestModuleData;

await this.proposeResponse(chainId);
} catch (err) {
if (err instanceof ResponseAlreadyProposed) {
this.logger.warn(err.message);
} else {
this.logger.error(
`Could not propose a new response after response ${proposedResponse.id} disputal.`,
);

throw err;
}
}
})(),
]);

operations.forEach((element) => {
if (element.status === "rejected") throw element.reason;
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're throwing on 'rejected', there's no benefit on doing Promise.allSettled unless we require that Promises are all fulfilled

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random fact: Viem has this stringify implemented

jahabeebs
jahabeebs previously approved these changes Oct 25, 2024
@0xyaco 0xyaco merged commit f6379bf into dev Oct 25, 2024
5 checks passed
@0xyaco 0xyaco deleted the test/e2e-scenario-2 branch October 25, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants