Skip to content

Commit 6d047e5

Browse files
committed
Fix test
1 parent f80f93a commit 6d047e5

File tree

1 file changed

+60
-38
lines changed

1 file changed

+60
-38
lines changed

solana/tests/api_test.ts

+60-38
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ describe("api", async () => {
8383
let user4StakeConnection: StakeConnection;
8484
let user5StakeConnection: StakeConnection;
8585
let user6StakeConnection: StakeConnection;
86-
let user7StakeConnection: StakeConnection;
86+
let user8StakeConnection: StakeConnection;
8787

8888
let controller;
8989
let owner;
9090
let user2;
9191
let user3;
9292
let user4;
9393
let user6;
94-
let user7;
94+
let user8;
9595
let delegate;
9696

9797
const confirm = async (signature: string): Promise<string> => {
@@ -171,15 +171,15 @@ describe("api", async () => {
171171
);
172172
user6 = user6StakeConnection.provider.wallet.publicKey;
173173

174-
user7StakeConnection = await newUserStakeConnection(
174+
user8StakeConnection = await newUserStakeConnection(
175175
stakeConnection,
176176
Keypair.generate(),
177177
config,
178178
whMintAccount,
179179
whMintAuthority,
180180
WHTokenBalance.fromString("1000"),
181181
);
182-
user7 = user7StakeConnection.provider.wallet.publicKey;
182+
user8 = user8StakeConnection.provider.wallet.publicKey;
183183
});
184184

185185
it("postSignatures", async () => {
@@ -1174,30 +1174,30 @@ describe("api", async () => {
11741174

11751175
it("should fail to castVote with zeroing out the first checkpoint in new checkpoint account", async () => {
11761176
// filling the checkpoint account to the limit
1177-
for (let i = 0; i < TEST_CHECKPOINTS_ACCOUNT_LIMIT; i++) {
1177+
for (let i = 0; i < TEST_CHECKPOINTS_ACCOUNT_LIMIT - 1; i++) {
11781178
await sleep(1000);
1179-
await user7StakeConnection.delegate(
1180-
user7StakeConnection.userPublicKey(),
1179+
await user8StakeConnection.delegate(
1180+
user8StakeConnection.userPublicKey(),
11811181
WHTokenBalance.fromString("5"),
11821182
);
11831183
}
11841184

1185-
let user7StakeAccountMetadataAddress =
1186-
await user7StakeConnection.getStakeMetadataAddress(
1187-
user7StakeConnection.userPublicKey(),
1185+
let user8StakeAccountMetadataAddress =
1186+
await user8StakeConnection.getStakeMetadataAddress(
1187+
user8StakeConnection.userPublicKey(),
11881188
);
1189-
let previousUser7StakeAccountCheckpointsAddress =
1190-
await user7StakeConnection.getStakeAccountCheckpointsAddressByMetadata(
1191-
user7StakeAccountMetadataAddress,
1192-
true,
1189+
let previousUser8StakeAccountCheckpointsAddress =
1190+
await user8StakeConnection.getStakeAccountCheckpointsAddressByMetadata(
1191+
user8StakeAccountMetadataAddress,
1192+
false,
11931193
);
1194-
let user7StakeAccountCheckpointsAddress = PublicKey.findProgramAddressSync(
1194+
let user8StakeAccountCheckpointsAddress = PublicKey.findProgramAddressSync(
11951195
[
11961196
utils.bytes.utf8.encode(wasm.Constants.CHECKPOINT_DATA_SEED()),
1197-
user7StakeConnection.userPublicKey().toBuffer(),
1197+
user8StakeConnection.userPublicKey().toBuffer(),
11981198
Buffer.from([1]),
11991199
],
1200-
user7StakeConnection.program.programId,
1200+
user8StakeConnection.program.programId,
12011201
)[0];
12021202

12031203
let user6StakeAccountMetadataAddress =
@@ -1210,55 +1210,77 @@ describe("api", async () => {
12101210
false,
12111211
);
12121212

1213+
await sleep(2000);
12131214
const instructions: TransactionInstruction[] = [];
12141215
instructions.push(
1215-
await user7StakeConnection.program.methods
1216+
await user8StakeConnection.buildTransferInstruction(
1217+
user8StakeConnection.userPublicKey(),
1218+
WHTokenBalance.fromString("5").toBN(),
1219+
),
1220+
);
1221+
instructions.push(
1222+
await user8StakeConnection.program.methods
1223+
.delegate(user8StakeConnection.userPublicKey(), user8StakeConnection.userPublicKey())
1224+
.accountsPartial({
1225+
currentDelegateStakeAccountCheckpoints:
1226+
previousUser8StakeAccountCheckpointsAddress,
1227+
delegateeStakeAccountCheckpoints:
1228+
previousUser8StakeAccountCheckpointsAddress,
1229+
vestingConfig: null,
1230+
vestingBalance: null,
1231+
mint: user8StakeConnection.config.votingTokenMint,
1232+
})
1233+
.instruction(),
1234+
);
1235+
instructions.push(
1236+
await user8StakeConnection.program.methods
12161237
.createCheckpoints()
12171238
.accounts({
1218-
payer: user7StakeConnection.userPublicKey(),
1219-
stakeAccountCheckpoints: previousUser7StakeAccountCheckpointsAddress,
1220-
stakeAccountMetadata: user7StakeAccountMetadataAddress,
1239+
payer: user8StakeConnection.userPublicKey(),
1240+
stakeAccountCheckpoints: previousUser8StakeAccountCheckpointsAddress,
1241+
newStakeAccountCheckpoints: user8StakeAccountCheckpointsAddress,
1242+
stakeAccountMetadata: user8StakeAccountMetadataAddress,
12211243
})
12221244
.instruction(),
12231245
);
12241246
instructions.push(
1225-
await user7StakeConnection.program.methods
1226-
.delegate(user6StakeConnection.userPublicKey(), user7StakeConnection.userPublicKey())
1247+
await user8StakeConnection.program.methods
1248+
.delegate(user6StakeConnection.userPublicKey(), user8StakeConnection.userPublicKey())
12271249
.accountsPartial({
12281250
currentDelegateStakeAccountCheckpoints:
1229-
user7StakeAccountCheckpointsAddress,
1251+
user8StakeAccountCheckpointsAddress,
12301252
delegateeStakeAccountCheckpoints:
12311253
user6StakeAccountCheckpointsAddress,
12321254
vestingConfig: null,
12331255
vestingBalance: null,
1234-
mint: user7StakeConnection.config.votingTokenMint,
1256+
mint: user8StakeConnection.config.votingTokenMint,
12351257
})
12361258
.instruction(),
12371259
);
1238-
await user7StakeConnection.sendAndConfirmAsVersionedTransaction(instructions);
1260+
await user8StakeConnection.sendAndConfirmAsVersionedTransaction(instructions);
12391261

12401262
await sleep(2000);
1241-
await user7StakeConnection.delegate(
1242-
user7StakeConnection.userPublicKey(),
1263+
await user8StakeConnection.delegate(
1264+
user8StakeConnection.userPublicKey(),
12431265
WHTokenBalance.fromString("150"),
12441266
);
12451267

1246-
let user7StakeAccountCheckpoints: CheckpointAccount =
1247-
await user7StakeConnection.fetchCheckpointAccount(
1248-
user7StakeAccountCheckpointsAddress,
1268+
let user8StakeAccountCheckpoints: CheckpointAccount =
1269+
await user8StakeConnection.fetchCheckpointAccount(
1270+
user8StakeAccountCheckpointsAddress,
12491271
);
1250-
assert.equal(user7StakeAccountCheckpoints.checkpoints[0].value.toString(), "0");
1251-
assert.equal(user7StakeAccountCheckpoints.checkpoints[1].value.toString(), "225000000");
1272+
assert.equal(user8StakeAccountCheckpoints.checkpoints[0].value.toString(), "0");
1273+
assert.equal(user8StakeAccountCheckpoints.checkpoints[1].value.toString(), "225000000");
12521274

12531275
let proposalIdInput = await addTestProposal(
1254-
user7StakeConnection,
1276+
user8StakeConnection,
12551277
Math.floor(Date.now() / 1000),
12561278
);
12571279
const { proposalAccount } =
1258-
await user7StakeConnection.fetchProposalAccount(proposalIdInput);
1280+
await user8StakeConnection.fetchProposalAccount(proposalIdInput);
12591281

12601282
try {
1261-
await user7StakeConnection.program.methods
1283+
await user8StakeConnection.program.methods
12621284
.castVote(
12631285
Array.from(proposalIdInput),
12641286
new BN(10),
@@ -1268,8 +1290,8 @@ describe("api", async () => {
12681290
)
12691291
.accountsPartial({
12701292
proposal: proposalAccount,
1271-
voterCheckpoints: previousUser7StakeAccountCheckpointsAddress,
1272-
voterCheckpointsNext: user7StakeAccountCheckpointsAddress,
1293+
voterCheckpoints: previousUser8StakeAccountCheckpointsAddress,
1294+
voterCheckpointsNext: user8StakeAccountCheckpointsAddress,
12731295
})
12741296
.rpc();
12751297

0 commit comments

Comments
 (0)