|
| 1 | +import { |
| 2 | + Contract, |
| 3 | + MockNetworkProvider, |
| 4 | + randomUtxo, |
| 5 | + SignatureTemplate, |
| 6 | + TransactionBuilder, |
| 7 | +} from './../src/index.js'; |
| 8 | +import { |
| 9 | + bobAddress, |
| 10 | + bobPkh, |
| 11 | + bobPriv, |
| 12 | + bobPub, |
| 13 | +} from './fixture/vars.js'; |
| 14 | +import p2pkhArtifact from './fixture/p2pkh.artifact.js'; |
| 15 | +import bigintArtifact from './fixture/bigint.artifact.js'; |
| 16 | +import '../src/test/JestExtensions.js'; |
| 17 | + |
| 18 | +const bobSignatureTemplate = new SignatureTemplate(bobPriv); |
| 19 | + |
| 20 | +const provider = new MockNetworkProvider(); |
| 21 | + |
| 22 | +describe('Multi-Contract-Debugging tests', () => { |
| 23 | + describe('require statements', () => { |
| 24 | + it('it should only fail with correct error message when a final verify fails', async () => { |
| 25 | + const p2pkhContract = new Contract(p2pkhArtifact, [bobPkh], { provider }); |
| 26 | + const bigintContract = new Contract(bigintArtifact, [], { provider }); |
| 27 | + |
| 28 | + const MAX_INT64 = BigInt('9223372036854775807'); |
| 29 | + |
| 30 | + (provider as any).addUtxo?.(p2pkhContract.address, randomUtxo()); |
| 31 | + (provider as any).addUtxo?.(bigintContract.address, randomUtxo()); |
| 32 | + (provider as any).addUtxo?.(bobAddress, randomUtxo()); |
| 33 | + |
| 34 | + const to = p2pkhContract.address; |
| 35 | + const amount = 10000n; |
| 36 | + const p2pkhContractUtxos = await p2pkhContract.getUtxos(); |
| 37 | + const bigIntContractUtxos = await bigintContract.getUtxos(); |
| 38 | + const bobAddressUtxos = await provider.getUtxos(bobAddress); |
| 39 | + |
| 40 | + // when |
| 41 | + const transaction = new TransactionBuilder({ provider }) |
| 42 | + .addInput(p2pkhContractUtxos[0], p2pkhContract.unlock.spend(bobPub, bobSignatureTemplate)) |
| 43 | + .addInput(bigIntContractUtxos[0], bigintContract.unlock.proofOfBigInt(MAX_INT64 + 1n, -1n)) |
| 44 | + .addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH()) |
| 45 | + .addOutput({ to, amount }); |
| 46 | + |
| 47 | + console.warn(transaction.bitauthUri()); |
| 48 | + |
| 49 | + await expect(transaction).toFailRequire(); |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments