@@ -15,7 +15,7 @@ import {
15
15
import p2pkhArtifact from './fixture/p2pkh.artifact.js' ;
16
16
import bigintArtifact from './fixture/bigint.artifact.js' ;
17
17
import '../src/test/JestExtensions.js' ;
18
- import { ARTIFACT_SAME_NAME_DIFFERENT_PATH } from './fixture/debugging/multicontract_debugging_contracts.js' ;
18
+ import { ARTIFACT_FUNCTION_NAME_COLLISION , ARTIFACT_NAME_COLLISION , ARTIFACT_CONTRACT_NAME_COLLISION , ARTIFACT_SAME_NAME_DIFFERENT_PATH } from './fixture/debugging/multicontract_debugging_contracts.js' ;
19
19
20
20
const bobSignatureTemplate = new SignatureTemplate ( bobPriv ) ;
21
21
@@ -171,10 +171,33 @@ describe('Multi-Contract-Debugging tests', () => {
171
171
172
172
it . todo ( 'should fail with correct error message when introspected output bytecode of a different contract does not match' ) ;
173
173
it . todo ( 'should fail with correct error message when introspected input bytecode of a different contract does not match' ) ;
174
- it . todo ( 'should still work if contracts have the same name' ) ;
175
- it . todo ( 'should still work if contract or function parameters have the same name across contracts' ) ;
176
174
it . todo ( 'should still work with duplicate custom require messages across contracts' ) ;
177
175
176
+ it ( 'should still work if contract or function parameters have the same name across contracts' , ( ) => {
177
+ const nameCollision = new Contract ( ARTIFACT_NAME_COLLISION , [ 0n ] , { provider } ) ;
178
+ const functionNameCollision = new Contract ( ARTIFACT_FUNCTION_NAME_COLLISION , [ 1n ] , { provider } ) ;
179
+
180
+ const nameCollisionUtxo = randomUtxo ( ) ;
181
+ const functionNameCollisionUtxo = randomUtxo ( ) ;
182
+
183
+ provider . addUtxo ( nameCollision . address , nameCollisionUtxo ) ;
184
+ provider . addUtxo ( functionNameCollision . address , functionNameCollisionUtxo ) ;
185
+
186
+ const transaction1 = new TransactionBuilder ( { provider } )
187
+ . addInput ( nameCollisionUtxo , nameCollision . unlock . name_collision ( 0n ) )
188
+ . addInput ( functionNameCollisionUtxo , functionNameCollision . unlock . name_collision ( 0n ) )
189
+ . addOutput ( { to : nameCollision . address , amount : 10000n } ) ;
190
+
191
+ expect ( transaction1 ) . toFailRequireWith ( 'FunctionNameCollision.cash:4 Require statement failed at input 1 in contract FunctionNameCollision.cash at line 4 with the following message: b should be 1.' ) ;
192
+
193
+ const transaction2 = new TransactionBuilder ( { provider } )
194
+ . addInput ( nameCollisionUtxo , nameCollision . unlock . name_collision ( 1n ) )
195
+ . addInput ( functionNameCollisionUtxo , functionNameCollision . unlock . name_collision ( 1n ) )
196
+ . addOutput ( { to : nameCollision . address , amount : 10000n } ) ;
197
+
198
+ expect ( transaction2 ) . toFailRequireWith ( 'NameCollision.cash:5 Require statement failed at input 0 in contract NameCollision.cash at line 5 with the following message: b should be 0.' ) ;
199
+ } ) ;
200
+
178
201
it ( 'should still work with different instances of the same contract, with different paths due to different constructor parameter values' , ( ) => {
179
202
const p2pkhContract1 = new Contract ( ARTIFACT_SAME_NAME_DIFFERENT_PATH , [ 0n ] , { provider } ) ;
180
203
const p2pkhContract2 = new Contract ( ARTIFACT_SAME_NAME_DIFFERENT_PATH , [ 1n ] , { provider } ) ;
@@ -202,6 +225,24 @@ describe('Multi-Contract-Debugging tests', () => {
202
225
} ) ;
203
226
204
227
describe ( 'Non-require error messages' , ( ) => {
228
+ it ( 'should fail with the correct error message when there are name collisions on the contractName' , ( ) => {
229
+ const nameCollision = new Contract ( ARTIFACT_NAME_COLLISION , [ 0n ] , { provider } ) ;
230
+ const contractNameCollision = new Contract ( ARTIFACT_CONTRACT_NAME_COLLISION , [ 1n ] , { provider } ) ;
231
+
232
+ const nameCollisionUtxo = randomUtxo ( ) ;
233
+ const contractNameCollisionUtxo = randomUtxo ( ) ;
234
+
235
+ provider . addUtxo ( nameCollision . address , nameCollisionUtxo ) ;
236
+ provider . addUtxo ( contractNameCollision . address , contractNameCollisionUtxo ) ;
237
+
238
+ const transaction = new TransactionBuilder ( { provider } )
239
+ . addInput ( nameCollisionUtxo , nameCollision . unlock . name_collision ( 0n ) )
240
+ . addInput ( contractNameCollisionUtxo , contractNameCollision . unlock . name_collision ( 0n ) )
241
+ . addOutput ( { to : nameCollision . address , amount : 10000n } ) ;
242
+
243
+ expect ( ( ) => transaction . debug ( ) ) . toThrow ( 'There are multiple artifacts with the same contractName. Please make sure that all artifacts have unique names.' ) ;
244
+ } ) ;
245
+
205
246
it . todo ( 'should fail with correct error message and statement when a multiline non-require statement fails' ) ;
206
247
} ) ;
207
248
} ) ;
0 commit comments