chore: fix flaky web3 stake-program test (#14504)
* chore: remove dangling skipPreflight * chore: rearrange stake test to deactivate sooner after delegate * chore: ensure stake is inactive before trying to withdraw
This commit is contained in:
@ -369,6 +369,36 @@ test('live staking actions', async () => {
|
|||||||
}),
|
}),
|
||||||
).rejects.toThrow();
|
).rejects.toThrow();
|
||||||
|
|
||||||
|
// Deactivate stake
|
||||||
|
let deactivate = StakeProgram.deactivate({
|
||||||
|
stakePubkey: newAccountPubkey,
|
||||||
|
authorizedPubkey: authorized.publicKey,
|
||||||
|
});
|
||||||
|
await sendAndConfirmTransaction(connection, deactivate, [authorized], {
|
||||||
|
commitment: 'singleGossip',
|
||||||
|
});
|
||||||
|
|
||||||
|
let stakeActivationState;
|
||||||
|
do {
|
||||||
|
stakeActivationState = await connection.getStakeActivation(
|
||||||
|
newAccountPubkey,
|
||||||
|
);
|
||||||
|
} while (stakeActivationState.state != 'inactive');
|
||||||
|
|
||||||
|
// Test that withdraw succeeds after deactivation
|
||||||
|
withdraw = StakeProgram.withdraw({
|
||||||
|
stakePubkey: newAccountPubkey,
|
||||||
|
authorizedPubkey: authorized.publicKey,
|
||||||
|
toPubkey: recipient.publicKey,
|
||||||
|
lamports: minimumAmount + 20,
|
||||||
|
});
|
||||||
|
|
||||||
|
await sendAndConfirmTransaction(connection, withdraw, [authorized], {
|
||||||
|
commitment: 'singleGossip',
|
||||||
|
});
|
||||||
|
const recipientBalance = await connection.getBalance(recipient.publicKey);
|
||||||
|
expect(recipientBalance).toEqual(minimumAmount + 20);
|
||||||
|
|
||||||
// Split stake
|
// Split stake
|
||||||
const newStake = new Account();
|
const newStake = new Account();
|
||||||
let split = StakeProgram.split({
|
let split = StakeProgram.split({
|
||||||
@ -380,6 +410,8 @@ test('live staking actions', async () => {
|
|||||||
await sendAndConfirmTransaction(connection, split, [authorized, newStake], {
|
await sendAndConfirmTransaction(connection, split, [authorized, newStake], {
|
||||||
commitment: 'singleGossip',
|
commitment: 'singleGossip',
|
||||||
});
|
});
|
||||||
|
const balance = await connection.getBalance(newAccountPubkey);
|
||||||
|
expect(balance).toEqual(minimumAmount + 2);
|
||||||
|
|
||||||
// Authorize to new account
|
// Authorize to new account
|
||||||
const newAuthorized = new Account();
|
const newAuthorized = new Account();
|
||||||
@ -404,45 +436,18 @@ test('live staking actions', async () => {
|
|||||||
commitment: 'singleGossip',
|
commitment: 'singleGossip',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test old authorized can't deactivate
|
// Test old authorized can't delegate
|
||||||
let deactivateNotAuthorized = StakeProgram.deactivate({
|
let delegateNotAuthorized = StakeProgram.delegate({
|
||||||
stakePubkey: newAccountPubkey,
|
stakePubkey: newAccountPubkey,
|
||||||
authorizedPubkey: authorized.publicKey,
|
authorizedPubkey: authorized.publicKey,
|
||||||
|
votePubkey,
|
||||||
});
|
});
|
||||||
await expect(
|
await expect(
|
||||||
sendAndConfirmTransaction(
|
sendAndConfirmTransaction(connection, delegateNotAuthorized, [authorized], {
|
||||||
connection,
|
commitment: 'singleGossip',
|
||||||
deactivateNotAuthorized,
|
}),
|
||||||
[authorized],
|
|
||||||
{commitment: 'singleGossip', skipPreflight: true},
|
|
||||||
),
|
|
||||||
).rejects.toThrow();
|
).rejects.toThrow();
|
||||||
|
|
||||||
// Deactivate stake
|
|
||||||
let deactivate = StakeProgram.deactivate({
|
|
||||||
stakePubkey: newAccountPubkey,
|
|
||||||
authorizedPubkey: newAuthorized.publicKey,
|
|
||||||
});
|
|
||||||
await sendAndConfirmTransaction(connection, deactivate, [newAuthorized], {
|
|
||||||
commitment: 'singleGossip',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test that withdraw succeeds after deactivation
|
|
||||||
withdraw = StakeProgram.withdraw({
|
|
||||||
stakePubkey: newAccountPubkey,
|
|
||||||
authorizedPubkey: newAuthorized.publicKey,
|
|
||||||
toPubkey: recipient.publicKey,
|
|
||||||
lamports: minimumAmount + 20,
|
|
||||||
});
|
|
||||||
|
|
||||||
await sendAndConfirmTransaction(connection, withdraw, [newAuthorized], {
|
|
||||||
commitment: 'singleGossip',
|
|
||||||
});
|
|
||||||
const balance = await connection.getBalance(newAccountPubkey);
|
|
||||||
expect(balance).toEqual(minimumAmount + 2);
|
|
||||||
const recipientBalance = await connection.getBalance(recipient.publicKey);
|
|
||||||
expect(recipientBalance).toEqual(minimumAmount + 20);
|
|
||||||
|
|
||||||
// Authorize a derived address
|
// Authorize a derived address
|
||||||
authorize = StakeProgram.authorize({
|
authorize = StakeProgram.authorize({
|
||||||
stakePubkey: newAccountPubkey,
|
stakePubkey: newAccountPubkey,
|
||||||
|
Reference in New Issue
Block a user