Skip to content

Commit

Permalink
fix: more test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jahabeebs committed Nov 30, 2024
1 parent 432a086 commit d801176
Showing 1 changed file with 112 additions and 65 deletions.
177 changes: 112 additions & 65 deletions apps/agent/test/e2e/scenarios/01_happy_path/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { ChildProcessWithoutNullStreams } from "child_process";
import fs from "fs";
import path from "path";
import { oracleAbi, ProphetCodec, ProtocolProvider } from "@ebo-agent/automated-dispute";
import { RequestId } from "@ebo-agent/automated-dispute/dist/types/prophet.js";
import { bondEscalationModuleAbi } from "@ebo-agent/automated-dispute/src/abis/index.js";
import { NullNotificationService } from "@ebo-agent/automated-dispute/src/index.js";
import { ResponseId } from "@ebo-agent/automated-dispute/src/types/index.js";
import { RequestId, ResponseId } from "@ebo-agent/automated-dispute/src/types/index.js";
import { BlockNumberService } from "@ebo-agent/blocknumber";
import { Caip2ChainId, Logger } from "@ebo-agent/shared";
import { CreateServerReturnType } from "prool";
Expand Down Expand Up @@ -106,7 +105,6 @@ describe.sequential("single agent", () => {
});

beforeEach(async () => {
Logger.getInstance();
Logger.getInstance();
l2ProtocolAnvil = await createAnvilServer(
PROTOCOL_L2_LOCAL_RPC_HOST,
Expand Down Expand Up @@ -416,6 +414,8 @@ describe.sequential("single agent", () => {
notifier,
);

console.log("blockNumberService", blockNumberService);

const protocolProvider = new ProtocolProvider(
{
l1: {
Expand Down Expand Up @@ -450,6 +450,8 @@ describe.sequential("single agent", () => {
blockNumberService,
);

console.log("protocolProvider", protocolProvider);

const anvilClient = createTestClient({
mode: "anvil",
account: GRT_HOLDER,
Expand All @@ -470,8 +472,11 @@ describe.sequential("single agent", () => {
const initBlock = await anvilClient.getBlockNumber();
const currentEpoch = await protocolProvider.getCurrentEpoch();

console.log("currentEpoch", currentEpoch);
console.log("initBlock", initBlock);

const accessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
user: accounts[0].account.address as Address,
data: "0x" as Address,
};

Expand All @@ -494,11 +499,16 @@ describe.sequential("single agent", () => {
throw new Error("RequestCreated event not found");
}

console.log(requestCreatedEvent, "requestCreatedEvent");
console.log(currentEpoch.startTimestamp, "currentEpoch.startTimestamp");

const correctResponse = await blockNumberService.getEpochBlockNumber(
currentEpoch.startTimestamp,
PROTOCOL_L2_CHAIN_ID,
);

console.log("correctResponse", correctResponse);

// A1 proposes a response RESP1(REQ1)
await protocolProvider.proposeResponse(
requestCreatedEvent.args._request,
Expand All @@ -522,16 +532,85 @@ describe.sequential("single agent", () => {
blockTimeout: initBlock + 1000n,
});

console.log("badResponseProposedEvent", badResponseProposedEvent);
console.log(accounts[0].account.address, "accounts[0].account.address");

if (badResponseProposedEvent === undefined) {
throw new Error("ResponseProposed event not found");
}

// Define accessControl for Agent A1
const agentAccessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
user: accounts[0].account.address as Address,
data: "0x" as Address,
};

agent = spawnAgent({
configPath: tmpConfigFile,
config: {
protocolProvider: {
contracts: {
oracle: protocolContracts["Oracle"] as Address,
bondEscalationModule: protocolContracts["BondEscalationModule"] as Address,
eboRequestCreator: protocolContracts["EBORequestCreator"] as Address,
horizonAccountingExtension: protocolContracts[
"HorizonAccountingExtension"
] as Address,
epochManager: EPOCH_MANAGER_ADDRESS,
horizonStaking: HORIZON_STAKING_ADDRESS,
},
rpcsConfig: {
l1: {
chainId: PROTOCOL_L2_CHAIN_ID,
transactionReceiptConfirmations: 1,
timeout: 1_000,
retryInterval: 500,
},
l2: {
chainId: PROTOCOL_L2_CHAIN_ID,
transactionReceiptConfirmations: 1,
timeout: 1_000,
retryInterval: 500,
},
},
},
blockNumberService: {
blockmetaConfig: {
baseUrl: new URL("http://not.needed/"),
bearerTokenExpirationWindow: 1000,
servicePaths: {
block: "/block",
blockByTime: "/blockByTime",
},
},
},
processor: {
accountingModules: {
responseModule: protocolContracts["BondedResponseModule"] as Address,
escalationModule: protocolContracts["BondEscalationModule"] as Address,
},
msBetweenChecks: 3000,
},
},
env: {
PROTOCOL_PROVIDER_PRIVATE_KEY: accounts[0].privateKey,
PROTOCOL_PROVIDER_L1_RPC_URLS: [PROTOCOL_L2_LOCAL_URL],
// Using the same RPC due to Anvil's arbitrum block number bug
PROTOCOL_PROVIDER_L2_RPC_URLS: [PROTOCOL_L2_LOCAL_URL],
BLOCK_NUMBER_BLOCKMETA_TOKEN: "not.needed",
BLOCK_NUMBER_RPC_URLS_MAP: new Map<Caip2ChainId, string[]>([
[PROTOCOL_L2_CHAIN_ID, [PROTOCOL_L2_LOCAL_URL]],
]),
},
});

console.log("disputing response");
console.log(requestCreatedEvent.args._request, "requestCreatedEvent.args._request");
console.log(
badResponseProposedEvent.args._response,
"badResponseProposedEvent.args._response",
);

// A1 disputes RESP1 with DISP1 and provides accessControl
await protocolProvider.disputeResponse(
requestCreatedEvent.args._request,
Expand Down Expand Up @@ -560,64 +639,13 @@ describe.sequential("single agent", () => {
blockTimeout: initBlock + 1000n,
});

console.log("badResponseDisputedEvent", badResponseDisputedEvent);

expect(badResponseDisputedEvent).toBeDefined();
if (badResponseDisputedEvent === undefined) {
throw new Error("ResponseDisputed event not found");
}

// Instantiate ProtocolProvider for Account2
const protocolProviderAccount2 = new ProtocolProvider(
{
l1: {
chainId: PROTOCOL_L2_CHAIN_ID,
urls: [PROTOCOL_L2_LOCAL_URL],
transactionReceiptConfirmations: 1,
timeout: 1_000,
retryInterval: 500,
},
l2: {
chainId: PROTOCOL_L2_CHAIN_ID,
urls: [PROTOCOL_L2_LOCAL_URL],
transactionReceiptConfirmations: 1,
timeout: 1_000,
retryInterval: 500,
},
},
{
bondEscalationModule: protocolContracts["BondEscalationModule"] as Address,
eboRequestCreator: protocolContracts["EBORequestCreator"] as Address,
epochManager: EPOCH_MANAGER_ADDRESS,
oracle: protocolContracts["Oracle"] as Address,
horizonAccountingExtension: protocolContracts[
"HorizonAccountingExtension"
] as Address,
horizonStaking: HORIZON_STAKING_ADDRESS,
},
accounts[1].privateKey,
undefined,
logger,
blockNumberService,
);

// Define accessControl for Account2
const account2AccessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
data: "0x" as Address,
};

// Account2 disputes RESP1, creating DISP1
await protocolProviderAccount2.disputeResponse(
requestCreatedEvent.args._request,
badResponseProposedEvent.args._response,
{
disputer: accounts[1].account.address,
proposer: accounts[0].account.address,
responseId: badResponseProposedEvent.args._responseId as ResponseId,
requestId: requestCreatedEvent.args._requestId as RequestId,
},
account2AccessControl,
);

// A1 proposes a correct response RESP2
await protocolProvider.proposeResponse(
requestCreatedEvent.args._request,
Expand All @@ -629,6 +657,8 @@ describe.sequential("single agent", () => {
agentAccessControl,
);

console.log("correctResponse", correctResponse);

const correctResponseProposedEvent = await waitForEvent({
client: anvilClient,
filter: {
Expand All @@ -652,12 +682,17 @@ describe.sequential("single agent", () => {
blockTimeout: initBlock + 1000n,
});

console.log("correctResponseProposedEvent", correctResponseProposedEvent);

expect(correctResponseProposedEvent).toBeDefined();
if (correctResponseProposedEvent === undefined) {
throw new Error("CorrectResponseProposed event not found");
}

console.log("Advancing blockchain time by 4 weeks to trigger settlement...");
await anvilClient.increaseTime({ seconds: 60 * 60 * 24 * 7 * 4 });
await anvilClient.mine({ blocks: 1 });
console.log("Blockchain time advanced.");

const disputeSettledEvent = await waitForEvent({
client: anvilClient,
Expand All @@ -668,6 +703,11 @@ describe.sequential("single agent", () => {
strict: true,
},
matcher: (log) => {
console.log(log, "log");
console.log(log.args._status, "log.args._status");
console.log(ProphetCodec.decodeDisputeStatus(log.args._status), "decoded status");
console.log(log.args._disputeId, "log.args._disputeId");

const status = ProphetCodec.decodeDisputeStatus(log.args._status);

return (
Expand All @@ -679,6 +719,8 @@ describe.sequential("single agent", () => {
blockTimeout: initBlock + 1000n,
});

console.log("disputeSettledEvent", disputeSettledEvent);

expect(disputeSettledEvent).toBeDefined();

const [requestFinalizedEvent, newEpochEventFinal] = await Promise.all([
Expand Down Expand Up @@ -709,8 +751,13 @@ describe.sequential("single agent", () => {
},
matcher: (log) => {
return (
console.log(log.args._chainId, "log.args._chainId"),
console.log(
keccak256(toHex(ARBITRUM_SEPOLIA_ID)),
"keccak256(toHex(ARBITRUM_SEPOLIA_ID))",
),
log.args._chainId === keccak256(toHex(ARBITRUM_SEPOLIA_ID)) &&
log.args._epoch === currentEpoch.number
log.args._epoch === currentEpoch.number
);
},
pollingIntervalMs: 100,
Expand Down Expand Up @@ -820,7 +867,7 @@ describe.sequential("single agent", () => {
const currentEpoch = await protocolProvider.getCurrentEpoch();

const accessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
user: accounts[0].account.address as Address,
data: "0x" as Address,
};

Expand Down Expand Up @@ -881,7 +928,7 @@ describe.sequential("single agent", () => {

// Define accessControl for Account2
const account2AccessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
user: accounts[0].account.address as Address,
data: "0x" as Address,
};

Expand Down Expand Up @@ -1027,7 +1074,7 @@ describe.sequential("single agent", () => {

// Define accessControl for escalation
const escalationAccessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
user: accounts[0].account.address as Address,
data: "0x" as Address,
};

Expand Down Expand Up @@ -1193,7 +1240,7 @@ describe.sequential("single agent", () => {

// Define accessControl as required by the updated ProtocolProvider methods
const accessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
user: accounts[0].account.address as Address,
data: "0x" as Address,
};

Expand Down Expand Up @@ -1257,7 +1304,7 @@ describe.sequential("single agent", () => {

// Define accessControl for Account2
const account2AccessControl = {
user: "0x000000000000000000000000000000000000000",
user: accounts[0].account.address,
data: "0x",
};

Expand Down Expand Up @@ -1393,7 +1440,7 @@ describe.sequential("single agent", () => {

// Define accessControl for escalation
const escalationAccessControl = {
user: "0x000000000000000000000000000000000000000" as Address,
user: accounts[0].account.address as Address,
data: "0x" as Address,
};

Expand Down

0 comments on commit d801176

Please sign in to comment.