Skip to content

Commit b85fa14

Browse files
committed
Add vesting test cases
1 parent fc075bf commit b85fa14

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed

solana/tests/vesting.ts

+181
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,47 @@ describe("vesting", () => {
749749
.then(confirm);
750750
});
751751

752+
it("Close and re-create vesting balance", async () => {
753+
await stakeConnection.program.methods
754+
.closeVestingBalance()
755+
.accounts({
756+
...accounts,
757+
vestingBalance: vestingBalance,
758+
rentPayer: whMintAuthority.publicKey,
759+
})
760+
.signers([whMintAuthority])
761+
.rpc()
762+
.then(confirm);
763+
764+
await stakeConnection.program.methods
765+
.createVestingBalance()
766+
.accounts({
767+
...accounts,
768+
vestingBalance: vestingBalance,
769+
})
770+
.signers([whMintAuthority])
771+
.rpc()
772+
.then(confirm);
773+
});
774+
775+
it("should fail to close vesting balance account with incorrect rent payer", async () => {
776+
try {
777+
await stakeConnection.program.methods
778+
.closeVestingBalance()
779+
.accounts({
780+
...accounts,
781+
vestingBalance: vestingBalance,
782+
rentPayer: vester.publicKey,
783+
})
784+
.signers([vester])
785+
.rpc()
786+
.then(confirm);
787+
assert.fail("Expected error was not thrown");
788+
} catch (e) {
789+
assert((e as AnchorError).error?.errorCode?.code === "ConstraintHasOne");
790+
}
791+
});
792+
752793
it("Create another vesting balance", async () => {
753794
await stakeConnection.program.methods
754795
.createVestingBalance()
@@ -806,6 +847,123 @@ describe("vesting", () => {
806847
.then(confirm);
807848
});
808849

850+
it("Close and re-create another vesting balance", async () => {
851+
await stakeConnection.program.methods
852+
.closeVestingBalance()
853+
.accounts({
854+
...accounts,
855+
vestingBalance: vesting2Balance,
856+
vesterTa: vester2Ta,
857+
rentPayer: whMintAuthority.publicKey,
858+
})
859+
.signers([whMintAuthority])
860+
.rpc()
861+
.then(confirm);
862+
863+
await stakeConnection.program.methods
864+
.closeVestingBalance()
865+
.accounts({
866+
...accounts,
867+
vestingBalance: vesting3Balance,
868+
vesterTa: vester3Ta,
869+
rentPayer: whMintAuthority.publicKey,
870+
})
871+
.signers([whMintAuthority])
872+
.rpc()
873+
.then(confirm);
874+
875+
await stakeConnection.program.methods
876+
.closeVestingBalance()
877+
.accounts({
878+
...accounts,
879+
vestingBalance: newVestingBalance,
880+
vesterTa: newVesterTa,
881+
rentPayer: whMintAuthority.publicKey,
882+
})
883+
.signers([whMintAuthority])
884+
.rpc()
885+
.then(confirm);
886+
887+
await stakeConnection.program.methods
888+
.closeVestingBalance()
889+
.accounts({
890+
...accounts,
891+
vestingBalance: newVesting2Balance,
892+
vesterTa: newVester2Ta,
893+
rentPayer: whMintAuthority.publicKey,
894+
})
895+
.signers([whMintAuthority])
896+
.rpc()
897+
.then(confirm);
898+
899+
await stakeConnection.program.methods
900+
.closeVestingBalance()
901+
.accounts({
902+
...accounts,
903+
config: config2,
904+
vestingBalance: vestingBalance2,
905+
rentPayer: whMintAuthority.publicKey,
906+
})
907+
.signers([whMintAuthority])
908+
.rpc()
909+
.then(confirm);
910+
911+
await stakeConnection.program.methods
912+
.createVestingBalance()
913+
.accounts({
914+
...accounts,
915+
vestingBalance: vesting2Balance,
916+
vesterTa: vester2Ta,
917+
})
918+
.signers([whMintAuthority])
919+
.rpc()
920+
.then(confirm);
921+
922+
await stakeConnection.program.methods
923+
.createVestingBalance()
924+
.accounts({
925+
...accounts,
926+
vestingBalance: vesting3Balance,
927+
vesterTa: vester3Ta,
928+
})
929+
.signers([whMintAuthority])
930+
.rpc()
931+
.then(confirm);
932+
933+
await stakeConnection.program.methods
934+
.createVestingBalance()
935+
.accounts({
936+
...accounts,
937+
vestingBalance: newVestingBalance,
938+
vesterTa: newVesterTa,
939+
})
940+
.signers([whMintAuthority])
941+
.rpc()
942+
.then(confirm);
943+
944+
await stakeConnection.program.methods
945+
.createVestingBalance()
946+
.accounts({
947+
...accounts,
948+
vestingBalance: newVesting2Balance,
949+
vesterTa: newVester2Ta,
950+
})
951+
.signers([whMintAuthority])
952+
.rpc()
953+
.then(confirm);
954+
955+
await stakeConnection.program.methods
956+
.createVestingBalance()
957+
.accounts({
958+
...accounts,
959+
config: config2,
960+
vestingBalance: vestingBalance2,
961+
})
962+
.signers([whMintAuthority])
963+
.rpc()
964+
.then(confirm);
965+
});
966+
809967
it("should fail to create vest with invalid admin", async () => {
810968
try {
811969
await stakeConnection.program.methods
@@ -3384,6 +3542,10 @@ describe("vesting", () => {
33843542
updatedNewVestingBalance.vester.toString("hex"),
33853543
vesterWithoutAccount.publicKey.toString("hex"),
33863544
);
3545+
assert.equal(
3546+
updatedNewVestingBalance.rentPayer.toString("hex"),
3547+
newVester.publicKey.toString("hex"),
3548+
);
33873549

33883550
let newVesterStakeCheckpointsAfter: CheckpointAccount =
33893551
await newVesterStakeConnection.fetchCheckpointAccount(
@@ -3395,6 +3557,25 @@ describe("vesting", () => {
33953557
);
33963558
});
33973559

3560+
it("should fail to close vesting balance account when balance is not 0", async () => {
3561+
try {
3562+
await stakeConnection.program.methods
3563+
.closeVestingBalance()
3564+
.accounts({
3565+
...accounts,
3566+
rentPayer: newVester.publicKey,
3567+
vestingBalance: vestingBalanceWithoutAccount,
3568+
vesterTa: vesterTaWithoutAccount,
3569+
})
3570+
.signers([newVester])
3571+
.rpc()
3572+
.then(confirm);
3573+
assert.fail("Expected error was not thrown");
3574+
} catch (e) {
3575+
assert((e as AnchorError).error?.errorCode?.code === "NotFullyVested");
3576+
}
3577+
});
3578+
33983579
it("should fail to transfer vest if newVestingBalance has stake account metadata and vestingBalance has no stake account metadata", async () => {
33993580
let stakeAccountMetadataAddress =
34003581
await vester3StakeConnection.getStakeMetadataAddress(vester3.publicKey);

0 commit comments

Comments
 (0)