Skip to content

Commit 38d9927

Browse files
committed
Small refactor with mocknet test skipping
1 parent a7c929d commit 38d9927

File tree

3 files changed

+161
-168
lines changed

3 files changed

+161
-168
lines changed

packages/cashscript/test/e2e/network/FullStack.test.ts

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,67 @@ import { getTxOutputs } from '../../test-util.js';
1010
import { FailedRequireError } from '../../../src/Errors.js';
1111
import artifact from '../../fixture/p2pkh.json' with { type: 'json' };
1212

13-
if (!process.env.TESTS_USE_MOCKNET) {
14-
describe('test FullStackNetworkProvider', () => {
15-
const provider = new FullStackNetworkProvider('mainnet', new BCHJS({ restURL: 'https://api.fullstack.cash/v5/' }));
13+
const describeOrSkip = process.env.TESTS_USE_MOCKNET ? describe.skip : describe;
1614

17-
describe('get utxos using FullStackNetworkProvider', () => {
18-
it('should get the utxos for a p2sh20 contract', async () => {
19-
// Note: We instantiate the contract with bobPkh to avoid mempool conflicts with other tests
20-
const p2pkhInstance = new Contract(artifact, [bobPkh], { provider, addressType: 'p2sh20' });
21-
console.log(p2pkhInstance.address);
15+
describeOrSkip('test FullStackNetworkProvider', () => {
16+
const provider = new FullStackNetworkProvider('mainnet', new BCHJS({ restURL: 'https://api.fullstack.cash/v5/' }));
2217

23-
const utxos = await p2pkhInstance.getUtxos();
24-
expect(Array.isArray(utxos)).toBe(true);
25-
});
26-
it('should get the utxos for a p2sh32 contract', async () => {
27-
// Note: We instantiate the contract with bobPkh to avoid mempool conflicts with other tests
28-
const p2pkhInstance = new Contract(artifact, [bobPkh], { provider, addressType: 'p2sh32' });
29-
console.log(p2pkhInstance.address);
18+
describe('get utxos using FullStackNetworkProvider', () => {
19+
it('should get the utxos for a p2sh20 contract', async () => {
20+
// Note: We instantiate the contract with bobPkh to avoid mempool conflicts with other tests
21+
const p2pkhInstance = new Contract(artifact, [bobPkh], { provider, addressType: 'p2sh20' });
22+
console.log(p2pkhInstance.address);
3023

31-
const utxos = await p2pkhInstance.getUtxos();
32-
expect(Array.isArray(utxos)).toBe(true);
33-
});
24+
const utxos = await p2pkhInstance.getUtxos();
25+
expect(Array.isArray(utxos)).toBe(true);
3426
});
35-
36-
describe('send using FullStackNetworkProvider', () => {
27+
it('should get the utxos for a p2sh32 contract', async () => {
3728
// Note: We instantiate the contract with bobPkh to avoid mempool conflicts with other tests
38-
// Using p2sh20 address because it is funded on mainnet
39-
const p2pkhInstance = new Contract(artifact, [bobPkh], { provider, addressType: 'p2sh20' });
29+
const p2pkhInstance = new Contract(artifact, [bobPkh], { provider, addressType: 'p2sh32' });
4030
console.log(p2pkhInstance.address);
4131

42-
it('should fail when using incorrect function arguments', async () => {
43-
// given
44-
const to = p2pkhInstance.address;
45-
const amount = 10000n;
32+
const utxos = await p2pkhInstance.getUtxos();
33+
expect(Array.isArray(utxos)).toBe(true);
34+
});
35+
});
36+
37+
describe('send using FullStackNetworkProvider', () => {
38+
// Note: We instantiate the contract with bobPkh to avoid mempool conflicts with other tests
39+
// Using p2sh20 address because it is funded on mainnet
40+
const p2pkhInstance = new Contract(artifact, [bobPkh], { provider, addressType: 'p2sh20' });
41+
console.log(p2pkhInstance.address);
4642

47-
// when
48-
const txPromise = p2pkhInstance.functions
49-
.spend(bobPub, new SignatureTemplate(alicePriv))
50-
.to(to, amount)
51-
.send();
43+
it('should fail when using incorrect function arguments', async () => {
44+
// given
45+
const to = p2pkhInstance.address;
46+
const amount = 10000n;
5247

53-
// then
54-
await expect(txPromise).rejects.toThrow(FailedRequireError);
55-
await expect(txPromise).rejects.toThrow('P2PKH.cash:5 Require statement failed at input 0 in contract P2PKH.cash at line 5.');
56-
});
48+
// when
49+
const txPromise = p2pkhInstance.functions
50+
.spend(bobPub, new SignatureTemplate(alicePriv))
51+
.to(to, amount)
52+
.send();
53+
54+
// then
55+
await expect(txPromise).rejects.toThrow(FailedRequireError);
56+
await expect(txPromise).rejects.toThrow('P2PKH.cash:5 Require statement failed at input 0 in contract P2PKH.cash at line 5.');
57+
});
5758

58-
it('should succeed when using correct function arguments', async () => {
59-
// given
60-
const to = p2pkhInstance.address;
61-
const amount = 10000n;
59+
it('should succeed when using correct function arguments', async () => {
60+
// given
61+
const to = p2pkhInstance.address;
62+
const amount = 10000n;
6263

63-
// when
64-
const tx = await p2pkhInstance.functions
65-
.spend(bobPub, new SignatureTemplate(bobPriv))
66-
.to(to, amount)
67-
.send();
64+
// when
65+
const tx = await p2pkhInstance.functions
66+
.spend(bobPub, new SignatureTemplate(bobPriv))
67+
.to(to, amount)
68+
.send();
6869

69-
// then
70-
const txOutputs = getTxOutputs(tx, 'mainnet');
71-
expect(txOutputs).toEqual(expect.arrayContaining([{ to, amount }]));
72-
expect(tx.txid).toBeDefined();
73-
});
70+
// then
71+
const txOutputs = getTxOutputs(tx, 'mainnet');
72+
expect(txOutputs).toEqual(expect.arrayContaining([{ to, amount }]));
73+
expect(tx.txid).toBeDefined();
7474
});
7575
});
76-
} else {
77-
test.skip('skip', () => { });
78-
}
76+
});

packages/cashscript/test/e2e/old/Mecenas.test.ts

Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,91 +17,88 @@ import { getTxOutputs } from '../../test-util.js';
1717
import { FailedTransactionError } from '../../../src/Errors.js';
1818
import artifact from '../../fixture/old/mecenas.json' with { type: 'json' };
1919

20-
if (!process.env.TESTS_USE_MOCKNET) {
21-
// Mecenas has tx.age check omitted for testing
22-
describe('v0.6.0 - Mecenas', () => {
23-
let mecenas: Contract;
24-
const pledge = 10000n;
25-
const minerFee = 1000n;
20+
const describeOrSkip = process.env.TESTS_USE_MOCKNET ? describe.skip : describe;
2621

27-
beforeAll(() => {
28-
const provider = new ElectrumNetworkProvider(Network.CHIPNET);
29-
const addressType = 'p2sh20';
30-
mecenas = new Contract(artifact, [alicePkh, bobPkh, pledge], { provider, addressType });
31-
console.log(mecenas.address);
32-
});
22+
describeOrSkip('v0.6.0 - Mecenas', () => {
23+
let mecenas: Contract;
24+
const pledge = 10000n;
25+
const minerFee = 1000n;
26+
27+
beforeAll(() => {
28+
const provider = new ElectrumNetworkProvider(Network.CHIPNET);
29+
const addressType = 'p2sh20';
30+
mecenas = new Contract(artifact, [alicePkh, bobPkh, pledge], { provider, addressType });
31+
console.log(mecenas.address);
32+
});
3333

34-
describe('send', () => {
35-
it('should fail when trying to send more than pledge', async () => {
34+
describe('send', () => {
35+
it('should fail when trying to send more than pledge', async () => {
3636
// given
37-
const to = aliceAddress;
38-
const amount = pledge + 10n;
37+
const to = aliceAddress;
38+
const amount = pledge + 10n;
3939

40-
// when
41-
const txPromise = mecenas.functions
42-
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
43-
.to(to, amount)
44-
.withHardcodedFee(minerFee)
45-
.send();
40+
// when
41+
const txPromise = mecenas.functions
42+
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
43+
.to(to, amount)
44+
.withHardcodedFee(minerFee)
45+
.send();
4646

47-
// then
48-
await expect(txPromise).rejects.toThrow(FailedTransactionError);
49-
await expect(txPromise).rejects.toThrow('Script failed an OP_EQUALVERIFY operation');
50-
});
47+
// then
48+
await expect(txPromise).rejects.toThrow(FailedTransactionError);
49+
await expect(txPromise).rejects.toThrow('Script failed an OP_EQUALVERIFY operation');
50+
});
5151

52-
it('should fail when trying to send to wrong person', async () => {
52+
it('should fail when trying to send to wrong person', async () => {
5353
// given
54-
const to = bobAddress;
55-
const amount = pledge;
54+
const to = bobAddress;
55+
const amount = pledge;
5656

57-
// when
58-
const txPromise = mecenas.functions
59-
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
60-
.to(to, amount)
61-
.withHardcodedFee(minerFee)
62-
.send();
57+
// when
58+
const txPromise = mecenas.functions
59+
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
60+
.to(to, amount)
61+
.withHardcodedFee(minerFee)
62+
.send();
6363

64-
// then
65-
await expect(txPromise).rejects.toThrow(FailedTransactionError);
66-
await expect(txPromise).rejects.toThrow('Script failed an OP_EQUALVERIFY operation');
67-
});
64+
// then
65+
await expect(txPromise).rejects.toThrow(FailedTransactionError);
66+
await expect(txPromise).rejects.toThrow('Script failed an OP_EQUALVERIFY operation');
67+
});
6868

69-
it('should fail when trying to send to multiple people', async () => {
69+
it('should fail when trying to send to multiple people', async () => {
7070
// given
71-
const to = aliceAddress;
72-
const amount = pledge;
71+
const to = aliceAddress;
72+
const amount = pledge;
7373

74-
// when
75-
const txPromise = mecenas.functions
76-
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
77-
.to(to, amount)
78-
.to(to, amount)
79-
.withHardcodedFee(minerFee)
80-
.send();
74+
// when
75+
const txPromise = mecenas.functions
76+
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
77+
.to(to, amount)
78+
.to(to, amount)
79+
.withHardcodedFee(minerFee)
80+
.send();
8181

82-
// then
83-
await expect(txPromise).rejects.toThrow(FailedTransactionError);
84-
await expect(txPromise).rejects.toThrow('Script failed an OP_EQUALVERIFY operation');
85-
});
82+
// then
83+
await expect(txPromise).rejects.toThrow(FailedTransactionError);
84+
await expect(txPromise).rejects.toThrow('Script failed an OP_EQUALVERIFY operation');
85+
});
8686

87-
it('should succeed when sending pledge to receiver', async () => {
87+
it('should succeed when sending pledge to receiver', async () => {
8888
// given
89-
const to = aliceAddress;
90-
const amount = pledge;
89+
const to = aliceAddress;
90+
const amount = pledge;
9191

92-
// when
93-
const tx = await mecenas.functions
94-
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
95-
.to(to, amount)
96-
.withHardcodedFee(minerFee)
97-
.send();
92+
// when
93+
const tx = await mecenas.functions
94+
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
95+
.to(to, amount)
96+
.withHardcodedFee(minerFee)
97+
.send();
9898

99-
// then
100-
const txOutputs = getTxOutputs(tx);
101-
expect(txOutputs).toEqual(expect.arrayContaining([{ to, amount }]));
102-
});
99+
// then
100+
const txOutputs = getTxOutputs(tx);
101+
expect(txOutputs).toEqual(expect.arrayContaining([{ to, amount }]));
103102
});
104103
});
105-
} else {
106-
test.skip('skip', () => {});
107-
}
104+
});

packages/cashscript/test/e2e/old/misc.test.ts

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,62 @@ import { getTxOutputs } from '../../test-util.js';
1616
import simpleCovenantArtifact from '../../fixture/old/simple_covenant.json' with { type: 'json' };
1717
import mecenasBorderArtifact from '../../fixture/old/mecenas_border.json' with { type: 'json' };
1818

19-
if (!process.env.TESTS_USE_MOCKNET) {
20-
describe('v0.6.0 - Simple Covenant', () => {
21-
let covenant: Contract;
19+
const describeOrSkip = process.env.TESTS_USE_MOCKNET ? describe.skip : describe;
2220

23-
beforeAll(() => {
24-
const provider = new ElectrumNetworkProvider(Network.CHIPNET);
25-
const addressType = 'p2sh20';
26-
covenant = new Contract(simpleCovenantArtifact, [], { provider, addressType });
27-
console.log(covenant.address);
28-
});
29-
30-
describe('send', () => {
31-
it('should succeed', async () => {
32-
// given
33-
const to = covenant.address;
34-
const amount = 1000n;
21+
describeOrSkip('v0.6.0 - Simple Covenant', () => {
22+
let covenant: Contract;
3523

36-
// when
37-
const tx = await covenant.functions
38-
.spend(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
39-
.to(to, amount)
40-
.send();
41-
42-
// then
43-
const txOutputs = getTxOutputs(tx);
44-
expect(txOutputs).toEqual(expect.arrayContaining([{ to, amount }]));
45-
});
46-
});
24+
beforeAll(() => {
25+
const provider = new ElectrumNetworkProvider(Network.CHIPNET);
26+
const addressType = 'p2sh20';
27+
covenant = new Contract(simpleCovenantArtifact, [], { provider, addressType });
28+
console.log(covenant.address);
4729
});
4830

49-
describe('v0.6.0 - Bytecode VarInt Border Mecenas', () => {
50-
let mecenas: Contract;
51-
const pledge = 10000n;
52-
53-
beforeAll(() => {
54-
const provider = new ElectrumNetworkProvider(Network.CHIPNET);
55-
const addressType = 'p2sh20';
56-
mecenas = new Contract(mecenasBorderArtifact, [alicePkh, bobPkh, pledge], { provider, addressType });
57-
console.log(mecenas.address);
58-
});
59-
60-
it('should succeed when sending pledge to receiver', async () => {
61-
// given
62-
const to = aliceAddress;
63-
const amount = pledge;
31+
describe('send', () => {
32+
it('should succeed', async () => {
33+
// given
34+
const to = covenant.address;
35+
const amount = 1000n;
6436

6537
// when
66-
const tx = await mecenas.functions
67-
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
38+
const tx = await covenant.functions
39+
.spend(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
6840
.to(to, amount)
69-
.withHardcodedFee(1000n)
7041
.send();
7142

7243
// then
7344
const txOutputs = getTxOutputs(tx);
7445
expect(txOutputs).toEqual(expect.arrayContaining([{ to, amount }]));
7546
});
7647
});
77-
} else {
78-
test.skip('skip', () => {});
79-
}
48+
});
49+
50+
describe('v0.6.0 - Bytecode VarInt Border Mecenas', () => {
51+
let mecenas: Contract;
52+
const pledge = 10000n;
53+
54+
beforeAll(() => {
55+
const provider = new ElectrumNetworkProvider(Network.CHIPNET);
56+
const addressType = 'p2sh20';
57+
mecenas = new Contract(mecenasBorderArtifact, [alicePkh, bobPkh, pledge], { provider, addressType });
58+
console.log(mecenas.address);
59+
});
60+
61+
it('should succeed when sending pledge to receiver', async () => {
62+
// given
63+
const to = aliceAddress;
64+
const amount = pledge;
65+
66+
// when
67+
const tx = await mecenas.functions
68+
.receive(alicePub, new SignatureTemplate(alicePriv, HashType.SIGHASH_ALL))
69+
.to(to, amount)
70+
.withHardcodedFee(1000n)
71+
.send();
72+
73+
// then
74+
const txOutputs = getTxOutputs(tx);
75+
expect(txOutputs).toEqual(expect.arrayContaining([{ to, amount }]));
76+
});
77+
});

0 commit comments

Comments
 (0)