Skip to content

Commit 8f0a808

Browse files
committed
Add more test cases to multi-contract-debugging tests
1 parent 882d837 commit 8f0a808

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

packages/cashscript/test/multi-contract-debugging.test.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
TransactionBuilder,
77
} from './../src/index.js';
88
import {
9+
alicePub,
910
bobAddress,
1011
bobPkh,
1112
bobPriv,
@@ -21,10 +22,70 @@ const provider = new MockNetworkProvider();
2122

2223
describe('Multi-Contract-Debugging tests', () => {
2324
describe('require statements', () => {
25+
it('it should not throw an error if no require statement fails', async () => {
26+
const p2pkhContract = new Contract(p2pkhArtifact, [bobPkh], { provider });
27+
const bigintContract = new Contract(bigintArtifact, [], { provider });
28+
29+
const MAX_INT64 = BigInt('9223372036854775807');
30+
31+
(provider as any).addUtxo?.(p2pkhContract.address, randomUtxo());
32+
(provider as any).addUtxo?.(bigintContract.address, randomUtxo());
33+
(provider as any).addUtxo?.(bobAddress, randomUtxo());
34+
35+
const to = p2pkhContract.address;
36+
const amount = 10000n;
37+
const p2pkhContractUtxos = await p2pkhContract.getUtxos();
38+
const bigIntContractUtxos = await bigintContract.getUtxos();
39+
const bobAddressUtxos = await provider.getUtxos(bobAddress);
40+
41+
// when
42+
const transaction = new TransactionBuilder({ provider })
43+
// wrong public key
44+
.addInput(p2pkhContractUtxos[0], p2pkhContract.unlock.spend(bobPub, bobSignatureTemplate))
45+
.addInput(bigIntContractUtxos[0], bigintContract.unlock.proofOfBigInt(MAX_INT64 + 1n, 1n))
46+
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
47+
.addOutput({ to, amount });
48+
49+
console.warn(transaction.bitauthUri());
50+
51+
await expect(transaction).toFailRequire();
52+
// throw new Error('test');
53+
});
54+
55+
it('it should fail if a require statement fails', async () => {
56+
const p2pkhContract = new Contract(p2pkhArtifact, [bobPkh], { provider });
57+
const bigintContract = new Contract(bigintArtifact, [], { provider });
58+
59+
const MAX_INT64 = BigInt('9223372036854775807');
60+
61+
(provider as any).addUtxo?.(p2pkhContract.address, randomUtxo());
62+
(provider as any).addUtxo?.(bigintContract.address, randomUtxo());
63+
(provider as any).addUtxo?.(bobAddress, randomUtxo());
64+
65+
const to = p2pkhContract.address;
66+
const amount = 10000n;
67+
const p2pkhContractUtxos = await p2pkhContract.getUtxos();
68+
const bigIntContractUtxos = await bigintContract.getUtxos();
69+
const bobAddressUtxos = await provider.getUtxos(bobAddress);
70+
71+
// when
72+
const transaction = new TransactionBuilder({ provider })
73+
// wrong public key
74+
.addInput(p2pkhContractUtxos[0], p2pkhContract.unlock.spend(alicePub, bobSignatureTemplate))
75+
.addInput(bigIntContractUtxos[0], bigintContract.unlock.proofOfBigInt(MAX_INT64 + 1n, 1n))
76+
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
77+
.addOutput({ to, amount });
78+
79+
console.warn(transaction.bitauthUri());
80+
81+
await expect(transaction).toFailRequire();
82+
// throw new Error('test');
83+
});
84+
2485
it('it should only fail with correct error message when a final verify fails', async () => {
2586
const p2pkhContract = new Contract(p2pkhArtifact, [bobPkh], { provider });
2687
const bigintContract = new Contract(bigintArtifact, [], { provider });
27-
88+
2889
const MAX_INT64 = BigInt('9223372036854775807');
2990

3091
(provider as any).addUtxo?.(p2pkhContract.address, randomUtxo());
@@ -45,7 +106,7 @@ describe('Multi-Contract-Debugging tests', () => {
45106
.addOutput({ to, amount });
46107

47108
console.warn(transaction.bitauthUri());
48-
109+
49110
await expect(transaction).toFailRequire();
50111
});
51112
});

0 commit comments

Comments
 (0)