@@ -31,31 +31,54 @@ describe('CellsService', () => {
3131
3232 const bob = {
3333 lockScript : {
34- codeHash : '0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88 ' ,
34+ codeHash : '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2 ' ,
3535 args : [ '0x36c329ed630d6ce750712a477543672adab57f4c' ] ,
3636 hashType : ScriptHashType . Type ,
3737 } ,
38- lockHash : '0x024b0fd0c4912e98aab6808f6474cacb1969255d526b3cac5d3bdd15962a8818 ' ,
38+ lockHash : '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba ' ,
3939 address : 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83' ,
4040 blake160 : '0x36c329ed630d6ce750712a477543672adab57f4c' ,
4141 }
4242
43- const generateCell = ( capacity : string , status : OutputStatus , hasData : boolean , typeScript : Script | null ) => {
43+ const alice = {
44+ lockScript : {
45+ codeHash : '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2' ,
46+ args : [ '0xe2193df51d78411601796b35b17b4f8f2cd85bd0' ] ,
47+ hashType : ScriptHashType . Type ,
48+ } ,
49+ lockHash : '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c' ,
50+ address : 'ckt1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gqfvmy2v' ,
51+ blake160 : '0xe2193df51d78411601796b35b17b4f8f2cd85bd0' ,
52+ }
53+
54+ const generateCell = (
55+ capacity : string ,
56+ status : OutputStatus ,
57+ hasData : boolean ,
58+ typeScript : Script | null ,
59+ who : any = bob
60+ ) => {
4461 const output = new OutputEntity ( )
4562 output . outPointTxHash = randomHex ( )
4663 output . outPointIndex = '0'
4764 output . capacity = capacity
48- output . lock = bob . lockScript
49- output . lockHash = bob . lockHash
65+ output . lock = who . lockScript
66+ output . lockHash = who . lockHash
5067 output . status = status
5168 output . hasData = hasData
5269 output . typeScript = typeScript
5370
5471 return output
5572 }
5673
57- const createCell = async ( capacity : string , status : OutputStatus , hasData : boolean , typeScript : Script | null ) => {
58- const cell = generateCell ( capacity , status , hasData , typeScript )
74+ const createCell = async (
75+ capacity : string ,
76+ status : OutputStatus ,
77+ hasData : boolean ,
78+ typeScript : Script | null ,
79+ who : any = bob
80+ ) => {
81+ const cell = generateCell ( capacity , status , hasData , typeScript , who )
5982 await getConnection ( ) . manager . save ( cell )
6083 return cell
6184 }
@@ -89,8 +112,6 @@ describe('CellsService', () => {
89112 expect ( blake160s ) . toEqual ( [ bob . blake160 ] )
90113 } )
91114
92-
93-
94115 const lockHashes = [ bob . lockHash ]
95116
96117 describe ( 'getBalance' , ( ) => {
@@ -197,5 +218,30 @@ describe('CellsService', () => {
197218 }
198219 expect ( error ) . toBeInstanceOf ( CapacityNotEnough )
199220 } )
221+
222+ it ( `bob's and alice's cells` , async ( ) => {
223+ SkipDataAndType . getInstance ( ) . update ( true )
224+ await createCells ( )
225+ await createCell ( toShannon ( '5000' ) , OutputStatus . Live , false , null , alice )
226+
227+ const result = await CellsService . gatherInputs ( toShannon ( '6000' ) , [ alice . lockHash , bob . lockHash ] )
228+
229+ expect ( result . capacities ) . toEqual ( '600000000000' )
230+ } )
231+
232+ it ( `only bob's cells` , async ( ) => {
233+ SkipDataAndType . getInstance ( ) . update ( true )
234+ await createCells ( )
235+ await createCell ( toShannon ( '5000' ) , OutputStatus . Live , false , null , alice )
236+
237+ let error
238+ try {
239+ await CellsService . gatherInputs ( toShannon ( '1001' ) , [ bob . lockHash ] )
240+ } catch ( e ) {
241+ error = e
242+ }
243+
244+ expect ( error ) . toBeInstanceOf ( CapacityNotEnough )
245+ } )
200246 } )
201247} )
0 commit comments