1515
1616import { describe , expect , it , beforeEach , vi } from "vitest" ;
1717import type { CdmJson } from "@parity/product-sdk-contracts" ;
18- import { CDM_REGISTRY_ADDRESS } from "../config.js " ;
18+ import { REGISTRY_ADDRESS } from "@dotdm/contracts " ;
1919
2020const { createContractFromClientMock, getAddressQueryMock } = vi . hoisted ( ( ) => ( {
2121 createContractFromClientMock : vi . fn ( ) ,
@@ -26,6 +26,10 @@ vi.mock("@parity/product-sdk-contracts", () => ({
2626 createContractFromClient : ( ...args : unknown [ ] ) => createContractFromClientMock ( ...args ) ,
2727} ) ) ;
2828
29+ vi . mock ( "@parity/product-sdk-descriptors/paseo-asset-hub" , ( ) => ( {
30+ paseo_asset_hub : { genesis : "0xasset" } ,
31+ } ) ) ;
32+
2933import {
3034 PLAYGROUND_REGISTRY_CONTRACT ,
3135 resolveLiveContractAddresses ,
@@ -35,6 +39,7 @@ import {
3539
3640const snapshotAddress = "0x1111111111111111111111111111111111111111" ;
3741const liveAddress = "0x2222222222222222222222222222222222222222" ;
42+ const targetRegistryAddress = "0x5555555555555555555555555555555555555555" ;
3843
3944/**
4045 * Mock `Weight` for `QueryResult.gasRequired` — required (non-optional) on
@@ -50,6 +55,7 @@ function manifest(): CdmJson {
5055 target1 : {
5156 "asset-hub" : "wss://asset-hub.example" ,
5257 bulletin : "https://bulletin.example/ipfs" ,
58+ registry : targetRegistryAddress ,
5359 } ,
5460 } ,
5561 dependencies : {
@@ -73,7 +79,7 @@ function manifest(): CdmJson {
7379 } ,
7480 } ,
7581 } ,
76- } ;
82+ } as CdmJson ;
7783}
7884
7985beforeEach ( ( ) => {
@@ -85,22 +91,25 @@ beforeEach(() => {
8591} ) ;
8692
8793describe ( "resolveLiveContractAddresses" , ( ) => {
88- it ( "queries the fixed CDM registry for requested libraries" , async ( ) => {
94+ it ( "queries the configured CDM registry for requested libraries" , async ( ) => {
8995 getAddressQueryMock . mockResolvedValue ( {
9096 success : true ,
9197 value : { isSome : true , value : liveAddress } ,
9298 gasRequired : OK_WEIGHT ,
9399 } ) ;
94100
95101 const assetHub = { } as any ;
96- const addresses = await resolveLiveContractAddresses ( assetHub , [
97- PLAYGROUND_REGISTRY_CONTRACT ,
98- ] ) ;
102+ const addresses = await resolveLiveContractAddresses (
103+ assetHub ,
104+ [ PLAYGROUND_REGISTRY_CONTRACT ] ,
105+ { registryAddress : targetRegistryAddress } ,
106+ ) ;
99107
100108 expect ( addresses ) . toEqual ( { [ PLAYGROUND_REGISTRY_CONTRACT ] : liveAddress } ) ;
101109 expect ( createContractFromClientMock ) . toHaveBeenCalledWith (
102110 assetHub ,
103- CDM_REGISTRY_ADDRESS ,
111+ { genesis : "0xasset" } ,
112+ targetRegistryAddress ,
104113 expect . arrayContaining ( [
105114 expect . objectContaining ( { name : "getAddress" , type : "function" } ) ,
106115 ] ) ,
@@ -120,11 +129,13 @@ describe("resolveLiveContractAddresses", () => {
120129 const origin = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" ;
121130 await resolveLiveContractAddresses ( assetHub , [ PLAYGROUND_REGISTRY_CONTRACT ] , {
122131 defaultOrigin : origin ,
132+ registryAddress : targetRegistryAddress ,
123133 } ) ;
124134
125135 expect ( createContractFromClientMock ) . toHaveBeenCalledWith (
126136 assetHub ,
127- CDM_REGISTRY_ADDRESS ,
137+ { genesis : "0xasset" } ,
138+ targetRegistryAddress ,
128139 expect . any ( Array ) ,
129140 expect . objectContaining ( { defaultOrigin : origin } ) ,
130141 ) ;
@@ -138,9 +149,29 @@ describe("resolveLiveContractAddresses", () => {
138149 } ) ;
139150
140151 await expect (
141- resolveLiveContractAddresses ( { } as any , [ PLAYGROUND_REGISTRY_CONTRACT ] ) ,
152+ resolveLiveContractAddresses ( { } as any , [ PLAYGROUND_REGISTRY_CONTRACT ] , {
153+ registryAddress : targetRegistryAddress ,
154+ } ) ,
142155 ) . resolves . toEqual ( { } ) ;
143156 } ) ;
157+
158+ it ( "falls back to CDM's package registry address when no registry is supplied" , async ( ) => {
159+ getAddressQueryMock . mockResolvedValue ( {
160+ success : true ,
161+ value : { isSome : true , value : liveAddress } ,
162+ gasRequired : OK_WEIGHT ,
163+ } ) ;
164+
165+ await resolveLiveContractAddresses ( { } as any , [ PLAYGROUND_REGISTRY_CONTRACT ] ) ;
166+
167+ expect ( createContractFromClientMock ) . toHaveBeenCalledWith (
168+ { } ,
169+ { genesis : "0xasset" } ,
170+ REGISTRY_ADDRESS ,
171+ expect . any ( Array ) ,
172+ expect . any ( Object ) ,
173+ ) ;
174+ } ) ;
144175} ) ;
145176
146177describe ( "withLiveContractAddresses" , ( ) => {
@@ -200,7 +231,8 @@ describe("withLiveContractAddresses", () => {
200231
201232 expect ( createContractFromClientMock ) . toHaveBeenCalledWith (
202233 assetHub ,
203- CDM_REGISTRY_ADDRESS ,
234+ { genesis : "0xasset" } ,
235+ targetRegistryAddress ,
204236 expect . any ( Array ) ,
205237 expect . objectContaining ( { defaultOrigin : origin } ) ,
206238 ) ;
@@ -224,7 +256,8 @@ describe("withLiveContractAddresses", () => {
224256
225257 expect ( createContractFromClientMock ) . toHaveBeenCalledWith (
226258 assetHub ,
227- CDM_REGISTRY_ADDRESS ,
259+ { genesis : "0xasset" } ,
260+ targetRegistryAddress ,
228261 expect . any ( Array ) ,
229262 expect . objectContaining ( { defaultOrigin : origin } ) ,
230263 ) ;
0 commit comments