FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix transaction inspector tests · javascriptit/aepp-aeproject-js@6b244f3 · GitHub

Repository navigation

Commit 6b244f3

Browse files
committed
Fix transaction inspector tests
1 parent 54842cd commit 6b244f3

4 files changed

Lines changed: 26 additions & 88 deletions

File tree

‎packages/aeproject-cli/aeproject-tx-inspector/tx-inspector.js‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
require = require('esm')(module /*, options */) // use to handle es6 import/export
1919

20+
const { TransactionValidator, Node } = require('@aeternity/aepp-sdk');
2021
const utils = require('aeproject-utils');
2122

22-
const TxValidator = utils.txValidator;
2323
const httpGet = utils.httpGet;
2424

2525
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
@@ -36,13 +36,12 @@ async function run (option) {
3636

3737
const network = utils.getNetwork(option.network ? option.network : 'local', option.networkId);
3838

39-
const validator = await TxValidator({
40-
url: network.url,
41-
internalUrl: network.url + '/internal',
39+
const validator = await TransactionValidator({
40+
nodes: [{ name: 'temp', instance: await Node({ url: network.url }) }],
4241
forceCompatibility: true
4342
});
4443

45-
let result = await validator.unpackAndVerify(option.tx, network.networkId);
44+
let result = await validator.unpackAndVerify(option.tx, { networkId: network.networkId });
4645

4746
let publicKey = getPublicKeyFromTx(result.txType, result.tx);
4847

@@ -163,4 +162,4 @@ function printValidationResult (data) {
163162

164163
module.exports = {
165164
run
166-
}
165+
}

‎packages/aeproject-utils/index.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const timeout = aeprojectUtils.timeout;
3030
const contractCompile = aeprojectUtils.contractCompile;
3131
const checkNestedProperty = aeprojectUtils.checkNestedProperty;
3232
const winExec = aeprojectUtils.winExec;
33-
const txValidator = aeprojectUtils.TransactionValidator;
3433
const readSpawnOutput = aeprojectUtils.readSpawnOutput;
3534
const readErrorSpawnOutput = aeprojectUtils.readErrorSpawnOutput;
3635
const capitalize = aeprojectUtils.capitalize;
@@ -83,11 +82,10 @@ module.exports = {
8382
createDirIfNotExists,
8483
writeFileSync,
8584
winExec,
86-
txValidator,
8785
httpGet,
8886
readSpawnOutput,
8987
readErrorSpawnOutput,
9088
capitalize,
9189
addCaretToDependencyVersion,
9290
prompt
93-
}
91+
}

‎packages/aeproject-utils/utils/aeproject-utils.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const prompts = require('prompts');
66
const AeSDK = require('@aeternity/aepp-sdk');
77
const Universal = AeSDK.Universal;
88
const Node = AeSDK.Node;
9-
const TransactionValidator = AeSDK.TransactionValidator;
109

1110
let rgx = /^include\s+\"([\d\w\/\.\-\_]+)\"/gmi;
1211
let dependencyPathRgx = /"([\d\w\/\.\-\_]+)\"/gmi;
@@ -366,10 +365,9 @@ module.exports = {
366365
contractCompile,
367366
checkNestedProperty,
368367
winExec,
369-
TransactionValidator,
370368
readSpawnOutput,
371369
readErrorSpawnOutput,
372370
capitalize,
373371
addCaretToDependencyVersion,
374372
prompt
375-
}
373+
}

‎test/commands-tests/tx-inspector-tests.js‎

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const chai = require('chai');
22
const chaiFiles = require('chai-files');
33
const assert = chai.assert;
44
chai.use(chaiFiles);
5+
chai.use(require('chai-as-promised'));
56

67
const fs = require('fs-extra');
78
const execute = require('../../packages/aeproject-utils/utils/aeproject-utils.js').aeprojectExecute;
@@ -57,13 +58,7 @@ describe('Transaction inspector tests', async function () {
5758
txType: 'spendTx'`
5859

5960
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim());
60-
61-
62-
expectedResArr.map(x => {
63-
if (!result.includes(x)) {
64-
assert.isOk(false, `Non expected data: ${ x }`)
65-
}
66-
});
61+
expectedResArr.map(x => chai.expect(result).to.include(x));
6762
})
6863

6964
it('Should inspect valid contract create tx in local network', async function () {
@@ -94,16 +89,9 @@ describe('Transaction inspector tests', async function () {
9489
'sg_FAQ2PoJsqHpv9ZDPiT4yozTNkuQ3YMAiK2e4c1yMuBi3DDsnKFLeBmrAzndeY6iGHesKwLHWaZ3AL54859mYg58RLorZ'
9590
txType: 'contractCreateTx'`
9691

97-
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim().toLowerCase())
98-
99-
result = result.toLowerCase()
100-
101-
expectedResArr.map(x => {
102-
103-
if (!result.includes(x)) {
104-
assert.isOk(false, `Non expected data: ${ x }`)
105-
}
106-
});
92+
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim().toLowerCase());
93+
result = result.toLowerCase();
94+
expectedResArr.map(x => chai.expect(result).to.include(x));
10795
})
10896

10997
it('Should inspect invalid contract create tx in local network', async function () {
@@ -113,7 +101,6 @@ describe('Transaction inspector tests', async function () {
113101

114102
let expectedResultAsText = `'Nonce' - Account not found
115103
'fee' - The account balance 0 is not enough to execute the transaction
116-
'amount' - The account balance 0 is not enough to execute the transaction
117104
tx:
118105
tag: '42'
119106
VSN: '1'
@@ -137,11 +124,7 @@ describe('Transaction inspector tests', async function () {
137124
txType: 'contractCreateTx'`
138125

139126
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim());
140-
expectedResArr.map(x => {
141-
if (!result.includes(x)) {
142-
assert.isOk(false, `Non expected data: ${ x }`)
143-
}
144-
});
127+
expectedResArr.map(x => chai.expect(result).to.include(x));
145128
})
146129

147130
it('Should inspect contract call tx in local network', async function () {
@@ -172,11 +155,7 @@ describe('Transaction inspector tests', async function () {
172155
txType: 'contractCallTx'`
173156

174157
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
175-
expectedResArr.map(x => {
176-
if (!result.includes(x)) {
177-
assert.isOk(false, `Non expected data: ${ x }`)
178-
}
179-
});
158+
expectedResArr.map(x => chai.expect(result).to.include(x));
180159
})
181160
})
182161

@@ -214,11 +193,7 @@ describe('Transaction inspector tests', async function () {
214193
txType: 'spendTx'`
215194

216195
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
217-
expectedResArr.map(x => {
218-
if (!result.includes(x)) {
219-
assert.isOk(false, `Non expected data: ${ x }`)
220-
}
221-
});
196+
expectedResArr.map(x => chai.expect(result).to.include(x));
222197
})
223198

224199
it('Should inspect valid contract create tx in testnet network', async function () {
@@ -255,11 +230,7 @@ describe('Transaction inspector tests', async function () {
255230
txType: 'contractCreateTx'`
256231

257232
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
258-
expectedResArr.map(x => {
259-
if (!result.includes(x)) {
260-
assert.isOk(false, `Non expected data: ${ x }`)
261-
}
262-
});
233+
expectedResArr.map(x => chai.expect(result).to.include(x));
263234
})
264235

265236
it('Should inspect invalid contract create tx in testnet network', async function () {
@@ -272,7 +243,6 @@ describe('Transaction inspector tests', async function () {
272243
let expectedResultAsText = `'Nonce' - Account not found
273244
'ttl' - The TTL is already expired
274245
'fee' - The account balance 0 is not enough to execute the transaction
275-
'amount' - The account balance 0 is not enough to execute the transaction
276246
'signature' - The signature cannot be verified, please verify that you used the correct network id and the correct private key for the sender address
277247
tx:
278248
tag: '42'
@@ -296,12 +266,8 @@ describe('Transaction inspector tests', async function () {
296266
'sg_L2o8HWfghDvanAe6wbyvMj7ttCe361fEyDTpqJXPw198z2twfM2Y97bRxFCBvhn75f2qPrnFBVr7pNxYbMYNtrCDwiQVu'
297267
txType: 'contractCreateTx'`
298268

299-
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
300-
expectedResArr.map(x => {
301-
if (!result.includes(x)) {
302-
assert.isOk(false, `Non expected data: ${ x }`)
303-
}
304-
});
269+
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim());
270+
expectedResArr.map(x => chai.expect(result).to.include(x));
305271
})
306272

307273
it('Should inspect contract call tx in testnet network', async function () {
@@ -336,11 +302,7 @@ describe('Transaction inspector tests', async function () {
336302
txType: 'contractCallTx' `
337303

338304
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
339-
expectedResArr.map(x => {
340-
if (!result.includes(x)) {
341-
assert.isOk(false, `Non expected data: ${ x }`)
342-
}
343-
});
305+
expectedResArr.map(x => chai.expect(result).to.include(x));
344306
})
345307

346308
})
@@ -378,12 +340,8 @@ describe('Transaction inspector tests', async function () {
378340
payload: 'ba_Xfbg4g=='
379341
txType: 'spendTx'`
380342

381-
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
382-
expectedResArr.map(x => {
383-
if (!result.includes(x)) {
384-
assert.isOk(false, `Non expected data: ${ x }`)
385-
}
386-
});
343+
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim());
344+
expectedResArr.map(x => chai.expect(result).to.include(x));
387345
})
388346

389347
it('Should inspect valid contract create tx in mainnet network', async function () {
@@ -396,7 +354,6 @@ describe('Transaction inspector tests', async function () {
396354
let expectedResultAsText = `'Nonce' - Account not found
397355
'ttl' - The TTL is already expired
398356
'fee' - The account balance 0 is not enough to execute the transaction
399-
'amount' - The account balance 0 is not enough to execute the transaction
400357
'nonce' - The nonce is technically valid but will not be processed immediately by the node
401358
'signature' - The signature cannot be verified, please verify that you used the correct network id and the correct private key for the sender address
402359
tx:
@@ -421,12 +378,8 @@ describe('Transaction inspector tests', async function () {
421378
'sg_FAQ2PoJsqHpv9ZDPiT4yozTNkuQ3YMAiK2e4c1yMuBi3DDsnKFLeBmrAzndeY6iGHesKwLHWaZ3AL54859mYg58RLorZ'
422379
txType: 'contractCreateTx'`
423380

424-
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
425-
expectedResArr.map(x => {
426-
if (!result.includes(x)) {
427-
assert.isOk(false, `Non expected data: ${ x }`)
428-
}
429-
});
381+
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim());
382+
expectedResArr.map(x => chai.expect(result).to.include(x));
430383
})
431384

432385
it('Should inspect invalid contract create tx in testnet network', async function () {
@@ -439,7 +392,6 @@ describe('Transaction inspector tests', async function () {
439392
let expectedResultAsText = `'Nonce' - Account not found
440393
'ttl' - The TTL is already expired,
441394
'fee' - The account balance 0 is not enough to execute the transaction
442-
'amount' - The account balance 0 is not enough to execute the transaction
443395
'signature' - The signature cannot be verified, please verify that you used the correct network id and the correct private key for the sender address
444396
tx:
445397
tag: '42'
@@ -464,11 +416,7 @@ describe('Transaction inspector tests', async function () {
464416
txType: 'contractCreateTx'`
465417

466418
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
467-
expectedResArr.map(x => {
468-
if (!result.includes(x)) {
469-
assert.isOk(false, `Non expected data: ${ x }`)
470-
}
471-
});
419+
expectedResArr.map(x => chai.expect(result).to.include(x));
472420
})
473421

474422
it('Should inspect contract call tx in testnet network', async function () {
@@ -480,7 +428,6 @@ describe('Transaction inspector tests', async function () {
480428

481429
let expectedResultAsText = `'Nonce' - Account not found
482430
'fee' - The account balance 0 is not enough to execute the transaction
483-
'amount' - The account balance 0 is not enough to execute the transaction
484431
'nonce' - The nonce is technically valid but will not be processed immediately by the node (next valid nonce is
485432
'signature' - The signature cannot be verified, please verify that you used the correct network id and the correct private key for the sender address
486433
tx:
@@ -505,11 +452,7 @@ describe('Transaction inspector tests', async function () {
505452
txType: 'contractCallTx'`
506453

507454
let expectedResArr = expectedResultAsText.trim().split('\n').map(x => x.trim())
508-
expectedResArr.map(x => {
509-
if (!result.includes(x)) {
510-
assert.isOk(false, `Non expected data: ${ x }`)
511-
}
512-
});
455+
expectedResArr.map(x => chai.expect(result).to.include(x));
513456
})
514457
})
515458

@@ -532,4 +475,4 @@ describe('Transaction inspector tests', async function () {
532475

533476
fs.removeSync(`.${ testFolder }`)
534477
})
535-
})
478+
})

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL