diff --git a/apps/cli/src/baseCommand.ts b/apps/cli/src/baseCommand.ts index 10faebdb..b01c4457 100644 --- a/apps/cli/src/baseCommand.ts +++ b/apps/cli/src/baseCommand.ts @@ -3,7 +3,7 @@ import chalk from "chalk"; import { execa } from "execa"; import fs from "fs"; import path from "path"; -import { Address, Hash, isHash } from "viem"; +import { Address, Hash, getAddress, isHash } from "viem"; import { authorityHistoryPairFactoryAddress, @@ -26,14 +26,7 @@ export type Flags = Interfaces.InferredFlags< (typeof BaseCommand)["baseFlags"] & T["flags"] >; export type Args = Interfaces.InferredArgs; - export type AddressBook = Record; -export interface DApp { - address: Address; - blockHash: Address; - blockNumber: number; - transactionHash: Address; -} export abstract class BaseCommand extends Command { protected flags!: Flags; @@ -77,15 +70,18 @@ export abstract class BaseCommand extends Command { this.log(`${chalk.green("?")} ${title} ${chalk.cyan(value)}`); } - protected async getApplicationAddress(): Promise
{ + protected async getApplicationAddress(): Promise
{ // fixed value, as we do deterministic deployment with a zero hash - return "0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e"; + return getAddress("0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e"); } protected async getAddressBook(): Promise { + const applicationAddress = await this.getApplicationAddress(); + // build rollups contracts address book const contracts: AddressBook = { AuthorityHistoryPairFactory: authorityHistoryPairFactoryAddress, + CartesiDApp: applicationAddress, CartesiDAppFactory: cartesiDAppFactoryAddress, DAppAddressRelay: dAppAddressRelayAddress, EntryPointV06: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", @@ -110,11 +106,6 @@ export abstract class BaseCommand extends Command { VerifyingPaymasterV07: "0xc5c97885C67F7361aBAfD2B95067a5bBdA603608", }; - // get dapp address - const applicationAddress = await this.getApplicationAddress(); - if (applicationAddress) { - contracts["CartesiDApp"] = applicationAddress; - } return contracts; } diff --git a/apps/cli/src/commands/build.ts b/apps/cli/src/commands/build.ts index f78236df..47a85dcd 100644 --- a/apps/cli/src/commands/build.ts +++ b/apps/cli/src/commands/build.ts @@ -153,13 +153,7 @@ Update your application Dockerfile using one of the templates at https://github. outputFilePath: string, ): Promise { // create docker tarball from app image - const { stdout: appCid } = await execa("docker", [ - "image", - "save", - image, - "-o", - outputFilePath, - ]); + await execa("docker", ["image", "save", image, "-o", outputFilePath]); } // this wraps the call to the sdk image with a one-shot approach diff --git a/apps/cli/test/helpers/init.js b/apps/cli/test/helpers/init.js deleted file mode 100644 index 2c586bb0..00000000 --- a/apps/cli/test/helpers/init.js +++ /dev/null @@ -1,6 +0,0 @@ -const path = require("path"); -process.env.TS_NODE_PROJECT = path.resolve("test/tsconfig.json"); -process.env.NODE_ENV = "development"; - -global.oclif = global.oclif || {}; -global.oclif.columns = 80; diff --git a/apps/cli/test/node/database.test.ts b/apps/cli/test/node/database.test.ts deleted file mode 100644 index 7277a36d..00000000 --- a/apps/cli/test/node/database.test.ts +++ /dev/null @@ -1,194 +0,0 @@ -import { rmSync } from "fs"; -import { tmpNameSync } from "tmp"; -import { describe, expect, test } from "vitest"; - -import { Database } from "../../src/node/database"; - -describe("database", () => { - test("empty", () => { - const db = new Database(); - expect(db.applications).toHaveLength(0); - }); - - test("store and load at same time", () => { - const db = new Database(); - const now: bigint = BigInt(Date.now()); - db.addMachine(1n, "0xdeadbeef", "C123"); - db.addMachine(1n, "0x123", "Que2"); - db.addApplication(now, { - blockNumber: 2n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0xdeadbeef", - shutdownAt: now + 1000n, - }); - db.addApplication(now, { - blockNumber: 3n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0x123", - shutdownAt: now + 500n, - }); - const tmp = tmpNameSync(); - db.store(tmp); - - // load with same time - const db2 = Database.load(tmp, now); - expect(db2.block).toBe(3n); - expect(db2.applications).toHaveLength(2); - expect(Object.keys(db2.machines)).toHaveLength(2); - expect(db2.applications[0].address).toBe("0x123"); - expect(db2.applications[1].address).toBe("0xdeadbeef"); - expect(db2.now).toBe(0); - rmSync(tmp); - }); - - test("store and load at future time", () => { - const db = new Database(); - const now: bigint = BigInt(Date.now()); - db.addMachine(1n, "0xdeadbeef", "C123"); - db.addMachine(1n, "0x123", "Que2"); - db.addApplication(now, { - blockNumber: 2n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0xdeadbeef", - shutdownAt: now + 1000n, - }); - db.addApplication(now, { - blockNumber: 3n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0x123", - shutdownAt: now + 500n, - }); - const tmp = tmpNameSync(); - db.store(tmp); - - // load at a future time - const db2 = Database.load(tmp, now + 2000n); - expect(db2.block).toBe(3n); - expect(db2.applications).toHaveLength(2); - expect(Object.keys(db2.machines)).toHaveLength(2); - expect(db2.applications[0].address).toBe("0x123"); - expect(db2.applications[1].address).toBe("0xdeadbeef"); - expect(db2.now).toBe(2); - rmSync(tmp); - }); - - test("tick with no applications", () => { - const db = new Database(); - const now: bigint = BigInt(Date.now()); - expect(db.tick(now)).toHaveLength(0); - }); - - test("tick", () => { - // [ ] - // now = -1 - const db = new Database(); - const now: bigint = BigInt(Date.now()); - - // [ +1s ] - // ^ - // | - // -- now - expect( - db.addApplication(now, { - blockNumber: 1n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0x1", - shutdownAt: now + 1000n, - }), - ).toBeDefined(); - expect(db.now).toBe(0); - - // [ +1s, +2s ] - // ^ - // | - // -- now - expect( - db.addApplication(now, { - blockNumber: 2n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0x2", - shutdownAt: now + 2000n, - }), - ).toBeDefined(); - expect(db.now).toBe(0); - - // [ +1s, +2s, +4s ] - // ^ - // | - // -- now - expect( - db.addApplication(now, { - blockNumber: 3n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0x3", - shutdownAt: now + 4000n, - }), - ).toBeDefined(); - expect(db.now).toBe(0); - - // [ -1s, +1s, +2s, +4s ] - // ^ - // | - // -- now - expect( - db.addApplication(now, { - blockNumber: 4n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0x4", - shutdownAt: now - 1000n, - }), - ).toBeUndefined(); - expect(db.now).toBe(1); - - // [ -4s, -1s, +1s, +2s, +4s ] - // ^ - // | - // -- now - expect( - db.addApplication(now, { - blockNumber: 5n, - blockHash: "0xdeadbeef", - transactionHash: "0xdeadbeef", - address: "0x5", - shutdownAt: now - 4000n, - }), - ).toBeUndefined(); - expect(db.now).toBe(2); - - // [ -4s, -1s, +1s, +2s, +4s ] - // ^ - // | - // -- now - expect(db.tick(now + 1000n)).toHaveLength(1); - expect(db.now).toBe(3); - - // [ -4s, -1s, +1s, +2s, +4s ] - // ^ - // | - // -- now - expect(db.tick(now + 2000n)).toHaveLength(1); - expect(db.now).toBe(4); - - // [ -4s, -1s, +1s, +2s, +4s ] - // ^ - // | - // -- now - expect(db.tick(now + 3000n)).toHaveLength(0); - expect(db.now).toBe(4); - - // [ -4s, -1s, +1s, +2s, +4s ] - // ^ - // | - // -- now - expect(db.tick(now + 4000n)).toHaveLength(1); - expect(db.now).toBe(5); - }); -});