@@ -78,13 +78,15 @@ describe("api", async () => {
78
78
let user4StakeConnection : StakeConnection ;
79
79
let user5StakeConnection : StakeConnection ;
80
80
let user6StakeConnection : StakeConnection ;
81
+ let user7StakeConnection : StakeConnection ;
81
82
82
83
let controller ;
83
84
let owner ;
84
85
let user2 ;
85
86
let user3 ;
86
87
let user4 ;
87
88
let user6 ;
89
+ let user7 ;
88
90
let delegate ;
89
91
90
92
const confirm = async ( signature : string ) : Promise < string > => {
@@ -163,6 +165,16 @@ describe("api", async () => {
163
165
WHTokenBalance . fromString ( "1000" ) ,
164
166
) ;
165
167
user6 = user6StakeConnection . provider . wallet . publicKey ;
168
+
169
+ user7StakeConnection = await newUserStakeConnection (
170
+ stakeConnection ,
171
+ Keypair . generate ( ) ,
172
+ config ,
173
+ whMintAccount ,
174
+ whMintAuthority ,
175
+ WHTokenBalance . fromString ( "1000" ) ,
176
+ ) ;
177
+ user7 = user7StakeConnection . provider . wallet . publicKey ;
166
178
} ) ;
167
179
168
180
it ( "postSignatures" , async ( ) => {
@@ -967,6 +979,47 @@ describe("api", async () => {
967
979
assert . equal ( abstainVotes . toString ( ) , "22" ) ;
968
980
} ) ;
969
981
982
+ it ( "should cast vote with the correct weight" , async ( ) => {
983
+ let stakeAccountCheckpointsAddress ;
984
+ let proposalIdInput ;
985
+
986
+ // Create 6 checkpoints, 1 second apart
987
+ for ( let i = 0 ; i < 6 ; i ++ ) {
988
+ stakeAccountCheckpointsAddress = await user7StakeConnection . delegate (
989
+ user7 ,
990
+ WHTokenBalance . fromString ( "50" ) ,
991
+ ) ;
992
+
993
+ // Create a proposal with a start time 10 seconds in the future in iteration 5
994
+ // We do this because the vote weight window is 10 seconds
995
+ if ( i == 4 ) {
996
+ proposalIdInput = await addTestProposal (
997
+ user7StakeConnection ,
998
+ Math . floor ( Date . now ( ) / 1000 ) + 10 ,
999
+ ) ;
1000
+ }
1001
+
1002
+ await sleep ( 1000 ) ;
1003
+ }
1004
+
1005
+ await user7StakeConnection . castVote (
1006
+ proposalIdInput ,
1007
+ new BN ( 10 ) ,
1008
+ new BN ( 20 ) ,
1009
+ new BN ( 12 ) ,
1010
+ 0 ,
1011
+ ) ;
1012
+
1013
+ const { proposalId, againstVotes, forVotes, abstainVotes } =
1014
+ await user7StakeConnection . proposalVotes ( proposalIdInput ) ;
1015
+
1016
+ assert . equal ( proposalId . toString ( "hex" ) , proposalIdInput . toString ( "hex" ) ) ;
1017
+ assert . equal ( againstVotes . toString ( ) , "10" ) ;
1018
+ assert . equal ( forVotes . toString ( ) , "20" ) ;
1019
+ assert . equal ( abstainVotes . toString ( ) , "12" ) ;
1020
+
1021
+ } ) ;
1022
+
970
1023
it ( "should fail to castVote if next voter checkpoints are invalid" , async ( ) => {
971
1024
await sleep ( 1000 ) ;
972
1025
await user4StakeConnection . delegate (
0 commit comments