Skip to content

Commit b6fc7f5

Browse files
authored
Merge pull request #7223 from brice-stacks/test/l1-bond-integration
L1 bond integration test
2 parents 9debe2f + 940d401 commit b6fc7f5

11 files changed

Lines changed: 3961 additions & 2390 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Complete L1 bitcoin staking integration tests, including both normal exit after the timelock expires, and early exit.

contrib/core-contract-tests/tests/clarigen-types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,7 +4805,7 @@ export const contracts = {
48054805
{ name: 'target-rate', type: 'uint128' },
48064806
{ name: 'stx-value-ratio', type: 'uint128' },
48074807
{ name: 'min-ustx-ratio', type: 'uint128' },
4808-
{ name: 'early-unlock-signers', type: { buffer: { length: 683 } } },
4808+
{ name: 'early-unlock-bytes', type: { buffer: { length: 683 } } },
48094809
{ name: 'early-unlock-admin', type: 'principal' },
48104810
{
48114811
name: 'allowlist',
@@ -4829,7 +4829,7 @@ export const contracts = {
48294829
tuple: [
48304830
{ name: 'bond-index', type: 'uint128' },
48314831
{
4832-
name: 'early-unlock-signers',
4832+
name: 'early-unlock-bytes',
48334833
type: { buffer: { length: 683 } },
48344834
},
48354835
{ name: 'max-allocation-sats', type: 'uint128' },
@@ -4848,7 +4848,7 @@ export const contracts = {
48484848
targetRate: TypedAbiArg<number | bigint, 'targetRate'>,
48494849
stxValueRatio: TypedAbiArg<number | bigint, 'stxValueRatio'>,
48504850
minUstxRatio: TypedAbiArg<number | bigint, 'minUstxRatio'>,
4851-
earlyUnlockSigners: TypedAbiArg<Uint8Array, 'earlyUnlockSigners'>,
4851+
earlyUnlockBytes: TypedAbiArg<Uint8Array, 'earlyUnlockBytes'>,
48524852
earlyUnlockAdmin: TypedAbiArg<string, 'earlyUnlockAdmin'>,
48534853
allowlist: TypedAbiArg<
48544854
{
@@ -4861,7 +4861,7 @@ export const contracts = {
48614861
Response<
48624862
{
48634863
bondIndex: bigint;
4864-
earlyUnlockSigners: Uint8Array;
4864+
earlyUnlockBytes: Uint8Array;
48654865
maxAllocationSats: bigint;
48664866
minUstxRatio: bigint;
48674867
stxValueRatio: bigint;
@@ -5352,7 +5352,7 @@ export const contracts = {
53525352
tuple: [
53535353
{ name: 'early-unlock-admin', type: 'principal' },
53545354
{
5355-
name: 'early-unlock-signers',
5355+
name: 'early-unlock-bytes',
53565356
type: { buffer: { length: 683 } },
53575357
},
53585358
{ name: 'min-ustx-ratio', type: 'uint128' },
@@ -5366,7 +5366,7 @@ export const contracts = {
53665366
[bondIndex: TypedAbiArg<number | bigint, 'bondIndex'>],
53675367
{
53685368
earlyUnlockAdmin: string;
5369-
earlyUnlockSigners: Uint8Array;
5369+
earlyUnlockBytes: Uint8Array;
53705370
minUstxRatio: bigint;
53715371
stxValueRatio: bigint;
53725372
targetRate: bigint;
@@ -6039,7 +6039,7 @@ export const contracts = {
60396039
value: {
60406040
tuple: [
60416041
{ name: 'early-unlock-admin', type: 'principal' },
6042-
{ name: 'early-unlock-signers', type: { buffer: { length: 683 } } },
6042+
{ name: 'early-unlock-bytes', type: { buffer: { length: 683 } } },
60436043
{ name: 'min-ustx-ratio', type: 'uint128' },
60446044
{ name: 'stx-value-ratio', type: 'uint128' },
60456045
{ name: 'target-rate', type: 'uint128' },
@@ -6049,7 +6049,7 @@ export const contracts = {
60496049
number | bigint,
60506050
{
60516051
earlyUnlockAdmin: string;
6052-
earlyUnlockSigners: Uint8Array;
6052+
earlyUnlockBytes: Uint8Array;
60536053
minUstxRatio: bigint;
60546054
stxValueRatio: bigint;
60556055
targetRate: bigint;

contrib/core-contract-tests/tests/pox-5/pox-5-helpers.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { accounts, project } from '../clarigen-types';
1818
import { rov, rovOk, txOk } from '@clarigen/test';
1919
import { sha256 } from '@noble/hashes/sha2.js';
20+
import { concatBytes } from '@noble/hashes/utils.js';
2021
import { secp256k1 } from '@noble/curves/secp256k1.js';
2122
import { expect } from 'vitest';
2223

@@ -55,20 +56,29 @@ export function serializeLockupScript({
5556
unlockBytes: Uint8Array;
5657
earlyUnlockBytes: Uint8Array;
5758
}) {
59+
// `unlockBytes` and `earlyUnlockBytes` are caller-supplied Bitcoin
60+
// subscripts (e.g. `<pubkey> OP_CHECKSIG`) that the contract splices
61+
// in raw — they must NOT go through `Script.encode` as Uint8Array
62+
// elements, which would wrap them in an OP_PUSHBYTES_N push.
5863
const stackerEncoded = serializeCV(principalCV(stacker));
59-
return BTC.Script.encode([
64+
const prefix = BTC.Script.encode([
6065
hex.decode(stackerEncoded),
6166
'DROP',
6267
'IF',
6368
Number(unlockBurnHeight),
6469
'CHECKLOCKTIMEVERIFY',
6570
'DROP',
71+
]);
72+
const OP_ELSE = new Uint8Array([0x67]);
73+
const OP_ENDIF = new Uint8Array([0x68]);
74+
return concatBytes(
75+
prefix,
6676
unlockBytes,
67-
'ELSE',
77+
OP_ELSE,
6878
earlyUnlockBytes,
6979
unlockBytes,
70-
'ENDIF',
71-
]);
80+
OP_ENDIF,
81+
);
7282
}
7383

7484
/**

0 commit comments

Comments
 (0)