@@ -21,7 +21,23 @@ describe("type-id", () => {
2121 depType : "code" as const ,
2222 } ;
2323
24+ const mockTypeId = ccc . hexFrom ( "1" . repeat ( 64 ) ) ;
25+
2426 beforeEach ( ( ) => {
27+ vi . spyOn ( ccc , "hashTypeId" ) . mockReturnValue ( mockTypeId ) ;
28+ vi . spyOn (
29+ ccc . Transaction . prototype ,
30+ "completeInputsAtLeastOne" ,
31+ ) . mockImplementation ( async function ( this : ccc . Transaction ) {
32+ this . addInput ( {
33+ previousOutput : {
34+ txHash : "0x" + "2" . repeat ( 64 ) ,
35+ index : 0 ,
36+ } ,
37+ } ) ;
38+ return 1 ;
39+ } ) ;
40+
2541 client = {
2642 getKnownScript : vi . fn ( ) ,
2743 getCellDeps : vi . fn ( ) ,
@@ -31,7 +47,6 @@ describe("type-id", () => {
3147 signer = {
3248 client,
3349 getRecommendedAddressObj : vi . fn ( ) ,
34- findCells : vi . fn ( ) ,
3550 } as unknown as ccc . Signer ;
3651
3752 ( client . getKnownScript as Mock ) . mockResolvedValue ( {
@@ -68,22 +83,6 @@ describe("type-id", () => {
6883 codec : customCodec ,
6984 } ) ;
7085
71- const inputCell = ccc . Cell . from ( {
72- outPoint : { txHash : "0x" + "2" . repeat ( 64 ) , index : 0 } ,
73- cellOutput : {
74- capacity : ccc . fixedPointFrom ( 1000 ) ,
75- lock : ccc . Script . from ( {
76- codeHash : "0x" + "0" . repeat ( 64 ) ,
77- hashType : "type" ,
78- args : "0x" ,
79- } ) ,
80- } ,
81- outputData : "0x" ,
82- } ) ;
83- ( signer . findCells as Mock ) . mockImplementation ( async function * ( ) {
84- yield inputCell ;
85- } ) ;
86-
8786 const { tx } = await create ( {
8887 signer,
8988 data : 123456 ,
@@ -104,22 +103,6 @@ describe("type-id", () => {
104103 calculateTypeId,
105104 } ) ;
106105
107- const inputCell = ccc . Cell . from ( {
108- outPoint : { txHash : "0x" + "2" . repeat ( 64 ) , index : 0 } ,
109- cellOutput : {
110- capacity : ccc . fixedPointFrom ( 1000 ) ,
111- lock : ccc . Script . from ( {
112- codeHash : "0x" + "0" . repeat ( 64 ) ,
113- hashType : "type" ,
114- args : "0x" ,
115- } ) ,
116- } ,
117- outputData : "0x" ,
118- } ) ;
119- ( signer . findCells as Mock ) . mockImplementation ( async function * ( ) {
120- yield inputCell ;
121- } ) ;
122-
123106 const { id, tx } = await create ( {
124107 signer,
125108 data : "0x" ,
@@ -150,22 +133,6 @@ describe("type-id", () => {
150133 addCellDeps,
151134 } ) ;
152135
153- const inputCell = ccc . Cell . from ( {
154- outPoint : { txHash : "0x" + "2" . repeat ( 64 ) , index : 0 } ,
155- cellOutput : {
156- capacity : ccc . fixedPointFrom ( 1000 ) ,
157- lock : ccc . Script . from ( {
158- codeHash : "0x" + "0" . repeat ( 64 ) ,
159- hashType : "type" ,
160- args : "0x" ,
161- } ) ,
162- } ,
163- outputData : "0x" ,
164- } ) ;
165- ( signer . findCells as Mock ) . mockImplementation ( async function * ( ) {
166- yield inputCell ;
167- } ) ;
168-
169136 const { tx } = await create ( {
170137 signer,
171138 data : "0x" ,
@@ -186,41 +153,21 @@ describe("type-id", () => {
186153
187154 describe ( "create" , ( ) => {
188155 it ( "should create a transaction with correct type id" , async ( ) => {
189- const inputCell = ccc . Cell . from ( {
190- outPoint : {
191- txHash : "0x" + "2" . repeat ( 64 ) ,
192- index : 0 ,
193- } ,
194- cellOutput : {
195- capacity : ccc . fixedPointFrom ( 1000 ) ,
196- lock : ccc . Script . from ( {
197- codeHash : "0x" + "0" . repeat ( 64 ) ,
198- hashType : "type" ,
199- args : "0x" ,
200- } ) ,
201- } ,
202- outputData : "0x" ,
203- } ) ;
204-
205- ( signer . findCells as Mock ) . mockImplementation ( async function * ( ) {
206- yield inputCell ;
207- } ) ;
208-
209156 const data = "0x1234" ;
210157 const { tx, id, index } = await create ( {
211158 signer,
212159 data,
213160 } ) ;
214161
215- expect ( tx . inputs . length ) . toBe ( 1 ) ;
216- expect ( tx . inputs [ 0 ] . previousOutput ) . toEqual ( inputCell . outPoint ) ;
162+ expect (
163+ void ccc . Transaction . prototype . completeInputsAtLeastOne ,
164+ ) . toHaveBeenCalledWith ( signer ) ;
165+ expect ( ccc . hashTypeId ) . toHaveBeenCalled ( ) ;
166+ expect ( id ) . toBe ( mockTypeId ) ;
217167
218168 expect ( tx . outputs . length ) . toBe ( 1 ) ;
219169 expect ( index ) . toBe ( 0 ) ;
220170
221- const expectedId = ccc . hashTypeId ( tx . inputs [ 0 ] , 0 ) ;
222- expect ( id ) . toBe ( expectedId ) ;
223-
224171 const output = tx . outputs [ 0 ] ;
225172 expect ( output . type ) . toBeDefined ( ) ;
226173 expect ( output . type ?. codeHash ) . toBe ( typeIdScript . codeHash ) ;
@@ -239,22 +186,6 @@ describe("type-id", () => {
239186 headerDeps : [ "0x" + "e" . repeat ( 64 ) ] ,
240187 } ) ;
241188
242- const inputCell = ccc . Cell . from ( {
243- outPoint : { txHash : "0x" + "2" . repeat ( 64 ) , index : 0 } ,
244- cellOutput : {
245- capacity : ccc . fixedPointFrom ( 1000 ) ,
246- lock : ccc . Script . from ( {
247- codeHash : "0x" + "0" . repeat ( 64 ) ,
248- hashType : "type" ,
249- args : "0x" ,
250- } ) ,
251- } ,
252- outputData : "0x" ,
253- } ) ;
254- ( signer . findCells as Mock ) . mockImplementation ( async function * ( ) {
255- yield inputCell ;
256- } ) ;
257-
258189 const { tx } = await create ( {
259190 signer,
260191 data : "0x" ,
@@ -272,22 +203,6 @@ describe("type-id", () => {
272203 args : "0xffee" ,
273204 } ) ;
274205
275- const inputCell = ccc . Cell . from ( {
276- outPoint : { txHash : "0x" + "2" . repeat ( 64 ) , index : 0 } ,
277- cellOutput : {
278- capacity : ccc . fixedPointFrom ( 1000 ) ,
279- lock : ccc . Script . from ( {
280- codeHash : "0x" + "0" . repeat ( 64 ) ,
281- hashType : "type" ,
282- args : "0x" ,
283- } ) ,
284- } ,
285- outputData : "0x" ,
286- } ) ;
287- ( signer . findCells as Mock ) . mockImplementation ( async function * ( ) {
288- yield inputCell ;
289- } ) ;
290-
291206 const { tx } = await create ( {
292207 signer,
293208 data : "0x" ,
0 commit comments