Skip to content

Commit 1d7fba1

Browse files
test(utxo-coredao): move into describe
TICKET: BTC-1578
1 parent aed3a91 commit 1d7fba1

File tree

1 file changed

+143
-140
lines changed

1 file changed

+143
-140
lines changed

modules/utxo-coredao/test/unit/transaction.ts

Lines changed: 143 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -19,160 +19,163 @@ describe('OP_RETURN', function () {
1919
'hex'
2020
);
2121
const validTimelock = 800800;
22-
it('should throw if invalid parameters are passed', function () {
23-
assert.throws(() =>
24-
createCoreDaoOpReturnOutputScript({
25-
version: 292,
26-
chainId: validChainId,
27-
delegator: validDelegator,
28-
validator: validValidator,
29-
fee: validFee,
30-
timelock: validTimelock,
31-
})
32-
);
33-
assert.throws(() =>
34-
createCoreDaoOpReturnOutputScript({
35-
version: validVersion,
36-
chainId: Buffer.alloc(32, 0),
37-
delegator: validDelegator,
38-
validator: validValidator,
39-
fee: validFee,
40-
timelock: validTimelock,
41-
})
42-
);
43-
assert.throws(() =>
44-
createCoreDaoOpReturnOutputScript({
45-
version: validVersion,
46-
chainId: validChainId,
47-
delegator: Buffer.alloc(19, 0),
48-
validator: validValidator,
49-
fee: validFee,
50-
timelock: validTimelock,
51-
})
52-
);
53-
assert.throws(() =>
54-
createCoreDaoOpReturnOutputScript({
22+
23+
describe('createCoreDaoOpReturnOutputScript', function () {
24+
it('should throw if invalid parameters are passed', function () {
25+
assert.throws(() =>
26+
createCoreDaoOpReturnOutputScript({
27+
version: 292,
28+
chainId: validChainId,
29+
delegator: validDelegator,
30+
validator: validValidator,
31+
fee: validFee,
32+
timelock: validTimelock,
33+
})
34+
);
35+
assert.throws(() =>
36+
createCoreDaoOpReturnOutputScript({
37+
version: validVersion,
38+
chainId: Buffer.alloc(32, 0),
39+
delegator: validDelegator,
40+
validator: validValidator,
41+
fee: validFee,
42+
timelock: validTimelock,
43+
})
44+
);
45+
assert.throws(() =>
46+
createCoreDaoOpReturnOutputScript({
47+
version: validVersion,
48+
chainId: validChainId,
49+
delegator: Buffer.alloc(19, 0),
50+
validator: validValidator,
51+
fee: validFee,
52+
timelock: validTimelock,
53+
})
54+
);
55+
assert.throws(() =>
56+
createCoreDaoOpReturnOutputScript({
57+
version: validVersion,
58+
chainId: validChainId,
59+
delegator: validDelegator,
60+
validator: Buffer.alloc(19, 0),
61+
fee: validFee,
62+
timelock: validTimelock,
63+
})
64+
);
65+
assert.throws(() =>
66+
createCoreDaoOpReturnOutputScript({
67+
version: validVersion,
68+
chainId: validChainId,
69+
delegator: validDelegator,
70+
validator: validValidator,
71+
fee: 256,
72+
timelock: validTimelock,
73+
})
74+
);
75+
assert.throws(() =>
76+
createCoreDaoOpReturnOutputScript({
77+
version: validVersion,
78+
chainId: validChainId,
79+
delegator: validDelegator,
80+
validator: validValidator,
81+
fee: validFee,
82+
timelock: -1,
83+
})
84+
);
85+
});
86+
87+
it('should return a buffer with the correct length', function () {
88+
const script = createCoreDaoOpReturnOutputScript({
5589
version: validVersion,
5690
chainId: validChainId,
5791
delegator: validDelegator,
58-
validator: Buffer.alloc(19, 0),
92+
validator: validValidator,
5993
fee: validFee,
6094
timelock: validTimelock,
61-
})
62-
);
63-
assert.throws(() =>
64-
createCoreDaoOpReturnOutputScript({
95+
});
96+
// Make sure that the first byte is the OP_RETURN opcode
97+
assert.strictEqual(script[0], 0x6a);
98+
// Make sure that the length of the script matches what is in the buffer
99+
assert.strictEqual(
100+
// We do not count the OP_RETURN opcode
101+
script.length - 1,
102+
script[1]
103+
);
104+
});
105+
106+
it('should have the correct placement of the values provided with a redeem script', function () {
107+
// This should produce an Op_RETURN that needs the extra push bytes for the length
108+
const script = createCoreDaoOpReturnOutputScript({
65109
version: validVersion,
66110
chainId: validChainId,
67111
delegator: validDelegator,
68112
validator: validValidator,
69-
fee: 256,
70-
timelock: validTimelock,
71-
})
72-
);
73-
assert.throws(() =>
74-
createCoreDaoOpReturnOutputScript({
113+
fee: validFee,
114+
redeemScript: validRedeemScript,
115+
});
116+
// Make sure that the first byte is the OP_RETURN opcode
117+
assert.strictEqual(script[0], 0x6a);
118+
// Make sure that the length of the script matches what is in the buffer
119+
assert.strictEqual(script[1], 0x4c);
120+
assert.strictEqual(
121+
// We do not count the OP_RETURN opcode
122+
script.length - 1,
123+
script[2]
124+
);
125+
// Satoshi plus identifier
126+
assert.deepStrictEqual(script.subarray(3, 7).toString('hex'), CORE_DAO_SATOSHI_PLUS_IDENTIFIER.toString('hex'));
127+
// Make sure that the version is correct
128+
assert.strictEqual(script[7], validVersion);
129+
// Make sure that the chainId is correct
130+
assert.deepStrictEqual(script.subarray(8, 10).toString('hex'), validChainId.toString('hex'));
131+
// Make sure that the delegator is correct
132+
assert.deepStrictEqual(script.subarray(10, 30).toString('hex'), validDelegator.toString('hex'));
133+
// Make sure that the validator is correct
134+
assert.deepStrictEqual(script.subarray(30, 50).toString('hex'), validValidator.toString('hex'));
135+
// Make sure that the fee is correct
136+
assert.strictEqual(script[50], validFee);
137+
// Make sure that the redeemScript is correct
138+
assert.deepStrictEqual(
139+
script.subarray(51, 51 + validRedeemScript.length).toString('hex'),
140+
validRedeemScript.toString('hex')
141+
);
142+
});
143+
144+
it('should have the correct placement of the values provided with a timelock', function () {
145+
// This should produce an Op_RETURN that needs the extra push bytes for the length
146+
const script = createCoreDaoOpReturnOutputScript({
75147
version: validVersion,
76148
chainId: validChainId,
77149
delegator: validDelegator,
78150
validator: validValidator,
79151
fee: validFee,
80-
timelock: -1,
81-
})
82-
);
83-
});
84-
85-
it('should return a buffer with the correct length', function () {
86-
const script = createCoreDaoOpReturnOutputScript({
87-
version: validVersion,
88-
chainId: validChainId,
89-
delegator: validDelegator,
90-
validator: validValidator,
91-
fee: validFee,
92-
timelock: validTimelock,
93-
});
94-
// Make sure that the first byte is the OP_RETURN opcode
95-
assert.strictEqual(script[0], 0x6a);
96-
// Make sure that the length of the script matches what is in the buffer
97-
assert.strictEqual(
98-
// We do not count the OP_RETURN opcode
99-
script.length - 1,
100-
script[1]
101-
);
102-
});
103-
104-
it('should have the correct placement of the values provided with a redeem script', function () {
105-
// This should produce an Op_RETURN that needs the extra push bytes for the length
106-
const script = createCoreDaoOpReturnOutputScript({
107-
version: validVersion,
108-
chainId: validChainId,
109-
delegator: validDelegator,
110-
validator: validValidator,
111-
fee: validFee,
112-
redeemScript: validRedeemScript,
113-
});
114-
// Make sure that the first byte is the OP_RETURN opcode
115-
assert.strictEqual(script[0], 0x6a);
116-
// Make sure that the length of the script matches what is in the buffer
117-
assert.strictEqual(script[1], 0x4c);
118-
assert.strictEqual(
119-
// We do not count the OP_RETURN opcode
120-
script.length - 1,
121-
script[2]
122-
);
123-
// Satoshi plus identifier
124-
assert.deepStrictEqual(script.subarray(3, 7).toString('hex'), CORE_DAO_SATOSHI_PLUS_IDENTIFIER.toString('hex'));
125-
// Make sure that the version is correct
126-
assert.strictEqual(script[7], validVersion);
127-
// Make sure that the chainId is correct
128-
assert.deepStrictEqual(script.subarray(8, 10).toString('hex'), validChainId.toString('hex'));
129-
// Make sure that the delegator is correct
130-
assert.deepStrictEqual(script.subarray(10, 30).toString('hex'), validDelegator.toString('hex'));
131-
// Make sure that the validator is correct
132-
assert.deepStrictEqual(script.subarray(30, 50).toString('hex'), validValidator.toString('hex'));
133-
// Make sure that the fee is correct
134-
assert.strictEqual(script[50], validFee);
135-
// Make sure that the redeemScript is correct
136-
assert.deepStrictEqual(
137-
script.subarray(51, 51 + validRedeemScript.length).toString('hex'),
138-
validRedeemScript.toString('hex')
139-
);
140-
});
141-
142-
it('should have the correct placement of the values provided with a timelock', function () {
143-
// This should produce an Op_RETURN that needs the extra push bytes for the length
144-
const script = createCoreDaoOpReturnOutputScript({
145-
version: validVersion,
146-
chainId: validChainId,
147-
delegator: validDelegator,
148-
validator: validValidator,
149-
fee: validFee,
150-
timelock: validTimelock,
152+
timelock: validTimelock,
153+
});
154+
// Make sure that the first byte is the OP_RETURN opcode
155+
assert.strictEqual(script[0], 0x6a);
156+
// Make sure that the length of the script matches what is in the buffer
157+
assert.strictEqual(
158+
// We do not count the OP_RETURN opcode
159+
script.length - 1,
160+
script[1]
161+
);
162+
// Satoshi plus identifier
163+
assert.deepStrictEqual(script.subarray(2, 6).toString('hex'), CORE_DAO_SATOSHI_PLUS_IDENTIFIER.toString('hex'));
164+
// Make sure that the version is correct
165+
assert.strictEqual(script[6], validVersion);
166+
// Make sure that the chainId is correct
167+
assert.deepStrictEqual(script.subarray(7, 9).toString('hex'), validChainId.toString('hex'));
168+
// Make sure that the delegator is correct
169+
assert.deepStrictEqual(script.subarray(9, 29).toString('hex'), validDelegator.toString('hex'));
170+
// Make sure that the validator is correct
171+
assert.deepStrictEqual(script.subarray(29, 49).toString('hex'), validValidator.toString('hex'));
172+
// Make sure that the fee is correct
173+
assert.strictEqual(script[49], validFee);
174+
// Make sure that the redeemScript is correct
175+
assert.deepStrictEqual(
176+
script.subarray(50, 54).reverse().toString('hex'),
177+
Buffer.alloc(4, validTimelock).toString('hex')
178+
);
151179
});
152-
// Make sure that the first byte is the OP_RETURN opcode
153-
assert.strictEqual(script[0], 0x6a);
154-
// Make sure that the length of the script matches what is in the buffer
155-
assert.strictEqual(
156-
// We do not count the OP_RETURN opcode
157-
script.length - 1,
158-
script[1]
159-
);
160-
// Satoshi plus identifier
161-
assert.deepStrictEqual(script.subarray(2, 6).toString('hex'), CORE_DAO_SATOSHI_PLUS_IDENTIFIER.toString('hex'));
162-
// Make sure that the version is correct
163-
assert.strictEqual(script[6], validVersion);
164-
// Make sure that the chainId is correct
165-
assert.deepStrictEqual(script.subarray(7, 9).toString('hex'), validChainId.toString('hex'));
166-
// Make sure that the delegator is correct
167-
assert.deepStrictEqual(script.subarray(9, 29).toString('hex'), validDelegator.toString('hex'));
168-
// Make sure that the validator is correct
169-
assert.deepStrictEqual(script.subarray(29, 49).toString('hex'), validValidator.toString('hex'));
170-
// Make sure that the fee is correct
171-
assert.strictEqual(script[49], validFee);
172-
// Make sure that the redeemScript is correct
173-
assert.deepStrictEqual(
174-
script.subarray(50, 54).reverse().toString('hex'),
175-
Buffer.alloc(4, validTimelock).toString('hex')
176-
);
177180
});
178181
});

0 commit comments

Comments
 (0)