Skip to content

Commit

Permalink
remove unless tests for the staking flow
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Nov 12, 2024
1 parent 1904900 commit 4dd9a79
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 768 deletions.
2 changes: 2 additions & 0 deletions src/app/api/getDelegations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface DelegationAPI {
staking_tx: StakingTxAPI;
unbonding_tx?: UnbondingTxAPI;
is_overflow: boolean;
transitioned: boolean;
}

interface StakingTxAPI {
Expand Down Expand Up @@ -87,6 +88,7 @@ export const getDelegations = async (
outputIndex: apiDelegation.unbonding_tx.output_index,
}
: undefined,
transitioned: apiDelegation.transitioned,
}),
);

Expand Down
5 changes: 3 additions & 2 deletions src/app/api/getParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ export const getParams = async (): Promise<Params> => {
current.version > prev.version ? current : prev,
);

// Find the v1 params which is the first version
// Find the genesis params which is the first version
// This param can be used for transitioning phase-1 delegations
const genesisParam = versions.find((v) => v.version === 0);
if (!genesisParam) {
throw new Error("V1 params not found");
throw new Error("Genesis params not found");
}

return {
Expand Down
10 changes: 3 additions & 7 deletions src/app/components/FAQ/FAQ.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useAppState } from "@/app/state";
import { getNetworkConfig } from "@/config/network.config";

import { questions } from "./data/questions";
Expand All @@ -7,18 +6,15 @@ import { Section } from "./Section";
interface FAQProps {}

export const FAQ: React.FC<FAQProps> = () => {
const { currentVersion } = useAppState();
const { coinName, networkName } = getNetworkConfig();
// TODO: To be handled by https://github.com/babylonlabs-io/simple-staking/issues/325
const confirmationDepth = 10;

return (
<div className="container mx-auto flex flex-col gap-2 p-6">
<h3 className="mb-4 font-bold">FAQ</h3>
<div className="flex flex-col gap-4">
{questions(
coinName,
networkName,
currentVersion?.confirmationDepth,
).map((question) => (
{questions(coinName, networkName, confirmationDepth).map((question) => (
<Section
key={question.title}
title={question.title}
Expand Down
6 changes: 4 additions & 2 deletions src/app/components/Summary/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import { StakerPoints } from "../Points/StakerPoints";
export const Summary = () => {
const { isApiNormal, isGeoBlocked } = useHealthCheck();
const { totalStaked } = useDelegationState();
const { totalBalance, currentVersion, isLoading: loading } = useAppState();
const { totalBalance, isLoading: loading } = useAppState();
const { address, publicKeyNoCoord } = useBTCWallet();

const { coinName } = getNetworkConfig();
const onMainnet = getNetworkConfig().network === Network.MAINNET;
// TODO: To be handled by https://github.com/babylonlabs-io/simple-staking/issues/325
const confirmationDepth = 10;

if (!address) return;

Expand All @@ -38,7 +40,7 @@ export const Summary = () => {
<span
className="cursor-pointer text-xs"
data-tooltip-id="tooltip-total-staked"
data-tooltip-content={`Total staked is updated after ${currentVersion?.confirmationDepth || 10} confirmations`}
data-tooltip-content={`Total staked is updated after ${confirmationDepth || 10} confirmations`}
data-tooltip-place="bottom"
>
<AiOutlineInfoCircle />
Expand Down
105 changes: 0 additions & 105 deletions src/utils/delegations/signUnbondingTx.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/utils/local_storage/toLocalStorageDelegation.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export const toLocalStorageIntermediateDelegation = (
},
isOverflow: false,
unbondingTx: undefined,
transitioned: false,
});
1 change: 1 addition & 0 deletions tests/helper/generateMockDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export function generateMockDelegation(
},
isOverflow: false,
unbondingTx: undefined,
transitioned: false,
};
}
56 changes: 0 additions & 56 deletions tests/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import * as bitcoin from "bitcoinjs-lib";
import ECPairFactory from "ecpair";

import { GlobalParamsVersion } from "@/app/types/globalParams";
import { createStakingTx } from "@/utils/delegations/signStakingTx";
import { getCurrentGlobalParamsVersion } from "@/utils/globalParams";
import { getPublicKeyNoCoord } from "@/utils/wallet";
import { UTXO } from "@/utils/wallet/btc_wallet_provider";

Expand Down Expand Up @@ -260,60 +258,6 @@ export class DataGenerator {
};
};

createRandomStakingPsbt = (
globalParams: GlobalParamsVersion[],
txHeight: number,
stakerKeysPairs?: KeyPairs,
) => {
const { currentVersion: selectedParam } = getCurrentGlobalParamsVersion(
txHeight,
globalParams,
);
if (!selectedParam) {
throw new Error("Current version not found");
}
const stakerKeys = stakerKeysPairs
? stakerKeysPairs
: this.generateRandomKeyPair();
const { scriptPubKey, address } = this.getAddressAndScriptPubKey(
stakerKeys.publicKey,
).nativeSegwit;
const stakingAmount = this.getRandomIntegerBetween(
selectedParam.minStakingAmountSat,
selectedParam.maxStakingAmountSat,
);
const stakingTerm = this.getRandomIntegerBetween(
selectedParam.minStakingTimeBlocks,
selectedParam.maxStakingTimeBlocks,
);
const { unsignedStakingPsbt } = createStakingTx(
selectedParam,
stakingAmount,
stakingTerm,
this.generateRandomKeyPair().noCoordPublicKey, // FP key
this.network,
address,
stakerKeys.noCoordPublicKey, // staker public key
DEFAULT_TEST_FEE_RATE,
this.generateRandomUTXOs(
stakingAmount + 1000000, // add some extra satoshis to cover the fee
this.getRandomIntegerBetween(1, 10),
scriptPubKey,
),
);

const unsignedPsbt = unsignedStakingPsbt;

const signedPsbt = unsignedStakingPsbt
.signAllInputs(stakerKeys.keyPair)
.finalizeAllInputs();

return {
unsignedPsbt,
signedPsbt,
};
};

private getTaprootAddress = (publicKey: string) => {
// Remove the prefix if it exists
if (publicKey.length == COMPRESSED_PUBLIC_KEY_HEX_LENGTH) {
Expand Down
Loading

0 comments on commit 4dd9a79

Please sign in to comment.