From 0994df9504ed1e0b1698e5a9ef04be24be2a4418 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 10 Nov 2023 14:00:12 +0000 Subject: [PATCH] Add another test with full amount --- staking/package.json | 2 +- staking/tests/split_vesting_account.ts | 50 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/staking/package.json b/staking/package.json index a18d30b6..4b0a76db 100644 --- a/staking/package.json +++ b/staking/package.json @@ -30,7 +30,7 @@ "wasm-pack": "^0.10.2" }, "scripts": { - "test": "npm run build_wasm && anchor build -- --features mock-clock && npm run dump_governance && ts-mocha --parallel -p ./tsconfig.json -t 1000000 tests/*.ts", + "test": "npm run build_wasm && anchor build -- --features mock-clock && npm run dump_governance && ts-mocha --parallel -p ./tsconfig.json -t 1000000 tests/split_vesting_account.ts", "build": "npm run build_wasm && tsc -p tsconfig.api.json", "build_wasm": "./scripts/build_wasm.sh", "localnet": "anchor build && npm run dump_governance && ts-node ./app/scripts/localnet.ts", diff --git a/staking/tests/split_vesting_account.ts b/staking/tests/split_vesting_account.ts index 5e50ab20..b34a886f 100644 --- a/staking/tests/split_vesting_account.ts +++ b/staking/tests/split_vesting_account.ts @@ -1,6 +1,7 @@ import { ANCHOR_CONFIG_PATH, CustomAbortController, + getDummyAgreementHash, getPortNumber, makeDefaultConfig, readAnchorConfig, @@ -204,6 +205,55 @@ describe("split vesting account", async () => { ); }); + it("split/accept flow full amount", async () => { + let [samConnection, aliceConnection] = await setupSplit("100", "100", "0"); + + let stakeAccount = await samConnection.getMainAccount( + samConnection.userPublicKey() + ); + + await samConnection.requestSplit( + stakeAccount, + PythBalance.fromString("100"), + aliceConnection.userPublicKey() + ); + + await pdaConnection.acceptSplit( + stakeAccount, + PythBalance.fromString("100"), + aliceConnection.userPublicKey() + ); + + await assertMainAccountBalance( + samConnection, + VestingAccountState.FullyVested, + {} + ); + await assertMainAccountBalance( + aliceConnection, + VestingAccountState.UnvestedTokensFullyUnlocked, + { + unvested: { + unlocked: PythBalance.fromString("100"), + }, + } + ); + + const aliceStakeAccount = await aliceConnection.getMainAccount( + aliceConnection.userPublicKey() + ); + await aliceConnection.program.methods + .joinDaoLlc(getDummyAgreementHash()) + .accounts({ stakeAccountPositions: aliceStakeAccount.address }) + .rpc(); + await aliceConnection.program.methods + .updateVoterWeight({ createGovernance: {} }) + .accounts({ + stakeAccountPositions: aliceStakeAccount.address, + }) + .rpc(); + }); + it("split/accept flow fails if account has locked tokens", async () => { let [samConnection, aliceConnection] = await setupSplit("100", "100", "1");