@@ -876,17 +876,66 @@ describe("api", async () => {
876
876
} ) ;
877
877
878
878
describe ( "castVote" , ( ) => {
879
+ it ( "should fail to castVote if proposal inactive" , async ( ) => {
880
+ await user6StakeConnection . delegate (
881
+ user6 ,
882
+ WHTokenBalance . fromString ( "50" ) ,
883
+ ) ;
884
+
885
+ let proposalIdInput = await addTestProposal (
886
+ user6StakeConnection ,
887
+ Math . floor ( Date . now ( ) / 1000 ) + 20 ,
888
+ ) ;
889
+
890
+ let stakeAccountMetadataAddress =
891
+ await user6StakeConnection . getStakeMetadataAddress (
892
+ user6StakeConnection . userPublicKey ( ) ,
893
+ ) ;
894
+ let previousStakeAccountCheckpointsAddress =
895
+ await user6StakeConnection . getStakeAccountCheckpointsAddressByMetadata (
896
+ stakeAccountMetadataAddress ,
897
+ false ,
898
+ ) ;
899
+
900
+ const { proposalAccount } =
901
+ await user6StakeConnection . fetchProposalAccount ( proposalIdInput ) ;
902
+
903
+ try {
904
+ await user6StakeConnection . program . methods
905
+ . castVote (
906
+ Array . from ( proposalIdInput ) ,
907
+ new BN ( 10 ) ,
908
+ new BN ( 20 ) ,
909
+ new BN ( 12 ) ,
910
+ 0 ,
911
+ )
912
+ . accountsPartial ( {
913
+ proposal : proposalAccount ,
914
+ voterCheckpoints : previousStakeAccountCheckpointsAddress ,
915
+ voterCheckpointsNext : null ,
916
+ } )
917
+ . rpc ( ) ;
918
+
919
+ assert . fail ( "Expected an error but none was thrown" ) ;
920
+ } catch ( e ) {
921
+ assert (
922
+ ( e as AnchorError ) . error ?. errorCode ?. code === "ProposalInactive" ,
923
+ ) ;
924
+ }
925
+ } ) ;
926
+
879
927
it ( "should fail to castVote if votes were added in the voteWeightWindow" , async ( ) => {
880
928
await user6StakeConnection . delegate (
881
929
user6 ,
882
- WHTokenBalance . fromString ( "150 " ) ,
930
+ WHTokenBalance . fromString ( "100 " ) ,
883
931
) ;
884
932
885
933
// voteWeightWindow is 10s
886
934
let proposalIdInput = await addTestProposal (
887
935
user6StakeConnection ,
888
936
Math . floor ( Date . now ( ) / 1000 ) + 3 ,
889
937
) ;
938
+ await sleep ( 3000 ) ;
890
939
891
940
let stakeAccountMetadataAddress =
892
941
await user6StakeConnection . getStakeMetadataAddress (
@@ -935,6 +984,7 @@ describe("api", async () => {
935
984
user3StakeConnection ,
936
985
Math . floor ( Date . now ( ) / 1000 ) + 12 ,
937
986
) ;
987
+ await sleep ( 12000 ) ;
938
988
939
989
await user3StakeConnection . castVote (
940
990
proposalIdInput ,
@@ -979,6 +1029,7 @@ describe("api", async () => {
979
1029
user4StakeConnection ,
980
1030
voteStart ,
981
1031
) ;
1032
+
982
1033
const { proposalAccount } =
983
1034
await user4StakeConnection . fetchProposalAccount ( proposalIdInput ) ;
984
1035
@@ -990,6 +1041,7 @@ describe("api", async () => {
990
1041
WHTokenBalance . fromString ( "5" ) ,
991
1042
) ;
992
1043
}
1044
+ await sleep ( 4000 ) ;
993
1045
994
1046
let currentStakeAccountCheckpointsAddress =
995
1047
await user4StakeConnection . getStakeAccountCheckpointsAddress (
@@ -1054,8 +1106,9 @@ describe("api", async () => {
1054
1106
1055
1107
let proposalIdInput = await addTestProposal (
1056
1108
user4StakeConnection ,
1057
- Math . floor ( Date . now ( ) / 1000 ) + 12 ,
1109
+ Math . floor ( Date . now ( ) / 1000 ) + 11 ,
1058
1110
) ;
1111
+ await sleep ( 11000 ) ;
1059
1112
1060
1113
const { proposalAccount } =
1061
1114
await user4StakeConnection . fetchProposalAccount ( proposalIdInput ) ;
0 commit comments