forked from vulpemventures/liquidjs-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction.spec.ts
47 lines (41 loc) · 1.62 KB
/
transaction.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { AssetHash, Transaction } from '../ts_src';
import jsonFixture from './fixtures/transaction.json';
import * as assert from 'assert';
const fromHex = (hex: string): Buffer => Buffer.from(hex, 'hex');
describe('Transaction', () => {
describe('hashForWitnessV1', () => {
const fixtures = jsonFixture.hashForWitnessV1;
for (const test of fixtures) {
it(test.description, () => {
const tx = Transaction.fromHex(test.txHex);
const hash = tx.hashForWitnessV1(
test.inIndex,
test.prevouts.map((p) => fromHex(p.script)),
test.prevouts.map((p) => ({
asset: AssetHash.fromHex(p.asset).bytes,
value: fromHex(p.value),
})),
test.type,
fromHex(test.genesisHash).reverse(),
test.leafHash != null ? fromHex(test.leafHash) : undefined,
);
assert.strictEqual(hash.toString('hex'), test.expectedHash);
});
}
});
describe('calculates weight and virtualSize', () => {
const fixtures = jsonFixture.discountCT;
for (const test of fixtures) {
it(test.description, () => {
const tx = Transaction.fromHex(test.txHex);
assert.strictEqual(tx.weight(false), test.weight);
assert.strictEqual(tx.virtualSize(false), test.vSize);
assert.strictEqual(tx.weight(true), test.discountWeight);
assert.strictEqual(tx.virtualSize(true), test.discountVSize);
// Check that the default behavior is discounted CT
assert.strictEqual(tx.weight(), test.discountWeight);
assert.strictEqual(tx.virtualSize(), test.discountVSize);
});
}
});
});