Skip to content

Commit 7ed31e0

Browse files
Merge pull request #5143 from BitGo/BTC-1582
chore(utxo-staking): add test for non blockheight timelock
2 parents 0031451 + d10cbcb commit 7ed31e0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

modules/utxo-staking/test/unit/coreDao/opReturn.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ describe('OP_RETURN', function () {
163163
);
164164
});
165165

166-
it('should have the correct placement of the values provided with a timelock', function () {
166+
it('should have the correct placement of the values provided with a blockheight timelock', function () {
167167
// This should produce an Op_RETURN that needs the extra push bytes for the length
168168
const script = createCoreDaoOpReturnOutputScript({
169169
version: validVersion,
@@ -198,6 +198,42 @@ describe('OP_RETURN', function () {
198198
assert.deepStrictEqual(decodeTimelock(script.subarray(50, 54)), validTimelock);
199199
});
200200

201+
it('should have the correct placement of the values provided with a time timelock', function () {
202+
// This should produce an Op_RETURN that needs the extra push bytes for the length
203+
const timelock = new Date('2022-01-01T00:00:00Z').getTime() / 1000;
204+
const script = createCoreDaoOpReturnOutputScript({
205+
version: validVersion,
206+
chainId: validChainId,
207+
delegator: validDelegator,
208+
validator: validValidator,
209+
fee: validFee,
210+
timelock,
211+
});
212+
// Make sure that the first byte is the OP_RETURN opcode
213+
assert.strictEqual(script[0], 0x6a);
214+
// Make sure that the length of the script matches what is in the buffer
215+
assert.strictEqual(
216+
// We do not count the OP_RETURN opcode or the length
217+
script.length - 2,
218+
script[1]
219+
);
220+
// Satoshi plus identifier
221+
assert.deepStrictEqual(script.subarray(2, 6).toString('hex'), CORE_DAO_SATOSHI_PLUS_IDENTIFIER.toString('hex'));
222+
// Make sure that the version is correct
223+
assert.strictEqual(script[6], validVersion);
224+
// Make sure that the chainId is correct
225+
assert.deepStrictEqual(script.subarray(7, 9).toString('hex'), validChainId.toString('hex'));
226+
// Make sure that the delegator is correct
227+
assert.deepStrictEqual(script.subarray(9, 29).toString('hex'), validDelegator.toString('hex'));
228+
// Make sure that the validator is correct
229+
assert.deepStrictEqual(script.subarray(29, 49).toString('hex'), validValidator.toString('hex'));
230+
// Make sure that the fee is correct
231+
assert.strictEqual(script[49], validFee);
232+
// Make sure that the redeemScript is correct
233+
assert.deepStrictEqual(script.subarray(50, 54).toString('hex'), encodeTimelock(timelock).toString('hex'));
234+
assert.deepStrictEqual(decodeTimelock(script.subarray(50, 54)), timelock);
235+
});
236+
201237
it('should recreate the example OP_RETURN correctly', function () {
202238
assert.deepStrictEqual(
203239
createCoreDaoOpReturnOutputScript({

0 commit comments

Comments
 (0)