Skip to content

Commit 35464f1

Browse files
Seulgi Kimmergify[bot]
authored andcommitted
Extract the function to send a transaction expected to fail in e2e tests
1 parent 6736c23 commit 35464f1

File tree

7 files changed

+97
-281
lines changed

7 files changed

+97
-281
lines changed

test/src/e2e.long/orders.test.ts

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,26 +1451,7 @@ describe("orders", function() {
14511451
});
14521452
await node.signTransactionInput(transferTx, 1);
14531453

1454-
await node.sdk.rpc.devel.stopSealing();
1455-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
1456-
const blockNumber = await node.getBestBlockNumber();
1457-
const pay = await node.sendPayTx({
1458-
recipient: faucetAddress,
1459-
seq,
1460-
quantity: 1
1461-
});
1462-
const hash = await node.sendAssetTransaction(transferTx, {
1463-
seq: seq + 1
1464-
});
1465-
await node.sdk.rpc.devel.startSealing();
1466-
await node.waitBlockNumber(blockNumber + 1);
1467-
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be
1468-
.false;
1469-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash()))
1470-
.be.true;
1471-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
1472-
.null;
1473-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
1454+
await node.sendAssetTransactionExpectedToFail(transferTx);
14741455
}).timeout(10_000);
14751456

14761457
it("Wrong order - originOutputs are wrong (few outputs)", async function() {
@@ -1557,26 +1538,7 @@ describe("orders", function() {
15571538
)
15581539
);
15591540

1560-
await node.sdk.rpc.devel.stopSealing();
1561-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
1562-
const blockNumber = await node.getBestBlockNumber();
1563-
const pay = await node.sendPayTx({
1564-
recipient: faucetAddress,
1565-
seq,
1566-
quantity: 1
1567-
});
1568-
const hash = await node.sendAssetTransaction(transferTx, {
1569-
seq: seq + 1
1570-
});
1571-
await node.sdk.rpc.devel.startSealing();
1572-
await node.waitBlockNumber(blockNumber + 1);
1573-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash()))
1574-
.be.true;
1575-
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be
1576-
.false;
1577-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
1578-
.null;
1579-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
1541+
await node.sendAssetTransactionExpectedToFail(transferTx);
15801542
}).timeout(10_000);
15811543

15821544
it("Wrong order - originOutputs are wrong (many outputs)", async function() {
@@ -1661,24 +1623,7 @@ describe("orders", function() {
16611623
)
16621624
);
16631625

1664-
await node.sdk.rpc.devel.stopSealing();
1665-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
1666-
const blockNumber = await node.getBestBlockNumber();
1667-
const pay = await node.sendPayTx({
1668-
recipient: faucetAddress,
1669-
seq,
1670-
quantity: 1
1671-
});
1672-
const hash = await node.sendAssetTransaction(transferTx, {
1673-
seq: seq + 1
1674-
});
1675-
await node.sdk.rpc.devel.startSealing();
1676-
await node.waitBlockNumber(blockNumber + 1);
1677-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash()))
1678-
.be.true;
1679-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
1680-
.null;
1681-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
1626+
await node.sendAssetTransactionExpectedToFail(transferTx);
16821627
}).timeout(10_000);
16831628

16841629
it("Wrong order - Ratio is wrong (from is zero)", async function() {
@@ -2820,26 +2765,7 @@ describe("orders", function() {
28202765
await node.signTransactionInput(transferTx, 1);
28212766
await node.signTransactionInput(transferTx, 2);
28222767

2823-
await node.sdk.rpc.devel.stopSealing();
2824-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
2825-
const blockNumber = await node.getBestBlockNumber();
2826-
const pay = await node.sendPayTx({
2827-
recipient: faucetAddress,
2828-
seq,
2829-
quantity: 1
2830-
});
2831-
const hash = await node.sendAssetTransaction(transferTx, {
2832-
seq: seq + 1
2833-
});
2834-
await node.sdk.rpc.devel.startSealing();
2835-
await node.waitBlockNumber(blockNumber + 1);
2836-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash()))
2837-
.be.true;
2838-
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be
2839-
.false;
2840-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
2841-
.null;
2842-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
2768+
await node.sendAssetTransactionExpectedToFail(transferTx);
28432769
});
28442770
});
28452771

test/src/e2e.long/timelock.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,8 @@ describe("Timelock", function() {
107107
shardId: asset.shardId,
108108
recipient: await node.createP2PKHAddress()
109109
});
110-
const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber();
111-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
112-
await node.sdk.rpc.devel.stopSealing();
113-
await node.sendPayTx({ seq, quantity: 1 });
114-
const hash = await node.sendAssetTransaction(failedTx, {
115-
seq: seq + 1
116-
});
117-
await node.sdk.rpc.devel.startSealing();
118-
await node.waitBlockNumber(blockNumber + 1);
119-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
110+
111+
await node.sendAssetTransactionExpectedToFail(failedTx);
120112

121113
const output0 = failedTx.getTransferredAsset(0);
122114
const tx = node.sdk.core.createTransferAssetTransaction();

test/src/e2e/burn.test.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,9 @@ describe("Burn", function() {
127127
tx2.input(0)!,
128128
tx2.hashWithoutScript()
129129
);
130-
await node.sdk.rpc.devel.stopSealing();
131-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
132-
const blockNumber = await node.getBestBlockNumber();
133-
const pay = await node.sendPayTx({
134-
recipient: faucetAddress,
135-
seq,
136-
quantity: 1
137-
});
138-
const hash2 = await node.sendAssetTransaction(tx2, { seq: seq + 1 });
139-
await node.sdk.rpc.devel.startSealing();
140-
await node.waitBlockNumber(blockNumber + 1);
141-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
142-
.true;
143-
expect(await node.sdk.rpc.chain.containsTransaction(hash2)).be.false;
144-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null;
145-
expect(await node.sdk.rpc.chain.getErrorHint(hash2)).not.null;
130+
131+
await node.sendAssetTransactionExpectedToFail(tx2);
132+
146133
expect(
147134
await node.sdk.rpc.chain.getAsset(tx1.tracker(), 0, asset.shardId)
148135
).not.to.be.null;
@@ -157,18 +144,7 @@ describe("Burn", function() {
157144
tx.addBurns(asset);
158145
await node.signTransactionP2PKH(tx.burn(0)!, tx.hashWithoutScript());
159146

160-
await node.sdk.rpc.devel.stopSealing();
161-
const blockNumber = await node.getBestBlockNumber();
162-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
163-
const pay = await node.sendPayTx({ seq, quantity: 1 });
164-
const hash = await node.sendAssetTransaction(tx, { seq: seq + 1 });
165-
await node.sdk.rpc.devel.startSealing();
166-
await node.waitBlockNumber(blockNumber + 1);
167-
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.false;
168-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
169-
.true;
170-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null;
171-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
147+
await node.sendAssetTransactionExpectedToFail(tx);
172148
});
173149

174150
afterEach(function() {

test/src/e2e/increaseAssetSupply.test.ts

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,7 @@ describe("IncreaseAssetSupply", async function() {
9696
expect(await node.sdk.rpc.chain.containsTransaction(hash1)).be.true;
9797
expect(await node.sdk.rpc.chain.getTransaction(hash1)).not.null;
9898

99-
await node.sdk.rpc.devel.stopSealing();
100-
const blockNumber = await node.getBestBlockNumber();
101-
102-
const pay = await node.sendPayTx({ seq: seq + 1, quantity: 1 });
103-
const hash2 = await node.sendAssetTransaction(tx2, {
104-
seq: seq + 2
105-
});
106-
107-
await node.sdk.rpc.devel.startSealing();
108-
await node.waitBlockNumber(blockNumber + 1);
109-
110-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
111-
.true;
112-
expect(await node.sdk.rpc.chain.containsTransaction(hash2)).be.false;
113-
expect(await node.sdk.rpc.chain.getTransaction(hash2)).be.null;
114-
expect(await node.sdk.rpc.chain.getErrorHint(hash2)).be.not.null;
99+
await node.sendAssetTransactionExpectedToFail(tx2, { seq: seq + 1 });
115100
});
116101

117102
it("cannot increase supply with the same transaction even the asset is moved", async function() {
@@ -167,22 +152,7 @@ describe("IncreaseAssetSupply", async function() {
167152
expect(await node.sdk.rpc.chain.getTransaction(transferHash)).be.not
168153
.null;
169154

170-
await node.sdk.rpc.devel.stopSealing();
171-
const blockNumber = await node.getBestBlockNumber();
172-
173-
const pay = await node.sendPayTx({ seq: seq + 2, quantity: 1 });
174-
const hash2 = await node.sendAssetTransaction(tx2, {
175-
seq: seq + 3
176-
});
177-
178-
await node.sdk.rpc.devel.startSealing();
179-
await node.waitBlockNumber(blockNumber + 1);
180-
181-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
182-
.true;
183-
expect(await node.sdk.rpc.chain.containsTransaction(hash2)).be.false;
184-
expect(await node.sdk.rpc.chain.getTransaction(hash2)).be.null;
185-
expect(await node.sdk.rpc.chain.getErrorHint(hash2)).be.not.null;
155+
await node.sendAssetTransactionExpectedToFail(tx2, { seq: seq + 2 });
186156
});
187157

188158
it("can increase supply again", async function() {
@@ -293,18 +263,7 @@ describe("IncreaseAssetSupply", async function() {
293263
supply: increasedAmount
294264
});
295265

296-
await node.sdk.rpc.devel.stopSealing();
297-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
298-
const blockNumber = await node.getBestBlockNumber();
299-
const pay = await node.sendPayTx({ seq, quantity: 1 });
300-
const hash = await node.sendAssetTransaction(tx, { seq: seq + 1 });
301-
await node.sdk.rpc.devel.startSealing();
302-
await node.waitBlockNumber(blockNumber + 1);
303-
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.false;
304-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
305-
.true;
306-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null;
307-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
266+
await node.sendAssetTransactionExpectedToFail(tx);
308267

309268
const additionalAsset = await node.sdk.rpc.chain.getAsset(
310269
tx.tracker(),
@@ -328,17 +287,8 @@ describe("IncreaseAssetSupply", async function() {
328287
supply: increasedAmount
329288
});
330289

331-
await node.sdk.rpc.devel.stopSealing();
332-
const blockNumber = await node.getBestBlockNumber();
333-
const pay = await node.sendPayTx({ quantity: 1 });
334-
const hash = await node.sendTransaction(tx, { account: outsider });
335-
await node.sdk.rpc.devel.startSealing();
336-
await node.waitBlockNumber(blockNumber + 1);
337-
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.false;
338-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
339-
.true;
340-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null;
341-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
290+
await node.sendTransactionExpectedToFail(tx, { account: outsider });
291+
342292
const results = await node.sdk.rpc.chain.getTransactionResultsByTracker(
343293
tx.tracker(),
344294
{
@@ -367,18 +317,7 @@ describe("IncreaseAssetSupply", async function() {
367317
supply: 1
368318
});
369319

370-
await node.sdk.rpc.devel.stopSealing();
371-
const blockNumber = await node.getBestBlockNumber();
372-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
373-
const pay = await node.sendPayTx({ seq, quantity: 1 });
374-
const hash = await node.sendAssetTransaction(tx, { seq: seq + 1 });
375-
await node.sdk.rpc.devel.startSealing();
376-
await node.waitBlockNumber(blockNumber + 1);
377-
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.false;
378-
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
379-
.true;
380-
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null;
381-
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
320+
await node.sendAssetTransactionExpectedToFail(tx);
382321

383322
const additionalAsset = await node.sdk.rpc.chain.getAsset(
384323
tx.tracker(),

test/src/e2e/partialSignature.test.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,6 @@ import { faucetAddress } from "../helper/constants";
3030
import CodeChain from "../helper/spawn";
3131
import { AssetTransaction } from "codechain-sdk/lib/core/Transaction";
3232

33-
// If one only sends certainly failing trasactions, the miner would not generate any block.
34-
// So to clearly check the result failed, insert the failing transactions inbetween succeessful ones.
35-
async function expectTransactionFail(
36-
node: CodeChain,
37-
targetTx: Transaction & AssetTransaction
38-
) {
39-
await node.sdk.rpc.devel.stopSealing();
40-
41-
const blockNumber = await node.getBestBlockNumber();
42-
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
43-
const signedDummyTx = await node.sendPayTx({ seq, quantity: 1 });
44-
const targetTxHash = await node.sendAssetTransaction(targetTx, {
45-
seq: seq + 1
46-
});
47-
48-
await node.sdk.rpc.devel.startSealing();
49-
await node.waitBlockNumber(blockNumber + 1);
50-
51-
expect(await node.sdk.rpc.chain.containsTransaction(signedDummyTx.hash()))
52-
.be.true;
53-
expect(await node.sdk.rpc.chain.getErrorHint(targetTxHash)).not.null;
54-
expect(await node.sdk.rpc.chain.containsTransaction(targetTxHash)).be.false;
55-
}
56-
5733
describe("Partial signature", function() {
5834
let node: CodeChain;
5935

@@ -140,7 +116,7 @@ describe("Partial signature", function() {
140116
tx.addBurns(assets[2]);
141117
await node.sdk.key.signTransactionBurn(tx, 0);
142118

143-
await expectTransactionFail(node, tx);
119+
await node.sendAssetTransactionExpectedToFail(tx);
144120
});
145121

146122
it("Can add burns after signing with the signature tag of single input", async function() {
@@ -177,7 +153,7 @@ describe("Partial signature", function() {
177153
tx.addInputs(assets[0]);
178154
await node.sdk.key.signTransactionInput(tx, 0);
179155

180-
await expectTransactionFail(node, tx);
156+
await node.sendAssetTransactionExpectedToFail(tx);
181157
});
182158

183159
it("Can add inputs after signing with the signature tag of signle input when signing burn", async function() {
@@ -216,7 +192,7 @@ describe("Partial signature", function() {
216192
tx.addInputs(assets[1]);
217193
await node.sdk.key.signTransactionInput(tx, 1);
218194

219-
await expectTransactionFail(node, tx);
195+
await node.sendAssetTransactionExpectedToFail(tx);
220196
});
221197

222198
it("Can add inputs after signing with the signature tag of single input", async function() {
@@ -257,7 +233,7 @@ describe("Partial signature", function() {
257233
recipient: address2
258234
});
259235

260-
await expectTransactionFail(node, tx);
236+
await node.sendAssetTransactionExpectedToFail(tx);
261237
});
262238

263239
it("Can add outputs after signing the signature tag of some outputs", async function() {
@@ -318,7 +294,7 @@ describe("Partial signature", function() {
318294
const address2Param = (tx as any)._transaction.outputs[1].parameters;
319295
((tx as any)._transaction.outputs[0].parameters as any) = address2Param;
320296

321-
await expectTransactionFail(node, tx);
297+
await node.sendAssetTransactionExpectedToFail(tx);
322298

323299
((tx as any)._transaction.outputs[0].parameters as any) = address1Param;
324300
// FIXME

0 commit comments

Comments
 (0)