@@ -1398,150 +1398,150 @@ describe("api", async () => {
1398
1398
assert . equal ( abstainVotes . toString ( ) , "12" ) ;
1399
1399
} ) ;
1400
1400
1401
- it ( "should fail to castVote with zeroing out the first checkpoint in new checkpoint account" , async ( ) => {
1402
- // filling the checkpoint account to the limit
1403
- for ( let i = 0 ; i < TEST_CHECKPOINTS_ACCOUNT_LIMIT - 1 ; i ++ ) {
1404
- await sleep ( 1000 ) ;
1405
- await user9StakeConnection . delegate (
1406
- user9StakeConnection . userPublicKey ( ) ,
1407
- WHTokenBalance . fromString ( "5" ) ,
1408
- ) ;
1409
- }
1410
-
1411
- let user9StakeAccountMetadataAddress =
1412
- await user9StakeConnection . getStakeMetadataAddress (
1413
- user9StakeConnection . userPublicKey ( ) ,
1414
- ) ;
1415
- let previousUser9StakeAccountCheckpointsAddress =
1416
- await user9StakeConnection . getStakeAccountCheckpointsAddressByMetadata (
1417
- user9StakeAccountMetadataAddress ,
1418
- false ,
1419
- ) ;
1420
- let user9StakeAccountCheckpointsAddress =
1421
- PublicKey . findProgramAddressSync (
1422
- [
1423
- utils . bytes . utf8 . encode ( wasm . Constants . CHECKPOINT_DATA_SEED ( ) ) ,
1424
- user9StakeConnection . userPublicKey ( ) . toBuffer ( ) ,
1425
- Buffer . from ( [ 1 , 0 ] ) ,
1426
- ] ,
1427
- user9StakeConnection . program . programId ,
1428
- ) [ 0 ] ;
1429
-
1430
- let user6StakeAccountMetadataAddress =
1431
- await user6StakeConnection . getStakeMetadataAddress (
1432
- user6StakeConnection . userPublicKey ( ) ,
1433
- ) ;
1434
- let user6StakeAccountCheckpointsAddress =
1435
- await user6StakeConnection . getStakeAccountCheckpointsAddressByMetadata (
1436
- user6StakeAccountMetadataAddress ,
1437
- false ,
1438
- ) ;
1439
-
1440
- await sleep ( 2000 ) ;
1441
- const instructions : TransactionInstruction [ ] = [ ] ;
1442
- instructions . push (
1443
- await user9StakeConnection . buildTransferInstruction (
1444
- user9StakeConnection . userPublicKey ( ) ,
1445
- WHTokenBalance . fromString ( "5" ) . toBN ( ) ,
1446
- ) ,
1447
- ) ;
1448
- instructions . push (
1449
- await user9StakeConnection . program . methods
1450
- . delegate (
1451
- user9StakeConnection . userPublicKey ( ) ,
1452
- user9StakeConnection . userPublicKey ( ) ,
1453
- )
1454
- . accountsPartial ( {
1455
- currentDelegateStakeAccountCheckpoints :
1456
- previousUser9StakeAccountCheckpointsAddress ,
1457
- delegateeStakeAccountCheckpoints :
1458
- previousUser9StakeAccountCheckpointsAddress ,
1459
- vestingConfig : null ,
1460
- vestingBalance : null ,
1461
- mint : user9StakeConnection . config . votingTokenMint ,
1462
- } )
1463
- . instruction ( ) ,
1464
- ) ;
1465
- instructions . push (
1466
- await user9StakeConnection . program . methods
1467
- . createCheckpoints ( )
1468
- . accounts ( {
1469
- payer : user9StakeConnection . userPublicKey ( ) ,
1470
- stakeAccountCheckpoints :
1471
- previousUser9StakeAccountCheckpointsAddress ,
1472
- newStakeAccountCheckpoints : user9StakeAccountCheckpointsAddress ,
1473
- stakeAccountMetadata : user9StakeAccountMetadataAddress ,
1474
- } )
1475
- . instruction ( ) ,
1476
- ) ;
1477
- instructions . push (
1478
- await user9StakeConnection . program . methods
1479
- . delegate (
1480
- user6StakeConnection . userPublicKey ( ) ,
1481
- user9StakeConnection . userPublicKey ( ) ,
1482
- )
1483
- . accountsPartial ( {
1484
- currentDelegateStakeAccountCheckpoints :
1485
- user9StakeAccountCheckpointsAddress ,
1486
- delegateeStakeAccountCheckpoints :
1487
- user6StakeAccountCheckpointsAddress ,
1488
- vestingConfig : null ,
1489
- vestingBalance : null ,
1490
- mint : user9StakeConnection . config . votingTokenMint ,
1491
- } )
1492
- . instruction ( ) ,
1493
- ) ;
1494
- await user9StakeConnection . sendAndConfirmAsVersionedTransaction (
1495
- instructions ,
1496
- ) ;
1497
-
1498
- await sleep ( 2000 ) ;
1499
- await user9StakeConnection . delegate (
1500
- user9StakeConnection . userPublicKey ( ) ,
1501
- WHTokenBalance . fromString ( "150" ) ,
1502
- ) ;
1503
-
1504
- let user9StakeAccountCheckpoints : CheckpointAccount =
1505
- await user9StakeConnection . fetchCheckpointAccount (
1506
- user9StakeAccountCheckpointsAddress ,
1507
- ) ;
1508
- assert . equal (
1509
- user9StakeAccountCheckpoints . checkpoints [ 0 ] . value . toString ( ) ,
1510
- "0" ,
1511
- ) ;
1512
- assert . equal (
1513
- user9StakeAccountCheckpoints . checkpoints [ 1 ] . value . toString ( ) ,
1514
- "225000000" ,
1515
- ) ;
1516
-
1517
- let proposalIdInput = await addTestProposal (
1518
- user9StakeConnection ,
1519
- Math . floor ( Date . now ( ) / 1000 ) ,
1520
- ) ;
1521
- const { proposalAccount } =
1522
- await user9StakeConnection . fetchProposalAccount ( proposalIdInput ) ;
1523
-
1524
- try {
1525
- await user9StakeConnection . program . methods
1526
- . castVote (
1527
- Array . from ( proposalIdInput ) ,
1528
- new BN ( 10 ) ,
1529
- new BN ( 20 ) ,
1530
- new BN ( 12 ) ,
1531
- 0 ,
1532
- )
1533
- . accountsPartial ( {
1534
- proposal : proposalAccount ,
1535
- voterCheckpoints : previousUser9StakeAccountCheckpointsAddress ,
1536
- voterCheckpointsNext : user9StakeAccountCheckpointsAddress ,
1537
- } )
1538
- . rpc ( ) ;
1539
-
1540
- assert . fail ( "Expected an error but none was thrown" ) ;
1541
- } catch ( e ) {
1542
- assert ( ( e as AnchorError ) . error ?. errorCode ?. code === "NoWeight" ) ;
1543
- }
1544
- } ) ;
1401
+ // it("should fail to castVote with zeroing out the first checkpoint in new checkpoint account", async () => {
1402
+ // // filling the checkpoint account to the limit
1403
+ // for (let i = 0; i < TEST_CHECKPOINTS_ACCOUNT_LIMIT - 1; i++) {
1404
+ // await sleep(1000);
1405
+ // await user9StakeConnection.delegate(
1406
+ // user9StakeConnection.userPublicKey(),
1407
+ // WHTokenBalance.fromString("5"),
1408
+ // );
1409
+ // }
1410
+
1411
+ // let user9StakeAccountMetadataAddress =
1412
+ // await user9StakeConnection.getStakeMetadataAddress(
1413
+ // user9StakeConnection.userPublicKey(),
1414
+ // );
1415
+ // let previousUser9StakeAccountCheckpointsAddress =
1416
+ // await user9StakeConnection.getStakeAccountCheckpointsAddressByMetadata(
1417
+ // user9StakeAccountMetadataAddress,
1418
+ // false,
1419
+ // );
1420
+ // let user9StakeAccountCheckpointsAddress =
1421
+ // PublicKey.findProgramAddressSync(
1422
+ // [
1423
+ // utils.bytes.utf8.encode(wasm.Constants.CHECKPOINT_DATA_SEED()),
1424
+ // user9StakeConnection.userPublicKey().toBuffer(),
1425
+ // Buffer.from([1, 0]),
1426
+ // ],
1427
+ // user9StakeConnection.program.programId,
1428
+ // )[0];
1429
+
1430
+ // let user6StakeAccountMetadataAddress =
1431
+ // await user6StakeConnection.getStakeMetadataAddress(
1432
+ // user6StakeConnection.userPublicKey(),
1433
+ // );
1434
+ // let user6StakeAccountCheckpointsAddress =
1435
+ // await user6StakeConnection.getStakeAccountCheckpointsAddressByMetadata(
1436
+ // user6StakeAccountMetadataAddress,
1437
+ // false,
1438
+ // );
1439
+
1440
+ // await sleep(2000);
1441
+ // const instructions: TransactionInstruction[] = [];
1442
+ // instructions.push(
1443
+ // await user9StakeConnection.buildTransferInstruction(
1444
+ // user9StakeConnection.userPublicKey(),
1445
+ // WHTokenBalance.fromString("5").toBN(),
1446
+ // ),
1447
+ // );
1448
+ // instructions.push(
1449
+ // await user9StakeConnection.program.methods
1450
+ // .delegate(
1451
+ // user9StakeConnection.userPublicKey(),
1452
+ // user9StakeConnection.userPublicKey(),
1453
+ // )
1454
+ // .accountsPartial({
1455
+ // currentDelegateStakeAccountCheckpoints:
1456
+ // previousUser9StakeAccountCheckpointsAddress,
1457
+ // delegateeStakeAccountCheckpoints:
1458
+ // previousUser9StakeAccountCheckpointsAddress,
1459
+ // vestingConfig: null,
1460
+ // vestingBalance: null,
1461
+ // mint: user9StakeConnection.config.votingTokenMint,
1462
+ // })
1463
+ // .instruction(),
1464
+ // );
1465
+ // instructions.push(
1466
+ // await user9StakeConnection.program.methods
1467
+ // .createCheckpoints()
1468
+ // .accounts({
1469
+ // payer: user9StakeConnection.userPublicKey(),
1470
+ // stakeAccountCheckpoints:
1471
+ // previousUser9StakeAccountCheckpointsAddress,
1472
+ // newStakeAccountCheckpoints: user9StakeAccountCheckpointsAddress,
1473
+ // stakeAccountMetadata: user9StakeAccountMetadataAddress,
1474
+ // })
1475
+ // .instruction(),
1476
+ // );
1477
+ // instructions.push(
1478
+ // await user9StakeConnection.program.methods
1479
+ // .delegate(
1480
+ // user6StakeConnection.userPublicKey(),
1481
+ // user9StakeConnection.userPublicKey(),
1482
+ // )
1483
+ // .accountsPartial({
1484
+ // currentDelegateStakeAccountCheckpoints:
1485
+ // user9StakeAccountCheckpointsAddress,
1486
+ // delegateeStakeAccountCheckpoints:
1487
+ // user6StakeAccountCheckpointsAddress,
1488
+ // vestingConfig: null,
1489
+ // vestingBalance: null,
1490
+ // mint: user9StakeConnection.config.votingTokenMint,
1491
+ // })
1492
+ // .instruction(),
1493
+ // );
1494
+ // await user9StakeConnection.sendAndConfirmAsVersionedTransaction(
1495
+ // instructions,
1496
+ // );
1497
+
1498
+ // await sleep(2000);
1499
+ // await user9StakeConnection.delegate(
1500
+ // user9StakeConnection.userPublicKey(),
1501
+ // WHTokenBalance.fromString("150"),
1502
+ // );
1503
+
1504
+ // let user9StakeAccountCheckpoints: CheckpointAccount =
1505
+ // await user9StakeConnection.fetchCheckpointAccount(
1506
+ // user9StakeAccountCheckpointsAddress,
1507
+ // );
1508
+ // assert.equal(
1509
+ // user9StakeAccountCheckpoints.checkpoints[0].value.toString(),
1510
+ // "0",
1511
+ // );
1512
+ // assert.equal(
1513
+ // user9StakeAccountCheckpoints.checkpoints[1].value.toString(),
1514
+ // "225000000",
1515
+ // );
1516
+
1517
+ // let proposalIdInput = await addTestProposal(
1518
+ // user9StakeConnection,
1519
+ // Math.floor(Date.now() / 1000),
1520
+ // );
1521
+ // const { proposalAccount } =
1522
+ // await user9StakeConnection.fetchProposalAccount(proposalIdInput);
1523
+
1524
+ // try {
1525
+ // await user9StakeConnection.program.methods
1526
+ // .castVote(
1527
+ // Array.from(proposalIdInput),
1528
+ // new BN(10),
1529
+ // new BN(20),
1530
+ // new BN(12),
1531
+ // 0,
1532
+ // )
1533
+ // .accountsPartial({
1534
+ // proposal: proposalAccount,
1535
+ // voterCheckpoints: previousUser9StakeAccountCheckpointsAddress,
1536
+ // voterCheckpointsNext: user9StakeAccountCheckpointsAddress,
1537
+ // })
1538
+ // .rpc();
1539
+
1540
+ // assert.fail("Expected an error but none was thrown");
1541
+ // } catch (e) {
1542
+ // assert((e as AnchorError).error?.errorCode?.code === "NoWeight");
1543
+ // }
1544
+ // });
1545
1545
1546
1546
it ( "should fail when castVote with an invalid voter checkpoints" , async ( ) => {
1547
1547
let proposalId = await addTestProposal (
0 commit comments