Skip to content

Commit f4406a0

Browse files
committed
test: move tx builder test to devnet
1 parent 1f0671c commit f4406a0

File tree

2 files changed

+94
-10
lines changed

2 files changed

+94
-10
lines changed

packages/evolution/test/TxBuilder.Scripts.test.ts renamed to packages/evolution-devnet/test/TxBuilder.Scripts.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { afterAll, beforeAll, describe, expect, it } from "@effect/vitest"
2+
import * as CoreAddress from "@evolution-sdk/evolution/core/Address"
3+
import * as Data from "@evolution-sdk/evolution/core/Data"
4+
import * as PlutusV2 from "@evolution-sdk/evolution/core/PlutusV2"
5+
import * as ScriptHash from "@evolution-sdk/evolution/core/ScriptHash"
6+
import * as Assets from "@evolution-sdk/evolution/sdk/Assets"
7+
import type { TxBuilderConfig } from "@evolution-sdk/evolution/sdk/builders/TransactionBuilder"
8+
import { makeTxBuilder } from "@evolution-sdk/evolution/sdk/builders/TransactionBuilder"
9+
import { KupmiosProvider } from "@evolution-sdk/evolution/sdk/provider/Kupmios"
10+
import * as Script from "@evolution-sdk/evolution/sdk/Script"
211
import { Schema } from "effect"
312

4-
import * as CoreAddress from "../src/core/Address.js"
5-
import * as Data from "../src/core/Data.js"
6-
import * as PlutusV2 from "../src/core/PlutusV2.js"
7-
import * as ScriptHash from "../src/core/ScriptHash.js"
8-
import * as Assets from "../src/sdk/Assets.js"
9-
import type { TxBuilderConfig } from "../src/sdk/builders/TransactionBuilder.js"
10-
import { makeTxBuilder } from "../src/sdk/builders/TransactionBuilder.js"
11-
import * as Devnet from "../src/sdk/Devnet/Devnet.js"
12-
import { KupmiosProvider } from "../src/sdk/provider/Kupmios.js"
13-
import * as Script from "../src/sdk/Script.js"
13+
import { Devnet } from "../src/index.js"
1414
import { createTestUtxo } from "./utils/utxo-helpers.js"
1515

1616
describe("TxBuilder Script Handling", () => {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import type * as Assets from "@evolution-sdk/evolution/sdk/Assets"
2+
import type * as Datum from "@evolution-sdk/evolution/sdk/Datum"
3+
import type * as Script from "@evolution-sdk/evolution/sdk/Script"
4+
import type * as UTxO from "@evolution-sdk/evolution/sdk/UTxO"
5+
6+
/**
7+
* Options for creating a test UTxO.
8+
*/
9+
export type CreateTestUtxoOptions = {
10+
/**
11+
* The address of the UTxO. Defaults to a test address.
12+
* @default "addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs68faae"
13+
*/
14+
address?: string
15+
/**
16+
* Optional datum to attach to the UTxO.
17+
*/
18+
datumOption?: Datum.Datum
19+
/**
20+
* The amount of lovelace in the UTxO.
21+
*/
22+
lovelace: bigint
23+
/**
24+
* Optional native assets to include in the UTxO.
25+
* Map of policyId+assetName (hex encoded) to quantity.
26+
*/
27+
nativeAssets?: Record<string, bigint>
28+
/**
29+
* The output index. Defaults to 0.
30+
* @default 0
31+
*/
32+
outputIndex?: number
33+
/**
34+
* Optional reference script to attach to the UTxO.
35+
*/
36+
scriptRef?: Script.Script
37+
/**
38+
* The transaction hash. Defaults to 64 zeros.
39+
* @default "0".repeat(64)
40+
*/
41+
txHash?: string
42+
}
43+
44+
/**
45+
* Default test address used when no address is provided.
46+
*/
47+
const DEFAULT_TEST_ADDRESS =
48+
"addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs68faae"
49+
50+
/**
51+
* Creates a test UTxO with the specified parameters.
52+
*/
53+
export const createTestUtxo = (options: CreateTestUtxoOptions): UTxO.UTxO => {
54+
const {
55+
address = DEFAULT_TEST_ADDRESS,
56+
datumOption,
57+
lovelace,
58+
nativeAssets,
59+
outputIndex = 0,
60+
scriptRef,
61+
txHash = "0".repeat(64)
62+
} = options
63+
64+
// Ensure txHash is 64 hex characters (convert short IDs to valid hex)
65+
const paddedTxHash = txHash.length === 64 && /^[0-9a-fA-F]+$/.test(txHash)
66+
? txHash
67+
: Array.from(txHash)
68+
.map(c => c.charCodeAt(0).toString(16).padStart(2, '0'))
69+
.join('')
70+
.padEnd(64, '0')
71+
72+
const assets: Assets.Assets = nativeAssets
73+
? { lovelace, ...nativeAssets }
74+
: { lovelace }
75+
76+
return {
77+
address,
78+
assets,
79+
datumOption,
80+
outputIndex,
81+
scriptRef,
82+
txHash: paddedTxHash
83+
}
84+
}

0 commit comments

Comments
 (0)