Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 17 additions & 61 deletions packages/evolution-devnet/test/Client.Devnet.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { describe, expect, it } from "@effect/vitest"
import * as Cluster from "@evolution-sdk/devnet/Cluster"
import * as Config from "@evolution-sdk/devnet/Config"
import * as Genesis from "@evolution-sdk/devnet/Genesis"
import { Cardano, Client, preprod } from "@evolution-sdk/evolution"
import { beforeAll, describe, expect, it } from "@effect/vitest"

Check failure on line 1 in packages/evolution-devnet/test/Client.Devnet.test.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Run autofix to sort these imports!
import { Cardano } from "@evolution-sdk/evolution"
import * as CoreAddress from "@evolution-sdk/evolution/Address"
import { afterAll, beforeAll } from "vitest"
import { inject } from "vitest"
import { type SharedClusterResult, useSharedCluster } from "./utils/shared-cluster.js"

// Alias for Cardano.Assets
const CoreAssets = Cardano.Assets
Expand All @@ -13,69 +11,26 @@
* Client integration tests with local Devnet
*/
describe("Client with Devnet", () => {
let devnetCluster: Cluster.Cluster | undefined
let genesisUtxos: Array<Cardano.UTxO.UTxO> = []
let genesisConfig: Config.ShelleyGenesis

const TEST_MNEMONIC =
"test test test test test test test test test test test test test test test test test test test test test test test sauce"

const createTestClient = () =>
Client.make(Cluster.getChain(devnetCluster!))
.withKupmios({ kupoUrl: "http://localhost:1443", ogmiosUrl: "http://localhost:1338" })
.withSeed({ mnemonic: TEST_MNEMONIC, accountIndex: 0 })
let shared: SharedClusterResult

beforeAll(async () => {
const testClient = Client.make(preprod).withSeed({ mnemonic: TEST_MNEMONIC, accountIndex: 0 })

const testAddress = await testClient.address()
const testAddressHex = CoreAddress.toHex(testAddress)

genesisConfig = {
...Config.DEFAULT_SHELLEY_GENESIS,
slotLength: 0.02,
epochLength: 50,
activeSlotsCoeff: 1.0,
initialFunds: { [testAddressHex]: 900_000_000_000 }
}

devnetCluster = await Cluster.make({
clusterName: "client-kupmios-wallet-test",
ports: { node: 6001, submit: 9002 },
shelleyGenesis: genesisConfig,
kupo: { enabled: true, port: 1443, logLevel: "Info" },
ogmios: { enabled: true, port: 1338, logLevel: "info" }
})

await Cluster.start(devnetCluster)
await new Promise((resolve) => setTimeout(resolve, 3_000))
shared = await useSharedCluster(inject("sharedCluster" as any), [0])
}, 180_000)

afterAll(async () => {
if (devnetCluster) {
await Cluster.stop(devnetCluster)
await Cluster.remove(devnetCluster)
}
}, 60_000)

it("should calculate genesis UTxOs from config", { timeout: 10_000 }, async () => {
const calculatedUtxos = await Genesis.calculateUtxosFromConfig(genesisConfig)
it("should verify genesis UTxOs have expected shape", { timeout: 10_000 }, async () => {
expect(shared.genesisUtxos).toBeDefined()
expect(shared.genesisUtxos.length).toBe(1)

expect(calculatedUtxos).toBeDefined()
expect(calculatedUtxos.length).toBe(1)

const utxo = calculatedUtxos[0]
const utxo = shared.genesisUtxos[0]
expect(utxo.transactionId).toBeDefined()
expect(Cardano.TransactionHash.toHex(utxo.transactionId).length).toBe(64)
expect(utxo.index).toBe(0n)
expect(utxo.index).toBeDefined()
expect(CoreAddress.toBech32(utxo.address)).toMatch(/^addr_test/)
expect(utxo.assets.lovelace).toBe(900_000_000_000n)

genesisUtxos = [...calculatedUtxos]
expect(utxo.assets.lovelace).toBeGreaterThan(0n)
})

it("should create signing client and query wallet address", { timeout: 30_000 }, async () => {
const client = createTestClient()
const client = shared.makeClient(0)

const address = await client.address()
expect(address).toBeDefined()
Expand All @@ -84,14 +39,14 @@
})

it("should query wallet UTxOs", { timeout: 30_000 }, async () => {
const client = createTestClient()
const client = shared.makeClient(0)

const utxos = await client.getWalletUtxos()
expect(utxos).toEqual([])
})

it("should query protocol parameters", { timeout: 10_000 }, async () => {
const client = createTestClient()
const client = shared.makeClient(0)
const params = await client.getProtocolParameters()

expect(params).toBeDefined()
Expand All @@ -105,11 +60,12 @@
})

it("should build and submit transaction", { timeout: 30_000 }, async () => {
const genesisUtxos = shared.genesisUtxos
if (genesisUtxos.length === 0) {
throw new Error("Genesis UTxOs not loaded")
}

const client = createTestClient()
const client = shared.makeClient(0)
const genesisAddress = await client.address()
const genesisAddressBech32 = CoreAddress.toBech32(genesisAddress)
const genesisUtxo = genesisUtxos.find((u) => CoreAddress.toBech32(u.address) === genesisAddressBech32)
Expand Down
65 changes: 10 additions & 55 deletions packages/evolution-devnet/test/TxBuilder.AddSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,22 @@
* to the transaction body's requiredSigners field.
*/

import { afterAll, beforeAll, describe, expect, it } from "@effect/vitest"
import * as Cluster from "@evolution-sdk/devnet/Cluster"
import * as Config from "@evolution-sdk/devnet/Config"
import * as Genesis from "@evolution-sdk/devnet/Genesis"
import { Cardano, Client, preprod } from "@evolution-sdk/evolution"
import * as Address from "@evolution-sdk/evolution/Address"
import { beforeAll, describe, expect, it } from "@effect/vitest"

Check failure on line 8 in packages/evolution-devnet/test/TxBuilder.AddSigner.test.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Run autofix to sort these imports!
import { Cardano } from "@evolution-sdk/evolution"
import * as KeyHash from "@evolution-sdk/evolution/KeyHash"
import * as TransactionHash from "@evolution-sdk/evolution/TransactionHash"
import { inject } from "vitest"
import { type SharedClusterResult, useSharedCluster } from "./utils/shared-cluster.js"

describe("TxBuilder addSigner (Devnet Submit)", () => {
let devnetCluster: Cluster.Cluster | undefined
let genesisConfig: Config.ShelleyGenesis
let genesisUtxos: ReadonlyArray<Cardano.UTxO.UTxO> = []

const TEST_MNEMONIC =
"test test test test test test test test test test test test test test test test test test test test test test test sauce"

const createTestClient = (accountIndex: number = 0) => {
if (!devnetCluster) throw new Error("Cluster not initialized")
return Client.make(Cluster.getChain(devnetCluster))
.withKupmios({ kupoUrl: "http://localhost:1449", ogmiosUrl: "http://localhost:1344" })
.withSeed({ mnemonic: TEST_MNEMONIC, accountIndex, addressType: "Base" })
}
let shared: SharedClusterResult

beforeAll(async () => {
const tempClient = Client.make(preprod).withSeed({ mnemonic: TEST_MNEMONIC, accountIndex: 0, addressType: "Base" })

const testAddress = await tempClient.address()
const testAddressHex = Address.toHex(testAddress)

genesisConfig = {
...Config.DEFAULT_SHELLEY_GENESIS,
slotLength: 0.02,
epochLength: 50,
activeSlotsCoeff: 1.0,
initialFunds: { [testAddressHex]: 500_000_000_000 }
}

genesisUtxos = await Genesis.calculateUtxosFromConfig(genesisConfig)

devnetCluster = await Cluster.make({
clusterName: "addsigner-test",
ports: { node: 6007, submit: 9008 },
shelleyGenesis: genesisConfig,
kupo: { enabled: true, port: 1449, logLevel: "Info" },
ogmios: { enabled: true, port: 1344, logLevel: "info" }
})

await Cluster.start(devnetCluster)
await new Promise((resolve) => setTimeout(resolve, 3_000))
shared = await useSharedCluster(inject("sharedCluster" as any), [1, 2])
}, 180_000)

afterAll(async () => {
if (devnetCluster) {
await Cluster.stop(devnetCluster)
await Cluster.remove(devnetCluster)
}
}, 60_000)

it("should include requiredSigners in transaction body and submit successfully", { timeout: 60_000 }, async () => {
const client = createTestClient(0)
const client = shared.makeClient(1)
const myAddress = await client.address()

// Extract payment key hash from address credential
Expand All @@ -81,7 +36,7 @@
address: myAddress,
assets: Cardano.Assets.fromLovelace(5_000_000n)
})
.build({ availableUtxos: [...genesisUtxos] })
.build({ availableUtxos: [...shared.genesisUtxos.filter((u) => u === shared.getGenesisUtxo(1))] })
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This availableUtxos expression is equivalent to just [shared.getGenesisUtxo(1)] but is harder to read and relies on reference equality. Consider simplifying to a direct single-element array for clarity.

Suggested change
.build({ availableUtxos: [...shared.genesisUtxos.filter((u) => u === shared.getGenesisUtxo(1))] })
.build({ availableUtxos: [shared.getGenesisUtxo(1)] })

Copilot uses AI. Check for mistakes.

const tx = await signBuilder.toTransaction()

Expand All @@ -103,8 +58,8 @@

it("should support multi-sig with partial signing and assembly", { timeout: 60_000 }, async () => {
// Create two clients with different account indices (different key pairs)
const client1 = createTestClient(0)
const client2 = createTestClient(1)
const client1 = shared.makeClient(1)
const client2 = shared.makeClient(2)

const address1 = await client1.address()
const address2 = await client2.address()
Expand Down
64 changes: 10 additions & 54 deletions packages/evolution-devnet/test/TxBuilder.Chain.test.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,25 @@
import { afterAll, beforeAll, describe, expect, it } from "@effect/vitest"
import * as Cluster from "@evolution-sdk/devnet/Cluster"
import * as Config from "@evolution-sdk/devnet/Config"
import * as Genesis from "@evolution-sdk/devnet/Genesis"
import { Cardano, Client, preprod } from "@evolution-sdk/evolution"
import * as Address from "@evolution-sdk/evolution/Address"
import { beforeAll, describe, expect, it } from "@effect/vitest"
import { Cardano } from "@evolution-sdk/evolution"
import type { SignBuilder } from "@evolution-sdk/evolution/sdk/builders/SignBuilder"
import * as TransactionHash from "@evolution-sdk/evolution/TransactionHash"
import { inject } from "vitest"

describe("TxBuilder.chainResult", () => {
let devnetCluster: Cluster.Cluster | undefined
let genesisConfig: Config.ShelleyGenesis
let genesisUtxos: ReadonlyArray<Cardano.UTxO.UTxO> = []

const TEST_MNEMONIC =
"test test test test test test test test test test test test test test test test test test test test test test test sauce"
import { type SharedClusterResult, useSharedCluster } from "./utils/shared-cluster.js"

const createTestClient = (accountIndex: number = 0) => {
if (!devnetCluster) throw new Error("Cluster not initialized")
return Client.make(Cluster.getChain(devnetCluster))
.withKupmios({ kupoUrl: "http://localhost:1456", ogmiosUrl: "http://localhost:1348" })
.withSeed({ mnemonic: TEST_MNEMONIC, accountIndex, addressType: "Base" })
}
describe("TxBuilder.chainResult", () => {
let shared: SharedClusterResult

beforeAll(async () => {
const tempClient = Client.make(preprod).withSeed({ mnemonic: TEST_MNEMONIC, accountIndex: 0, addressType: "Base" })

const testAddress = await tempClient.address()
const testAddressHex = Address.toHex(testAddress)

genesisConfig = {
...Config.DEFAULT_SHELLEY_GENESIS,
slotLength: 0.02,
epochLength: 50,
activeSlotsCoeff: 1.0,
initialFunds: { [testAddressHex]: 500_000_000_000 }
}

genesisUtxos = await Genesis.calculateUtxosFromConfig(genesisConfig)

devnetCluster = await Cluster.make({
clusterName: "chain-test",
ports: { node: 6013, submit: 9013 },
shelleyGenesis: genesisConfig,
kupo: { enabled: true, port: 1456, logLevel: "Info" },
ogmios: { enabled: true, port: 1348, logLevel: "info" }
})

await Cluster.start(devnetCluster)
await new Promise((resolve) => setTimeout(resolve, 5_000))
}, 180_000)

afterAll(async () => {
if (devnetCluster) {
await Cluster.stop(devnetCluster)
await Cluster.remove(devnetCluster)
}
}, 60_000)
shared = await useSharedCluster(inject("sharedCluster" as any), [3])
})

it("should chain multiple transactions and submit them all", { timeout: 90_000 }, async () => {
const client = createTestClient(0)
const client = shared.makeClient(3)
const address = await client.address()
const TX_COUNT = 5

// Build chained transactions using build() + chainResult
let available = [...genesisUtxos]
let available = [...shared.genesisUtxos]
const txs: Array<SignBuilder> = []

for (let i = 0; i < TX_COUNT; i++) {
Expand Down
Loading
Loading