@@ -967,6 +967,47 @@ describe("api", async () => {
967
967
assert . equal ( abstainVotes . toString ( ) , "22" ) ;
968
968
} ) ;
969
969
970
+ it . only ( "should cast vote with the correct weight" , async ( ) => {
971
+ let stakeAccountCheckpointsAddress ;
972
+ let proposalIdInput ;
973
+
974
+ // Create 6 checkpoints, 1 second apart
975
+ for ( let i = 0 ; i < 6 ; i ++ ) {
976
+ stakeAccountCheckpointsAddress = await user3StakeConnection . delegate (
977
+ user3 ,
978
+ WHTokenBalance . fromString ( "50" ) ,
979
+ ) ;
980
+
981
+ // Create a proposal with a start time 10 seconds in the future in iteration 5
982
+ // We do this because the vote weight window is 10 seconds
983
+ if ( i == 4 ) {
984
+ proposalIdInput = await addTestProposal (
985
+ user3StakeConnection ,
986
+ Math . floor ( Date . now ( ) / 1000 ) + 10 ,
987
+ ) ;
988
+ }
989
+
990
+ await sleep ( 1000 ) ;
991
+ }
992
+
993
+ await user3StakeConnection . castVote (
994
+ proposalIdInput ,
995
+ new BN ( 10 ) ,
996
+ new BN ( 20 ) ,
997
+ new BN ( 12 ) ,
998
+ 0 ,
999
+ ) ;
1000
+
1001
+ const { proposalId, againstVotes, forVotes, abstainVotes } =
1002
+ await user3StakeConnection . proposalVotes ( proposalIdInput ) ;
1003
+
1004
+ assert . equal ( proposalId . toString ( "hex" ) , proposalIdInput . toString ( "hex" ) ) ;
1005
+ assert . equal ( againstVotes . toString ( ) , "10" ) ;
1006
+ assert . equal ( forVotes . toString ( ) , "20" ) ;
1007
+ assert . equal ( abstainVotes . toString ( ) , "12" ) ;
1008
+
1009
+ } ) ;
1010
+
970
1011
it ( "should fail to castVote if next voter checkpoints are invalid" , async ( ) => {
971
1012
await sleep ( 1000 ) ;
972
1013
await user4StakeConnection . delegate (
0 commit comments